diff --git a/app/code/Magento/CustomerImportExport/Test/Unit/Model/ResourceModel/Import/CustomerComposite/DataTest.php b/app/code/Magento/CustomerImportExport/Test/Unit/Model/ResourceModel/Import/CustomerComposite/DataTest.php index ad8361e4e8762..1869056c6a30e 100644 --- a/app/code/Magento/CustomerImportExport/Test/Unit/Model/ResourceModel/Import/CustomerComposite/DataTest.php +++ b/app/code/Magento/CustomerImportExport/Test/Unit/Model/ResourceModel/Import/CustomerComposite/DataTest.php @@ -10,6 +10,7 @@ */ namespace Magento\CustomerImportExport\Test\Unit\Model\ResourceModel\Import\CustomerComposite; +use Magento\Backend\Model\Auth\Session; use Magento\CustomerImportExport\Model\Import\Address; use Magento\CustomerImportExport\Model\Import\CustomerComposite; use Magento\Framework\App\ResourceConnection; @@ -20,6 +21,7 @@ use Magento\Framework\Json\Helper\Data; use Magento\Framework\Model\ResourceModel\Db\Context; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use PHPUnit\Framework\MockObject\MockBuilder; use PHPUnit\Framework\TestCase; /** @@ -27,6 +29,36 @@ */ class DataTest extends TestCase { + /** + * @var string[] + */ + private $mockBuilderCallbacks = [ + Session::class => 'getSessionMock' + ]; + + /** + * @inheritDoc + */ + public function getMockBuilder(string $className): MockBuilder + { + $mockBuilder = parent::getMockBuilder($className); + if (isset($this->mockBuilderCallbacks[$className])) { + $mockBuilder = call_user_func_array([$this, $this->mockBuilderCallbacks[$className]], [$mockBuilder]); + } + + return $mockBuilder; + } + + /** + * @param MockBuilder $mockBuilder + * @return MockBuilder + * @SuppressWarnings(PHPMD.UnusedPrivateMethod) Used in callback. + */ + private function getSessionMock(MockBuilder $mockBuilder): MockBuilder + { + return $mockBuilder->onlyMethods(['isLoggedIn']); + } + /** * Array of customer attributes * @@ -57,9 +89,10 @@ protected function _getDependencies($entityType, $bunchData) ); /** @var $selectMock \Magento\Framework\DB\Select */ - $selectMock = $this->createPartialMock(Select::class, ['from', 'order']); + $selectMock = $this->createPartialMock(Select::class, ['from', 'order', 'where']); $selectMock->expects($this->any())->method('from')->willReturnSelf(); $selectMock->expects($this->any())->method('order')->willReturnSelf(); + $selectMock->expects($this->any())->method('where')->willReturnSelf(); /** @var AdapterInterface $connectionMock */ $connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class) diff --git a/app/code/Magento/Eav/Model/TypeLocator.php b/app/code/Magento/Eav/Model/TypeLocator.php index 76c03ff69ae05..c08f3d7139f08 100644 --- a/app/code/Magento/Eav/Model/TypeLocator.php +++ b/app/code/Magento/Eav/Model/TypeLocator.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Eav\Model; @@ -20,27 +21,19 @@ class TypeLocator implements CustomAttributeTypeLocatorInterface */ private $typeLocators; - /** - * @var ServiceTypeListInterface - */ - private $serviceTypeList; - /** * Initialize TypeLocator * - * @param ServiceTypeListInterface $serviceTypeList * @param \Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface[] $typeLocators */ public function __construct( - ServiceTypeListInterface $serviceTypeList, array $typeLocators = [] ) { $this->typeLocators = $typeLocators; - $this->serviceTypeList = $serviceTypeList; } /** - * {@inheritdoc} + * @inheritdoc */ public function getType($attributeCode, $entityType) { @@ -53,12 +46,4 @@ public function getType($attributeCode, $entityType) return TypeProcessor::NORMALIZED_ANY_TYPE; } - - /** - * {@inheritDoc} - */ - public function getAllServiceDataInterfaces() - { - return $this->serviceTypeList->getDataTypes(); - } } diff --git a/app/code/Magento/Eav/Model/TypeLocator/ComplexType.php b/app/code/Magento/Eav/Model/TypeLocator/ComplexType.php index c01779e27aa03..b82f9750188de 100644 --- a/app/code/Magento/Eav/Model/TypeLocator/ComplexType.php +++ b/app/code/Magento/Eav/Model/TypeLocator/ComplexType.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Eav\Model\TypeLocator; @@ -52,7 +53,7 @@ public function __construct( } /** - * {@inheritdoc} + * @inheritdoc */ public function getType($attributeCode, $entityType) { @@ -83,7 +84,7 @@ public function getType($attributeCode, $entityType) } /** - * {@inheritdoc} + * @inheritdoc */ public function getDataTypes() { @@ -96,14 +97,6 @@ public function getDataTypes() return array_unique($dataInterfaceArray); } - /** - * {@inheritDoc} - */ - public function getAllServiceDataInterfaces() - { - return $this->getDataTypes(); - } - /** * @return array [['backend model' => 'simple or complex type'], ..] */ diff --git a/app/code/Magento/Eav/Model/TypeLocator/ServiceClassLocator.php b/app/code/Magento/Eav/Model/TypeLocator/ServiceClassLocator.php index 7ffcf689c4381..e51c597e3d19d 100644 --- a/app/code/Magento/Eav/Model/TypeLocator/ServiceClassLocator.php +++ b/app/code/Magento/Eav/Model/TypeLocator/ServiceClassLocator.php @@ -73,12 +73,4 @@ public function getType($attributeCode, $entityType) return $type; } - - /** - * @inheritDoc - */ - public function getAllServiceDataInterfaces() - { - return $this->complexTypeLocator->getDataTypes(); - } } diff --git a/app/code/Magento/Eav/Model/TypeLocator/SimpleType.php b/app/code/Magento/Eav/Model/TypeLocator/SimpleType.php index eb9b173ed52be..b30ab008c84ce 100644 --- a/app/code/Magento/Eav/Model/TypeLocator/SimpleType.php +++ b/app/code/Magento/Eav/Model/TypeLocator/SimpleType.php @@ -3,13 +3,13 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Eav\Model\TypeLocator; use Magento\Eav\Api\AttributeRepositoryInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Reflection\TypeProcessor; -use Magento\Framework\Webapi\CustomAttribute\ServiceTypeListInterface; use Magento\Framework\Webapi\CustomAttributeTypeLocatorInterface; /** @@ -22,23 +22,15 @@ class SimpleType implements CustomAttributeTypeLocatorInterface */ private $attributeRepository; - /** - * @var ServiceTypeListInterface - */ - private $serviceTypeList; - /** * Constructor * * @param AttributeRepositoryInterface $attributeRepository - * @param ServiceTypeListInterface $serviceTypeList */ public function __construct( - AttributeRepositoryInterface $attributeRepository, - ServiceTypeListInterface $serviceTypeList + AttributeRepositoryInterface $attributeRepository ) { $this->attributeRepository = $attributeRepository; - $this->serviceTypeList = $serviceTypeList; } /** @@ -62,14 +54,4 @@ public function getType($attributeCode, $entityType) ]; return $backendTypeMap[$backendType] ?? TypeProcessor::NORMALIZED_ANY_TYPE; } - - /** - * Get data Types from service type list - * - * @return void - */ - public function getAllServiceDataInterfaces() - { - $this->serviceTypeList->getDataTypes(); - } } diff --git a/app/code/Magento/Eav/Test/Unit/Model/TypeLocatorTest.php b/app/code/Magento/Eav/Test/Unit/Model/TypeLocatorTest.php index c3c027e2a027c..e2f29d7addebd 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/TypeLocatorTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/TypeLocatorTest.php @@ -69,7 +69,7 @@ public function testGetType( $serviceClass, $serviceEntityTypeMapData, $expected - ) { + ): void { $this->complexType->expects($this->once())->method('getType')->willReturn($expected); $type = $this->customAttributeTypeLocator->getType( $attributeCode, @@ -83,7 +83,7 @@ public function testGetType( * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function getTypeDataProvider() + public function getTypeDataProvider(): array { $serviceInterface = ProductInterface::class; $eavEntityType = 'catalog_product'; diff --git a/app/code/Magento/ImportExport/Model/ResourceModel/Import/Data.php b/app/code/Magento/ImportExport/Model/ResourceModel/Import/Data.php index 254050bfb1dc1..e6d73f52765ed 100644 --- a/app/code/Magento/ImportExport/Model/ResourceModel/Import/Data.php +++ b/app/code/Magento/ImportExport/Model/ResourceModel/Import/Data.php @@ -5,14 +5,23 @@ */ namespace Magento\ImportExport\Model\ResourceModel\Import; +use Magento\Backend\Model\Auth\Session; +use Magento\Framework\App\ObjectManager; +use Magento\Framework\DB\Select; + /** * ImportExport import data resource model * * @api * @since 100.0.2 + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) Necessary to get current logged in user without modifying methods */ class Data extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb implements \IteratorAggregate { + /** + * Offline import user ID + */ + private const DEFAULT_USER_ID = 0; /** * @var \Iterator */ @@ -24,21 +33,28 @@ class Data extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb implemen * @var \Magento\Framework\Json\Helper\Data */ protected $jsonHelper; + /** + * @var Session + */ + private $authSession; /** * Class constructor * * @param \Magento\Framework\Model\ResourceModel\Db\Context $context * @param \Magento\Framework\Json\Helper\Data $jsonHelper - * @param string $connectionName + * @param string|null $connectionName + * @param Session|null $authSession */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Json\Helper\Data $jsonHelper, - $connectionName = null + $connectionName = null, + ?Session $authSession = null ) { parent::__construct($context, $connectionName); $this->jsonHelper = $jsonHelper; + $this->authSession = $authSession ?? ObjectManager::getInstance()->get(Session::class); } /** @@ -61,6 +77,7 @@ public function getIterator() { $connection = $this->getConnection(); $select = $connection->select()->from($this->getMainTable(), ['data'])->order('id ASC'); + $select = $this->prepareSelect($select); $stmt = $connection->query($select); $stmt->setFetchMode(\Zend_Db::FETCH_NUM); @@ -82,7 +99,7 @@ public function getIterator() */ public function cleanBunches() { - return $this->getConnection()->delete($this->getMainTable()); + return $this->getConnection()->delete($this->getMainTable(), $this->prepareDelete([])); } /** @@ -115,7 +132,9 @@ public function getEntityTypeCode() public function getUniqueColumnData($code) { $connection = $this->getConnection(); - $values = array_unique($connection->fetchCol($connection->select()->from($this->getMainTable(), [$code]))); + $select = $connection->select()->from($this->getMainTable(), [$code]); + $select = $this->prepareSelect($select); + $values = array_unique($connection->fetchCol($select)); if (count($values) != 1) { throw new \Magento\Framework\Exception\LocalizedException( @@ -170,7 +189,67 @@ public function saveBunch($entity, $behavior, array $data) return $this->getConnection()->insert( $this->getMainTable(), - ['behavior' => $behavior, 'entity' => $entity, 'data' => $encodedData] + $this->prepareInsert(['behavior' => $behavior, 'entity' => $entity, 'data' => $encodedData]) ); } + + /** + * Prepare select for query + * + * @param Select $select + * @return Select + */ + private function prepareSelect(Select $select): Select + { + // check if the table has not been overridden for backward compatibility + if ($this->getMainTable() === $this->getTable('importexport_importdata')) { + // user_id is NULL part is for backward compatibility + $select->where('user_id=? OR user_id is NULL', $this->getUserId()); + } + + return $select; + } + + /** + * Prepare data for insert + * + * @param array $data + * @return array + */ + private function prepareInsert(array $data): array + { + // check if the table has not been overridden for backward compatibility + if ($this->getMainTable() === $this->getTable('importexport_importdata')) { + $data['user_id'] = $this->getUserId(); + } + + return $data; + } + + /** + * Prepare delete constraints + * + * @param array $where + * @return array + */ + private function prepareDelete(array $where): array + { + // check if the table has not been overridden for backward compatibility + if ($this->getMainTable() === $this->getTable('importexport_importdata')) { + // user_id is NULL part is for backward compatibility + $where['user_id=? OR user_id is NULL'] = $this->getUserId(); + } + + return $where; + } + + /** + * Get current user ID + * + * @return int + */ + private function getUserId(): int + { + return $this->authSession->isLoggedIn() ? $this->authSession->getUser()->getId() : self::DEFAULT_USER_ID; + } } diff --git a/app/code/Magento/ImportExport/etc/db_schema.xml b/app/code/Magento/ImportExport/etc/db_schema.xml index 12242364fbf18..58721ea56f489 100644 --- a/app/code/Magento/ImportExport/etc/db_schema.xml +++ b/app/code/Magento/ImportExport/etc/db_schema.xml @@ -12,6 +12,7 @@ + diff --git a/app/code/Magento/ImportExport/etc/db_schema_whitelist.json b/app/code/Magento/ImportExport/etc/db_schema_whitelist.json index e78535d2c7585..e1bef0f20fc1d 100644 --- a/app/code/Magento/ImportExport/etc/db_schema_whitelist.json +++ b/app/code/Magento/ImportExport/etc/db_schema_whitelist.json @@ -4,7 +4,8 @@ "id": true, "entity": true, "behavior": true, - "data": true + "data": true, + "user_id": true }, "constraint": { "PRIMARY": true @@ -24,4 +25,4 @@ "PRIMARY": true } } -} \ No newline at end of file +} diff --git a/app/code/Magento/Theme/Model/Theme.php b/app/code/Magento/Theme/Model/Theme.php index b81fa117bdf14..fef8d0515e561 100644 --- a/app/code/Magento/Theme/Model/Theme.php +++ b/app/code/Magento/Theme/Model/Theme.php @@ -3,9 +3,12 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Theme\Model; use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\Area; use Magento\Framework\View\Design\ThemeInterface; use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection; @@ -36,14 +39,14 @@ class Theme extends \Magento\Framework\Model\AbstractModel implements ThemeInterface { /** - * {@inheritdoc} + * @inheritdoc * * @var string */ protected $_eventPrefix = 'theme'; /** - * {@inheritdoc} + * @inheritdoc * * @var string */ @@ -244,7 +247,7 @@ public function getStagingVersion() } /** - * {@inheritdoc} + * @inheritdoc */ public function getParentTheme() { @@ -261,19 +264,30 @@ public function getParentTheme() } /** - * {@inheritdoc} + * @inheritdoc */ public function getArea() { // In order to support environment emulation of area, if area is set, return it - if ($this->getData('area') && !$this->_appState->isAreaCodeEmulated()) { - return $this->getData('area'); + if ($this->getData(Area::PARAM_AREA) && !$this->_appState->isAreaCodeEmulated()) { + return $this->getData(Area::PARAM_AREA); } return $this->_appState->getAreaCode(); } /** - * {@inheritdoc} + * Set area + * + * @param string $area + * @return $this + */ + public function setArea($area) + { + return $this->setData(Area::PARAM_AREA, $area); + } + + /** + * @inheritdoc */ public function getThemePath() { @@ -294,7 +308,7 @@ public function getFullPath() } /** - * {@inheritdoc} + * @inheritdoc */ public function getCode() { diff --git a/app/code/Magento/Theme/Model/Theme/Data.php b/app/code/Magento/Theme/Model/Theme/Data.php index 336989f065354..468ea594ec7de 100644 --- a/app/code/Magento/Theme/Model/Theme/Data.php +++ b/app/code/Magento/Theme/Model/Theme/Data.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + declare(strict_types=1); + namespace Magento\Theme\Model\Theme; /** @@ -12,11 +14,5 @@ */ class Data extends \Magento\Theme\Model\Theme { - /** - * {@inheritdoc} - */ - public function getArea() - { - return $this->getData('area'); - } + } diff --git a/app/code/Magento/Theme/Model/View/Design.php b/app/code/Magento/Theme/Model/View/Design.php index f45b6b233a6a5..cd795807598e0 100644 --- a/app/code/Magento/Theme/Model/View/Design.php +++ b/app/code/Magento/Theme/Model/View/Design.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); namespace Magento\Theme\Model\View; @@ -15,14 +16,14 @@ class Design implements \Magento\Framework\View\DesignInterface { /** - * Package area + * Design area * * @var string */ protected $_area; /** - * Package theme + * Model theme * * @var \Magento\Theme\Model\Theme */ @@ -105,19 +106,6 @@ public function __construct( $this->objectManager = $objectManager; } - /** - * Set package area - * - * @param string $area - * @return $this - */ - public function setArea($area) - { - $this->_area = $area; - $this->_theme = null; - return $this; - } - /** * Retrieve package area * @@ -142,7 +130,7 @@ public function getArea() public function setDesignTheme($theme, $area = null) { if ($area) { - $this->setArea($area); + $this->_area = $area; } else { $area = $this->getArea(); } @@ -232,7 +220,7 @@ public function getDesignTheme() } /** - * {@inheritdoc} + * @inheritdoc */ public function getThemePath(\Magento\Framework\View\Design\ThemeInterface $theme) { @@ -272,7 +260,7 @@ public function setLocale(\Magento\Framework\Locale\ResolverInterface $locale) } /** - * {@inheritdoc} + * @inheritdoc */ public function getDesignParams() { diff --git a/app/code/Magento/Theme/Test/Unit/Model/View/DesignTest.php b/app/code/Magento/Theme/Test/Unit/Model/View/DesignTest.php index 12ddea6fd7f40..cee7d233e421f 100644 --- a/app/code/Magento/Theme/Test/Unit/Model/View/DesignTest.php +++ b/app/code/Magento/Theme/Test/Unit/Model/View/DesignTest.php @@ -103,7 +103,7 @@ public function testGetThemePath($themePath, $themeId, $expectedResult) /** * @return array */ - public function getThemePathDataProvider() + public function getThemePathDataProvider(): array { return [ ['some_path', '', 'some_path'], @@ -115,7 +115,7 @@ public function getThemePathDataProvider() /** * @return array */ - public function designThemeDataProvider() + public function designThemeDataProvider(): array { return [ 'single' => [true, ScopeInterface::SCOPE_WEBSITES], @@ -130,7 +130,7 @@ public function designThemeDataProvider() * @dataProvider designThemeDataProvider * @return void */ - public function testSetDefaultDesignTheme($storeMode, $scope) + public function testSetDefaultDesignTheme($storeMode, $scope): void { $area = Design::DEFAULT_AREA; $this->state->expects($this->any()) @@ -157,7 +157,7 @@ public function testSetDefaultDesignTheme($storeMode, $scope) * @covers \Magento\Theme\Model\View\Design::getArea * @covers \Magento\Theme\Model\View\Design::getDesignTheme */ - public function testGetDesignParams() + public function testGetDesignParams(): void { $locale = 'locale'; $area = Design::DEFAULT_AREA; @@ -189,7 +189,7 @@ public function testGetDesignParams() * @covers \Magento\Theme\Model\View\Design::setDesignTheme * @covers \Magento\Theme\Model\View\Design::setArea */ - public function testSetDesignTheme() + public function testSetDesignTheme(): void { $area = 'adminhtml'; $theme = $this->getMockBuilder(ThemeInterface::class) diff --git a/dev/tests/integration/testsuite/Magento/Backend/Block/System/Design/Edit/Tab/GeneralTest.php b/dev/tests/integration/testsuite/Magento/Backend/Block/System/Design/Edit/Tab/GeneralTest.php index ff7fda4f75eee..5a2c8323fd93e 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Block/System/Design/Edit/Tab/GeneralTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Block/System/Design/Edit/Tab/GeneralTest.php @@ -3,13 +3,17 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Backend\Block\System\Design\Edit\Tab; +use PHPUnit\Framework\TestCase; + /** * Test class for \Magento\Backend\Block\System\Design\Edit\Tab\General * @magentoAppArea adminhtml */ -class GeneralTest extends \PHPUnit\Framework\TestCase +class GeneralTest extends TestCase { /** * @magentoAppIsolation enabled @@ -19,8 +23,6 @@ public function testPrepareForm() $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $objectManager->get( \Magento\Framework\View\DesignInterface::class - )->setArea( - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE )->setDefaultDesignTheme(); $objectManager->get( \Magento\Framework\Registry::class diff --git a/dev/tests/integration/testsuite/Magento/Backend/Block/Widget/FormTest.php b/dev/tests/integration/testsuite/Magento/Backend/Block/Widget/FormTest.php index f9f8bc7fb0a86..6f9f9679b549e 100644 --- a/dev/tests/integration/testsuite/Magento/Backend/Block/Widget/FormTest.php +++ b/dev/tests/integration/testsuite/Magento/Backend/Block/Widget/FormTest.php @@ -3,13 +3,17 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Backend\Block\Widget; +use PHPUnit\Framework\TestCase; + /** * Test class for \Magento\Backend\Block\Widget\Form * @magentoAppArea adminhtml */ -class FormTest extends \PHPUnit\Framework\TestCase +class FormTest extends TestCase { /** * @magentoAppIsolation enabled @@ -19,8 +23,6 @@ public function testSetFieldset() $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $objectManager->get( \Magento\Framework\View\DesignInterface::class - )->setArea( - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE )->setDefaultDesignTheme(); $layout = $objectManager->create(\Magento\Framework\View\Layout::class); $formBlock = $layout->addBlock(\Magento\Backend\Block\Widget\Form::class); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php index be79d38a5535a..8311264af6c28 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Catalog\Controller\Adminhtml\Product; use Magento\Framework\Exception\LocalizedException; @@ -332,7 +334,7 @@ protected function _translate($string) \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( \Magento\Framework\View\DesignInterface::class )->setDesignTheme( - 1 + 'Magento/backend' ); /** @var \Magento\Framework\TranslateInterface $translate */ $translate = $this->_objectManager->get(\Magento\Framework\TranslateInterface::class); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/controllers/_files/products.php b/dev/tests/integration/testsuite/Magento/Catalog/controllers/_files/products.php index 4a3c8f2e6b96c..17c31f4b3843a 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/controllers/_files/products.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/controllers/_files/products.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - // Copy images to tmp media path use Magento\Framework\App\Filesystem\DirectoryList; @@ -12,8 +11,6 @@ $objectManager->get( \Magento\Framework\View\DesignInterface::class -)->setArea( - 'frontend' )->setDefaultDesignTheme(); /** @var \Magento\Catalog\Model\Product\Media\Config $config */ diff --git a/dev/tests/integration/testsuite/Magento/EncryptionKey/Block/Adminhtml/Crypt/Key/FormTest.php b/dev/tests/integration/testsuite/Magento/EncryptionKey/Block/Adminhtml/Crypt/Key/FormTest.php index 8f6ac72e4a6a2..e4ece95642ea7 100644 --- a/dev/tests/integration/testsuite/Magento/EncryptionKey/Block/Adminhtml/Crypt/Key/FormTest.php +++ b/dev/tests/integration/testsuite/Magento/EncryptionKey/Block/Adminhtml/Crypt/Key/FormTest.php @@ -3,13 +3,17 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\EncryptionKey\Block\Adminhtml\Crypt\Key; +use PHPUnit\Framework\TestCase; + /** * Test class for \Magento\EncryptionKey\Block\Adminhtml\Crypt\Key\Form * @magentoAppArea adminhtml */ -class FormTest extends \PHPUnit\Framework\TestCase +class FormTest extends TestCase { /** * @magentoAppIsolation enabled @@ -20,7 +24,6 @@ public function testPrepareForm() $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $objectManager->get(\Magento\Framework\View\DesignInterface::class) - ->setArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) ->setDefaultDesignTheme(); $block = $objectManager->get(\Magento\Framework\View\LayoutInterface::class) diff --git a/dev/tests/integration/testsuite/Magento/Framework/App/AreaTest.php b/dev/tests/integration/testsuite/Magento/Framework/App/AreaTest.php index 575caf6e3e991..5f1cf820bd345 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/App/AreaTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/App/AreaTest.php @@ -3,11 +3,14 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Framework\App; use Laminas\Stdlib\Parameters; +use PHPUnit\Framework\TestCase; -class AreaTest extends \PHPUnit\Framework\TestCase +class AreaTest extends TestCase { /** * @var \Magento\Framework\App\Area @@ -54,8 +57,6 @@ public function testInitDesign() )->getArea(); $sameDesign = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( \Magento\Framework\View\DesignInterface::class - )->setArea( - $designArea ); $this->assertSame($design, $sameDesign); } diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Model/ResourceModel/Import/DataTest.php b/dev/tests/integration/testsuite/Magento/ImportExport/Model/ResourceModel/Import/DataTest.php index 6552da2be754d..af9bd206a2065 100644 --- a/dev/tests/integration/testsuite/Magento/ImportExport/Model/ResourceModel/Import/DataTest.php +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Model/ResourceModel/Import/DataTest.php @@ -5,15 +5,23 @@ */ namespace Magento\ImportExport\Model\ResourceModel\Import; +use Magento\Backend\Model\Auth; +use Magento\Framework\Exception\LocalizedException; +use Magento\Framework\Registry; +use Magento\TestFramework\Bootstrap; +use Magento\TestFramework\ObjectManager; +use PHPUnit\Framework\TestCase; +use Zend_Db_Expr; + /** * Test Import Data resource model * * @magentoDataFixture Magento/ImportExport/_files/import_data.php */ -class DataTest extends \PHPUnit\Framework\TestCase +class DataTest extends TestCase { /** - * @var \Magento\ImportExport\Model\ResourceModel\Import\Data + * @var Data */ protected $_model; @@ -22,7 +30,7 @@ protected function setUp(): void parent::setUp(); $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\ImportExport\Model\ResourceModel\Import\Data::class + Data::class ); } @@ -31,11 +39,11 @@ protected function setUp(): void */ public function testGetUniqueColumnData() { - /** @var $objectManager \Magento\TestFramework\ObjectManager */ + /** @var $objectManager ObjectManager */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $expectedBunches = $objectManager->get( - \Magento\Framework\Registry::class + Registry::class )->registry( '_fixture/Magento_ImportExport_Import_Data' ); @@ -49,7 +57,7 @@ public function testGetUniqueColumnData() */ public function testGetUniqueColumnDataException() { - $this->expectException(\Magento\Framework\Exception\LocalizedException::class); + $this->expectException(LocalizedException::class); $this->_model->getUniqueColumnData('data'); } @@ -59,11 +67,11 @@ public function testGetUniqueColumnDataException() */ public function testGetBehavior() { - /** @var $objectManager \Magento\TestFramework\ObjectManager */ + /** @var $objectManager ObjectManager */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $expectedBunches = $objectManager->get( - \Magento\Framework\Registry::class + Registry::class )->registry( '_fixture/Magento_ImportExport_Import_Data' ); @@ -76,15 +84,84 @@ public function testGetBehavior() */ public function testGetEntityTypeCode() { - /** @var $objectManager \Magento\TestFramework\ObjectManager */ + /** @var $objectManager ObjectManager */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $expectedBunches = $objectManager->get( - \Magento\Framework\Registry::class + Registry::class )->registry( '_fixture/Magento_ImportExport_Import_Data' ); $this->assertEquals($expectedBunches[0]['entity'], $this->_model->getEntityTypeCode()); } + + /** + * Test that users import data are isolated from each other + */ + public function testUsersImportDataShouldBeIsolated() + { + $count = $this->_model->getConnection()->fetchOne( + $this->_model->getConnection()->select()->from($this->_model->getMainTable(), new Zend_Db_Expr('count(*)')) + ); + $auth = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(Auth::class); + $auth->login(Bootstrap::ADMIN_NAME, Bootstrap::ADMIN_PASSWORD); + $bunches = [ + 0 => [ + 'entity' => 'customer', + 'behavior' => 'delete', + 'data' => [ + [ + 'email' => 'mike.miller.101@magento.com', + '_website' => 'base', + ], + [ + 'email' => 'john.doe.102@magento.com', + '_website' => 'base', + ] + ] + ], + 1 => [ + 'entity' => 'customer', + 'behavior' => 'delete', + 'data' => [ + [ + 'email' => 'jack.simon.103@magento.com', + '_website' => 'base', + ], + ], + ], + ]; + $expectedData = []; + foreach ($bunches as $bunch) { + $this->_model->saveBunch($bunch['entity'], $bunch['behavior'], $bunch['data']); + $expectedData[] = $bunch['data']; + } + $expectedData = array_merge(...$expectedData); + $actualData = []; + while ($data = $this->_model->getNextBunch()) { + $actualData[] = $data; + } + $actualData = array_merge(...$actualData); + $this->assertEquals($expectedData, $actualData); + $this->_model->cleanBunches(); + $actualData = []; + while ($data = $this->_model->getNextBunch()) { + $actualData[] = $data; + } + $this->assertEmpty($actualData); + $newCount = $this->_model->getConnection()->fetchOne( + $this->_model->getConnection()->select()->from($this->_model->getMainTable(), new Zend_Db_Expr('count(*)')) + ); + $this->assertEquals($count, $newCount); + } + + /** + * @inheritDoc + */ + protected function tearDown(): void + { + $this->_model->getConnection()->delete($this->_model->getMainTable()); + parent::tearDown(); + } } diff --git a/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Queue/Edit/FormTest.php b/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Queue/Edit/FormTest.php index df50f80f4ea66..cf1cad58f66ef 100644 --- a/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Queue/Edit/FormTest.php +++ b/dev/tests/integration/testsuite/Magento/Newsletter/Block/Adminhtml/Queue/Edit/FormTest.php @@ -3,13 +3,19 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Newsletter\Block\Adminhtml\Queue\Edit; +use PHPUnit\Framework\TestCase; +use Magento\Backend\App\Area\FrontNameResolver; +use Magento\Newsletter\Model\Queue; + /** * Test class for \Magento\Newsletter\Block\Adminhtml\Queue\Edit\Form * @magentoAppArea adminhtml */ -class FormTest extends \PHPUnit\Framework\TestCase +class FormTest extends TestCase { /** * @magentoAppIsolation enabled @@ -17,20 +23,18 @@ class FormTest extends \PHPUnit\Framework\TestCase public function testPrepareForm() { $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $queue = $objectManager->get(\Magento\Newsletter\Model\Queue::class); + $queue = $objectManager->get(Queue::class); /** @var \Magento\Framework\Registry $registry */ $registry = $objectManager->get(\Magento\Framework\Registry::class); $registry->register('current_queue', $queue); $objectManager->get( \Magento\Framework\View\DesignInterface::class - )->setArea( - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE )->setDefaultDesignTheme(); $objectManager->get( \Magento\Framework\Config\ScopeInterface::class )->setCurrentScope( - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE + FrontNameResolver::AREA_CODE ); $block = $objectManager->create( \Magento\Newsletter\Block\Adminhtml\Queue\Edit\Form::class, @@ -43,8 +47,8 @@ public function testPrepareForm() $prepareFormMethod->setAccessible(true); $statuses = [ - \Magento\Newsletter\Model\Queue::STATUS_NEVER, - \Magento\Newsletter\Model\Queue::STATUS_PAUSE, + Queue::STATUS_NEVER, + Queue::STATUS_PAUSE, ]; foreach ($statuses as $status) { $queue->setQueueStatus($status); diff --git a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Filter/FormTest.php b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Filter/FormTest.php index 62ab380e55983..4613fe808584f 100644 --- a/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Filter/FormTest.php +++ b/dev/tests/integration/testsuite/Magento/Reports/Block/Adminhtml/Filter/FormTest.php @@ -3,13 +3,17 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Reports\Block\Adminhtml\Filter; +use PHPUnit\Framework\TestCase; + /** * Test class for \Magento\Reports\Block\Adminhtml\Filter\Form * @magentoAppArea adminhtml */ -class FormTest extends \PHPUnit\Framework\TestCase +class FormTest extends TestCase { /** * @magentoAppIsolation enabled @@ -18,8 +22,6 @@ public function testPrepareForm() { \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( \Magento\Framework\View\DesignInterface::class - )->setArea( - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE )->setDefaultDesignTheme(); $layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( \Magento\Framework\View\Layout::class diff --git a/dev/tests/integration/testsuite/Magento/Theme/Model/View/DesignTest.php b/dev/tests/integration/testsuite/Magento/Theme/Model/View/DesignTest.php index 3e651a90d1fc5..3b32d6750ae2e 100644 --- a/dev/tests/integration/testsuite/Magento/Theme/Model/View/DesignTest.php +++ b/dev/tests/integration/testsuite/Magento/Theme/Model/View/DesignTest.php @@ -3,17 +3,21 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Theme\Model\View; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Store\Model\ScopeInterface; +use Magento\Framework\App\Area; +use PHPUnit\Framework\TestCase; /** * @magentoComponentsDir Magento/Theme/Model/_files/design * @magentoDbIsolation enabled * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class DesignTest extends \PHPUnit\Framework\TestCase +class DesignTest extends TestCase { /** * @var \Magento\Framework\View\DesignInterface @@ -63,7 +67,7 @@ protected function setUp(): void $this->_model = $objectManager->create(\Magento\Framework\View\DesignInterface::class); $this->_viewFileSystem = $objectManager->create(\Magento\Framework\View\FileSystem::class); $this->_viewConfig = $objectManager->create(\Magento\Framework\View\ConfigInterface::class); - $objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend'); + $objectManager->get(\Magento\Framework\App\State::class)->setAreaCode(Area::AREA_FRONTEND); } /** @@ -73,7 +77,7 @@ protected function setUp(): void */ protected function _emulateFixtureTheme($themePath = 'Test_FrameworkThemeTest/default') { - \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('frontend'); + \Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea(Area::AREA_FRONTEND); $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $objectManager->get(\Magento\Framework\View\DesignInterface::class)->setDesignTheme($themePath); @@ -85,13 +89,13 @@ public function testSetGetArea() { $this->assertEquals(\Magento\Framework\View\DesignInterface::DEFAULT_AREA, $this->_model->getArea()); \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class) - ->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML); - $this->assertEquals(\Magento\Framework\App\Area::AREA_ADMINHTML, $this->_model->getArea()); + ->setAreaCode(Area::AREA_ADMINHTML); + $this->assertEquals(Area::AREA_ADMINHTML, $this->_model->getArea()); } public function testSetDesignTheme() { - $this->_model->setDesignTheme('Magento/blank', 'frontend'); + $this->_model->setDesignTheme('Magento/blank', Area::AREA_FRONTEND); $this->assertEquals('Magento/blank', $this->_model->getDesignTheme()->getThemePath()); } @@ -114,11 +118,11 @@ public function testGetConfigurationDesignThemeDefaults() $model = $objectManager->get(\Magento\Theme\Model\View\Design::class); $this->assertEquals('test_f', $model->getConfigurationDesignTheme()); - $this->assertEquals('test_f', $model->getConfigurationDesignTheme('frontend')); - $this->assertEquals('test_f', $model->getConfigurationDesignTheme('frontend', ['store' => 0])); - $this->assertEquals('test_f', $model->getConfigurationDesignTheme('frontend', ['store' => null])); - $this->assertEquals('test_a', $model->getConfigurationDesignTheme('adminhtml')); - $this->assertEquals('test_a', $model->getConfigurationDesignTheme('adminhtml', ['store' => uniqid()])); + $this->assertEquals('test_f', $model->getConfigurationDesignTheme(Area::AREA_FRONTEND)); + $this->assertEquals('test_f', $model->getConfigurationDesignTheme(Area::AREA_FRONTEND, ['store' => 0])); + $this->assertEquals('test_f', $model->getConfigurationDesignTheme(Area::AREA_FRONTEND, ['store' => null])); + $this->assertEquals('test_a', $model->getConfigurationDesignTheme(Area::AREA_ADMINHTML)); + $this->assertEquals('test_a', $model->getConfigurationDesignTheme(Area::AREA_ADMINHTML, ['store' => uniqid()])); } /** @@ -138,11 +142,11 @@ public function testGetConfigurationDesignThemeStore() ->getId(); $this->assertEquals('one', $this->_model->getConfigurationDesignTheme()); $this->assertEquals('one', $this->_model->getConfigurationDesignTheme(null, ['store' => $storeId])); - $this->assertEquals('one', $this->_model->getConfigurationDesignTheme('frontend', ['store' => $storeId])); + $this->assertEquals('one', $this->_model->getConfigurationDesignTheme(Area::AREA_FRONTEND, ['store' => $storeId])); $this->assertEquals('two', $this->_model->getConfigurationDesignTheme(null, ['store' => 'fixturestore'])); $this->assertEquals( 'two', - $this->_model->getConfigurationDesignTheme('frontend', ['store' => 'fixturestore']) + $this->_model->getConfigurationDesignTheme(Area::AREA_FRONTEND, ['store' => 'fixturestore']) ); } diff --git a/lib/internal/Magento/Framework/App/Area.php b/lib/internal/Magento/Framework/App/Area.php index ea8f96e0c0467..362d19ed0f327 100644 --- a/lib/internal/Magento/Framework/App/Area.php +++ b/lib/internal/Magento/Framework/App/Area.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\Framework\App; @@ -18,24 +17,24 @@ */ class Area implements \Magento\Framework\App\AreaInterface { - const AREA_GLOBAL = 'global'; - const AREA_FRONTEND = 'frontend'; - const AREA_ADMINHTML = 'adminhtml'; - const AREA_DOC = 'doc'; - const AREA_CRONTAB = 'crontab'; - const AREA_WEBAPI_REST = 'webapi_rest'; - const AREA_WEBAPI_SOAP = 'webapi_soap'; - const AREA_GRAPHQL = 'graphql'; + public const AREA_GLOBAL = 'global'; + public const AREA_FRONTEND = 'frontend'; + public const AREA_ADMINHTML = 'adminhtml'; + public const AREA_DOC = 'doc'; + public const AREA_CRONTAB = 'crontab'; + public const AREA_WEBAPI_REST = 'webapi_rest'; + public const AREA_WEBAPI_SOAP = 'webapi_soap'; + public const AREA_GRAPHQL = 'graphql'; /** * @deprecated */ - const AREA_ADMIN = 'admin'; + public const AREA_ADMIN = 'admin'; /** * Area parameter. */ - const PARAM_AREA = 'area'; + public const PARAM_AREA = 'area'; /** * Array of area loaded parts @@ -261,7 +260,7 @@ protected function _initTranslate() */ protected function _initDesign() { - $this->_getDesign()->setArea($this->_code)->setDefaultDesignTheme(); + $this->_getDesign()->setDefaultDesignTheme(); return $this; } } diff --git a/lib/internal/Magento/Framework/App/Config/ValueInterface.php b/lib/internal/Magento/Framework/App/Config/ValueInterface.php index a81ff2d325e0c..da237d359c84a 100644 --- a/lib/internal/Magento/Framework/App/Config/ValueInterface.php +++ b/lib/internal/Magento/Framework/App/Config/ValueInterface.php @@ -1,7 +1,5 @@ method('get') ->with(\Magento\Framework\View\DesignInterface::class) ->willReturn($designMock); - $designMock->expects($this->once()) - ->method('setArea') - ->with($this->areaCode) - ->willReturnSelf(); $designMock->expects($this->once()) ->method('setDefaultDesignTheme'); $this->object->load(Area::PART_DESIGN); @@ -207,10 +203,6 @@ public function testLoad() $designMock = $this->getMockBuilder(\Magento\Framework\View\DesignInterface::class) ->disableOriginalConstructor() ->getMock(); - $designMock->expects($this->once()) - ->method('setArea') - ->with($this->areaCode) - ->willReturnSelf(); $designMock->expects($this->once()) ->method('setDefaultDesignTheme'); $this->objectManagerMock->expects($this->exactly(2)) diff --git a/lib/internal/Magento/Framework/MessageQueue/ConsumerConfigurationInterface.php b/lib/internal/Magento/Framework/MessageQueue/ConsumerConfigurationInterface.php index eca5134064288..a3e0ff68b397b 100644 --- a/lib/internal/Magento/Framework/MessageQueue/ConsumerConfigurationInterface.php +++ b/lib/internal/Magento/Framework/MessageQueue/ConsumerConfigurationInterface.php @@ -45,16 +45,6 @@ public function getConsumerName(); */ public function getQueueName(); - /** - * Get consumer type sync|async. - * - * @return string - * @deprecated 103.0.0 - * @see \Magento\Framework\Communication\ConfigInterface::getTopic - * @throws \LogicException - */ - public function getType(); - /** * Get maximum number of message, which will be read by consumer before termination of the process. * diff --git a/lib/internal/Magento/Framework/View/DesignInterface.php b/lib/internal/Magento/Framework/View/DesignInterface.php index 64e11b09f6c36..c42673be4760f 100644 --- a/lib/internal/Magento/Framework/View/DesignInterface.php +++ b/lib/internal/Magento/Framework/View/DesignInterface.php @@ -31,15 +31,6 @@ interface DesignInterface */ const XML_PATH_THEME_ID = 'design/theme/theme_id'; - /** - * Set package area - * - * @param string $area - * @return DesignInterface - * @TODO MAGETWO-31474: Remove deprecated method setArea - */ - public function setArea($area); - /** * Retrieve package area * diff --git a/lib/internal/Magento/Framework/Webapi/CustomAttributeTypeLocatorInterface.php b/lib/internal/Magento/Framework/Webapi/CustomAttributeTypeLocatorInterface.php index 43ba64dbdef48..cb444d695437d 100644 --- a/lib/internal/Magento/Framework/Webapi/CustomAttributeTypeLocatorInterface.php +++ b/lib/internal/Magento/Framework/Webapi/CustomAttributeTypeLocatorInterface.php @@ -22,13 +22,4 @@ interface CustomAttributeTypeLocatorInterface * @return string */ public function getType($attributeCode, $entityType); - - /** - * Get list of all Data Interface corresponding to complex custom attribute types - * - * @return string[] array of Data Interface class names - * @deprecated 102.0.0 - * @see \Magento\Framework\Webapi\CustomAttribute\ServiceTypeListInterface::getDataTypes() - */ - public function getAllServiceDataInterfaces(); }