From fdec82c179e1e3de4505d2ad62321ce303e56ff3 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Fri, 28 Feb 2020 12:08:11 +1100 Subject: [PATCH 01/95] Customer attribute frontend labels not using the store label values --- .../Customer/Block/DataProviders/AddressAttributeData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php b/app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php index 2be340c8ccca4..74152ffebea08 100644 --- a/app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php +++ b/app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php @@ -52,7 +52,7 @@ public function getFrontendLabel(string $attributeCode): string { try { $attribute = $this->addressMetadata->getAttributeMetadata($attributeCode); - $frontendLabel = $attribute->getFrontendLabel(); + $frontendLabel = $attribute->getStoreLabel ?: $attribute->getFrontendLabel(); } catch (NoSuchEntityException $e) { $frontendLabel = ''; } From 9a7d68d176e1300dea2d52f41357cf79d71bec4c Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Fri, 28 Feb 2020 16:38:03 +1100 Subject: [PATCH 02/95] Fixed silly issue --- .../Customer/Block/DataProviders/AddressAttributeData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php b/app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php index 74152ffebea08..b4c737f6600bf 100644 --- a/app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php +++ b/app/code/Magento/Customer/Block/DataProviders/AddressAttributeData.php @@ -52,7 +52,7 @@ public function getFrontendLabel(string $attributeCode): string { try { $attribute = $this->addressMetadata->getAttributeMetadata($attributeCode); - $frontendLabel = $attribute->getStoreLabel ?: $attribute->getFrontendLabel(); + $frontendLabel = $attribute->getStoreLabel() ?: $attribute->getFrontendLabel(); } catch (NoSuchEntityException $e) { $frontendLabel = ''; } From 0bf66d9f82f793c9ec205f38e0f9005c2233297b Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Tue, 3 Mar 2020 13:21:34 +1100 Subject: [PATCH 03/95] Added integration test to cover the changes --- .../Customer/Block/Form/RegisterTest.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php index cb07b1a401fdf..02fa98cab3b9a 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php @@ -138,6 +138,31 @@ public function testFaxEnabled(): void $this->assertContains('title="Fax"', $block->toHtml()); } + /** + * @magentoAppIsolation enabled + * @magentoDbIsolation enabled + * @return void + */ + public function testTelephoneWithStoreLabel(): void + { + /** @var \Magento\Customer\Model\Attribute $model */ + $model = Bootstrap::getObjectManager()->create( + \Magento\Customer\Model\Attribute::class + ); + $model->loadByCode('customer_address', 'telephone')->setIsVisible('1')->setStoreLabel('Telephone2'); + $model->save(); + + /** @var \Magento\Customer\Block\Form\Register $block */ + $block = Bootstrap::getObjectManager()->create( + Register::class + )->setTemplate('Magento_Customer::form/register.phtml') + ->setShowAddressFields(true); + $this->setAttributeDataProvider($block); + + $this->assertNotContains('title="Phone Number"', $block->toHtml()); + $this->assertContains('title="Telephone2"', $block->toHtml()); + } + /** * @inheritdoc */ From aa148c330e63db3917cb89f5ee192bb710218207 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Wed, 4 Mar 2020 08:41:50 +1100 Subject: [PATCH 04/95] Fixed the integration test --- .../Magento/Customer/Block/Form/RegisterTest.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php index 02fa98cab3b9a..a3d05516283d4 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php @@ -145,11 +145,21 @@ public function testFaxEnabled(): void */ public function testTelephoneWithStoreLabel(): void { + /** @var \Magento\Store\Model\StoreManager $storeManager */ + $storeManager = Bootstrap::getObjectManager()->create( + \Magento\Store\Model\StoreManagerInterface::class + ); + $websites = $storeManager->getWebsites(); /** @var \Magento\Customer\Model\Attribute $model */ $model = Bootstrap::getObjectManager()->create( \Magento\Customer\Model\Attribute::class ); - $model->loadByCode('customer_address', 'telephone')->setIsVisible('1')->setStoreLabel('Telephone2'); + $model->loadByCode('customer_address', 'telephone')->setIsVisible('1'); + $storeLabels = $model->getStoreLabels(); + foreach ($websites as $website) { + $storeLabels[$website->getId()] = 'Phone NumberX'; + } + $model->setStoreLabels([$storeLabels]); $model->save(); /** @var \Magento\Customer\Block\Form\Register $block */ @@ -160,7 +170,7 @@ public function testTelephoneWithStoreLabel(): void $this->setAttributeDataProvider($block); $this->assertNotContains('title="Phone Number"', $block->toHtml()); - $this->assertContains('title="Telephone2"', $block->toHtml()); + $this->assertContains('title="Phone NumberX"', $block->toHtml()); } /** @@ -185,3 +195,4 @@ private function setAttributeDataProvider(Template $block): void $block->setAttributeData($attributeData); } } + From 705b5be7119c31284ebf862bdf0a9b6bf2a909d7 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Wed, 4 Mar 2020 09:34:45 +1100 Subject: [PATCH 05/95] Fix static tests --- .../testsuite/Magento/Customer/Block/Form/RegisterTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php index a3d05516283d4..6cd43a70164d3 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php @@ -195,4 +195,3 @@ private function setAttributeDataProvider(Template $block): void $block->setAttributeData($attributeData); } } - From 5749b24d5090354c2f5fd3d6569b1297b3810a1b Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Wed, 4 Mar 2020 11:18:38 +1100 Subject: [PATCH 06/95] Fixed the integration test --- .../Magento/Customer/Block/Form/RegisterTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php index 6cd43a70164d3..0a56bcb6c3737 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php @@ -150,11 +150,11 @@ public function testTelephoneWithStoreLabel(): void \Magento\Store\Model\StoreManagerInterface::class ); $websites = $storeManager->getWebsites(); - /** @var \Magento\Customer\Model\Attribute $model */ - $model = Bootstrap::getObjectManager()->create( - \Magento\Customer\Model\Attribute::class + /** @var \Magento\Eav\Model\Config $eavConfig */ + $eavConfig = Bootstrap::getObjectManager()->create( + \Magento\Eav\Model\Config::class ); - $model->loadByCode('customer_address', 'telephone')->setIsVisible('1'); + $model = $eavConfig->getAttribute('customer_address', 'telephone'); $storeLabels = $model->getStoreLabels(); foreach ($websites as $website) { $storeLabels[$website->getId()] = 'Phone NumberX'; From d4ba184dbd9d371713ac998dbdb00077a0f725cc Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Fri, 6 Mar 2020 09:18:42 +1100 Subject: [PATCH 07/95] Fixing the integration test --- .../testsuite/Magento/Customer/Block/Form/RegisterTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php index 0a56bcb6c3737..61720c5adbf3f 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php @@ -149,15 +149,15 @@ public function testTelephoneWithStoreLabel(): void $storeManager = Bootstrap::getObjectManager()->create( \Magento\Store\Model\StoreManagerInterface::class ); - $websites = $storeManager->getWebsites(); + $stores = $storeManager->getStores(); /** @var \Magento\Eav\Model\Config $eavConfig */ $eavConfig = Bootstrap::getObjectManager()->create( \Magento\Eav\Model\Config::class ); $model = $eavConfig->getAttribute('customer_address', 'telephone'); $storeLabels = $model->getStoreLabels(); - foreach ($websites as $website) { - $storeLabels[$website->getId()] = 'Phone NumberX'; + foreach ($stores as $store) { + $storeLabels[$store->getId()] = 'Phone NumberX'; } $model->setStoreLabels([$storeLabels]); $model->save(); From cec82daeb82b39cc5643e5a14eadad9dd5119cd1 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Fri, 6 Mar 2020 11:48:10 +1100 Subject: [PATCH 08/95] Fixing the integration test --- .../testsuite/Magento/Customer/Block/Form/RegisterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php index 61720c5adbf3f..c05defefa8b7d 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php @@ -140,7 +140,7 @@ public function testFaxEnabled(): void /** * @magentoAppIsolation enabled - * @magentoDbIsolation enabled + * @magentoDbIsolation disabled * @return void */ public function testTelephoneWithStoreLabel(): void From 88da24aea8f0d535324a7196c09fe37c78bbd08a Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Thu, 12 Mar 2020 16:34:03 +1100 Subject: [PATCH 09/95] Switched to use data fixture in the integration tests --- .../Customer/Block/Form/RegisterTest.php | 27 +++---------------- .../attribute_city_store_label_address.php | 19 +++++++++++++ 2 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php index c05defefa8b7d..d9c9b0a97f85b 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php @@ -139,29 +139,10 @@ public function testFaxEnabled(): void } /** - * @magentoAppIsolation enabled - * @magentoDbIsolation disabled - * @return void + * @magentoDataFixture Magento/Customer/_files/attribute_city_store_label_address.php */ - public function testTelephoneWithStoreLabel(): void + public function testCityWithStoreLabel(): void { - /** @var \Magento\Store\Model\StoreManager $storeManager */ - $storeManager = Bootstrap::getObjectManager()->create( - \Magento\Store\Model\StoreManagerInterface::class - ); - $stores = $storeManager->getStores(); - /** @var \Magento\Eav\Model\Config $eavConfig */ - $eavConfig = Bootstrap::getObjectManager()->create( - \Magento\Eav\Model\Config::class - ); - $model = $eavConfig->getAttribute('customer_address', 'telephone'); - $storeLabels = $model->getStoreLabels(); - foreach ($stores as $store) { - $storeLabels[$store->getId()] = 'Phone NumberX'; - } - $model->setStoreLabels([$storeLabels]); - $model->save(); - /** @var \Magento\Customer\Block\Form\Register $block */ $block = Bootstrap::getObjectManager()->create( Register::class @@ -169,8 +150,8 @@ public function testTelephoneWithStoreLabel(): void ->setShowAddressFields(true); $this->setAttributeDataProvider($block); - $this->assertNotContains('title="Phone Number"', $block->toHtml()); - $this->assertContains('title="Phone NumberX"', $block->toHtml()); + $this->assertNotContains('title="City"', $block->toHtml()); + $this->assertContains('title="Suburb"', $block->toHtml()); } /** diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php b/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php new file mode 100644 index 0000000000000..fabaaff877dce --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php @@ -0,0 +1,19 @@ +create(\Magento\Customer\Model\Attribute::class); +/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */ +$storeManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\StoreManager::class); +$model->loadByCode('customer_address', 'city'); +$storeLabels = $model->getStoreLabels(); +$websites = $storeManager->getWebsites(); +/** @var \Magento\Store\Api\Data\WebsiteInterface $website */ +foreach ($websites as $website) { + $storeLabels[$website->getId()] = 'Suburb'; +} +$model->setStoreLabels($storeLabels); +$model->save(); From 9f20b7f030ca5c9a399a3ec556fd391a1fa306a0 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Fri, 13 Mar 2020 09:33:53 +1100 Subject: [PATCH 10/95] Fixed static tests --- .../testsuite/Magento/Customer/Block/Form/RegisterTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php index d9c9b0a97f85b..ba29a94961f5a 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php @@ -12,6 +12,7 @@ /** * Test class for \Magento\Customer\Block\Form\Register * + * @codingStandardsIgnoreFile * @magentoAppArea frontend */ class RegisterTest extends \PHPUnit\Framework\TestCase From b1480fbb4e127ffd9e36e7a78d1b380a9b90321a Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Fri, 13 Mar 2020 09:42:02 +1100 Subject: [PATCH 11/95] Fixed static tests --- .../Customer/_files/attribute_city_store_label_address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php b/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php index fabaaff877dce..17fe79aa86645 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - +//@codingStandardsIgnoreFile /** @var \Magento\Customer\Model\Attribute $model */ $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Customer\Model\Attribute::class); /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */ From b06db1f34b6799255a1cc7f596e21190ebaec7f2 Mon Sep 17 00:00:00 2001 From: Jiten Patel Date: Fri, 20 Mar 2020 11:07:11 +0530 Subject: [PATCH 12/95] Fixed issue 27051: Saving an attribute with backend_type static --- .../Catalog/Controller/Adminhtml/Product/Attribute/Save.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php index 853cc65270306..0fcad1177dd85 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute/Save.php @@ -258,6 +258,10 @@ public function execute() unset($data['apply_to']); } + if ($model->getBackendType() == 'static' && !$model->getIsUserDefined()) { + $data['frontend_class'] = $model->getFrontendClass(); + } + $model->addData($data); if (!$attributeId) { From 54a11eb67d5ad3b0f2ca0160dcfa936d50b44d33 Mon Sep 17 00:00:00 2001 From: Quang Do Date: Wed, 25 Mar 2020 11:31:53 +1030 Subject: [PATCH 13/95] Add ACL role ID to category tree cache id --- .../DataProvider/Product/Form/Modifier/Categories.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php index cd1f8e8e3379b..46302185735f9 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php @@ -18,6 +18,7 @@ use Magento\Framework\UrlInterface; use Magento\Framework\Stdlib\ArrayManager; use Magento\Framework\AuthorizationInterface; +use Magento\Backend\Model\Auth\Session; /** * Data provider for categories field of product page @@ -86,12 +87,18 @@ class Categories extends AbstractModifier */ private $authorization; + /** + * @var Session + */ + private $session; + /** * @param LocatorInterface $locator * @param CategoryCollectionFactory $categoryCollectionFactory * @param DbHelper $dbHelper * @param UrlInterface $urlBuilder * @param ArrayManager $arrayManager + * @param Session $session * @param SerializerInterface $serializer * @param AuthorizationInterface $authorization */ @@ -101,6 +108,7 @@ public function __construct( DbHelper $dbHelper, UrlInterface $urlBuilder, ArrayManager $arrayManager, + Session $session, SerializerInterface $serializer = null, AuthorizationInterface $authorization = null ) { @@ -111,6 +119,7 @@ public function __construct( $this->arrayManager = $arrayManager; $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); $this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class); + $this->session = $session; } /** @@ -373,6 +382,7 @@ private function getCategoriesTreeCacheId(int $storeId, string $filter = '') : s { return self::CATEGORY_TREE_ID . '_' . (string) $storeId + . '_' . $this->session->getUser()->getAclRole() . '_' . $filter; } From f1c8ad56edcad49fd51288e3a0dbf2df74505df5 Mon Sep 17 00:00:00 2001 From: Quang Do Date: Wed, 25 Mar 2020 15:21:27 +1030 Subject: [PATCH 14/95] Ensure constructor change is backwards compatible --- .../Ui/DataProvider/Product/Form/Modifier/Categories.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php index 46302185735f9..b5b270e17a581 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php @@ -98,9 +98,9 @@ class Categories extends AbstractModifier * @param DbHelper $dbHelper * @param UrlInterface $urlBuilder * @param ArrayManager $arrayManager - * @param Session $session * @param SerializerInterface $serializer * @param AuthorizationInterface $authorization + * @param Session $session */ public function __construct( LocatorInterface $locator, @@ -108,9 +108,9 @@ public function __construct( DbHelper $dbHelper, UrlInterface $urlBuilder, ArrayManager $arrayManager, - Session $session, SerializerInterface $serializer = null, - AuthorizationInterface $authorization = null + AuthorizationInterface $authorization = null, + Session $session = null ) { $this->locator = $locator; $this->categoryCollectionFactory = $categoryCollectionFactory; @@ -119,7 +119,7 @@ public function __construct( $this->arrayManager = $arrayManager; $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); $this->authorization = $authorization ?: ObjectManager::getInstance()->get(AuthorizationInterface::class); - $this->session = $session; + $this->session = $session ?: ObjectManager::getInstance()->get(Session::class); } /** From 207a44956715bee23dbd7c0ded5735283299f9cc Mon Sep 17 00:00:00 2001 From: Quang Do Date: Wed, 25 Mar 2020 15:22:09 +1030 Subject: [PATCH 15/95] Suppress CookieAndSessionMisuse --- .../Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php index b5b270e17a581..1c04879ef36da 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php @@ -25,6 +25,7 @@ * * @api * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) * @since 101.0.0 */ class Categories extends AbstractModifier From 61f847ec3edbf7c91ae7158d81778109c0821fbc Mon Sep 17 00:00:00 2001 From: Quang Do Date: Wed, 25 Mar 2020 15:25:35 +1030 Subject: [PATCH 16/95] Add null check for admin session user --- .../DataProvider/Product/Form/Modifier/Categories.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php index 1c04879ef36da..ce5b740fe5fb0 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php @@ -379,11 +379,16 @@ protected function getCategoriesTree($filter = null) * @param string $filter * @return string */ - private function getCategoriesTreeCacheId(int $storeId, string $filter = '') : string + private function getCategoriesTreeCacheId(int $storeId, string $filter = ''): string { + if ($this->session->getUser() !== null) { + return self::CATEGORY_TREE_ID + . '_' . (string)$storeId + . '_' . $this->session->getUser()->getAclRole() + . '_' . $filter; + } return self::CATEGORY_TREE_ID - . '_' . (string) $storeId - . '_' . $this->session->getUser()->getAclRole() + . '_' . (string)$storeId . '_' . $filter; } From dec273fc98927ca8ffb97595f907322aecb3a371 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Mon, 30 Mar 2020 13:35:01 +0700 Subject: [PATCH 17/95] Remove the annotations --- .../testsuite/Magento/Customer/Block/Form/RegisterTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php index ba29a94961f5a..d9c9b0a97f85b 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Form/RegisterTest.php @@ -12,7 +12,6 @@ /** * Test class for \Magento\Customer\Block\Form\Register * - * @codingStandardsIgnoreFile * @magentoAppArea frontend */ class RegisterTest extends \PHPUnit\Framework\TestCase From 458ce8d9c511c734f078a0ecc6130db913ce9575 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Mon, 30 Mar 2020 13:35:42 +0700 Subject: [PATCH 18/95] Update fixtures --- .../Customer/_files/attribute_city_store_label_address.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php b/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php index 17fe79aa86645..8a4afc23aaea8 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/attribute_city_store_label_address.php @@ -10,10 +10,10 @@ $storeManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\StoreManager::class); $model->loadByCode('customer_address', 'city'); $storeLabels = $model->getStoreLabels(); -$websites = $storeManager->getWebsites(); +$stores = $storeManager->getStores(); /** @var \Magento\Store\Api\Data\WebsiteInterface $website */ -foreach ($websites as $website) { - $storeLabels[$website->getId()] = 'Suburb'; +foreach ($stores as $store) { + $storeLabels[$store->getId()] = 'Suburb'; } $model->setStoreLabels($storeLabels); $model->save(); From d95a65adde03f8a573b0b1dd15d0c5a247d8d99d Mon Sep 17 00:00:00 2001 From: Sathish Date: Fri, 3 Apr 2020 22:38:09 +0530 Subject: [PATCH 19/95] #27091 removed array print while setup upgrade --- setup/src/Magento/Setup/Model/Installer.php | 14 +- .../Setup/Test/Unit/Model/InstallerTest.php | 1413 +++++++++-------- 2 files changed, 754 insertions(+), 673 deletions(-) diff --git a/setup/src/Magento/Setup/Model/Installer.php b/setup/src/Magento/Setup/Model/Installer.php index 535040f942b89..bfab9b68e4aaf 100644 --- a/setup/src/Magento/Setup/Model/Installer.php +++ b/setup/src/Magento/Setup/Model/Installer.php @@ -46,6 +46,7 @@ use Magento\Setup\Module\SetupFactory; use Magento\Setup\Validator\DbValidator; use Magento\Store\Model\Store; +use Magento\Framework\App\Cache\Manager; /** * Class Installer contains the logic to install Magento application. @@ -1272,8 +1273,8 @@ public function uninstall() */ private function updateCaches($isEnabled, $types = []) { - /** @var \Magento\Framework\App\Cache\Manager $cacheManager */ - $cacheManager = $this->objectManagerProvider->get()->create(\Magento\Framework\App\Cache\Manager::class); + /** @var Manager $cacheManager */ + $cacheManager = $this->objectManagerProvider->get()->create(Manager::class); $availableTypes = $cacheManager->getAvailableTypes(); $types = empty($types) ? $availableTypes : array_intersect($availableTypes, $types); @@ -1292,8 +1293,9 @@ function (string $key) use ($types) { ); $this->log->log('Current status:'); - // phpcs:ignore Magento2.Functions.DiscouragedFunction - $this->log->log(print_r($cacheStatus, true)); + foreach ($cacheStatus as $cache => $status) { + $this->log->log(sprintf('%s: %d', $cache, $status)); + } } /** @@ -1305,8 +1307,8 @@ function (string $key) use ($types) { */ private function cleanCaches() { - /** @var \Magento\Framework\App\Cache\Manager $cacheManager */ - $cacheManager = $this->objectManagerProvider->get()->get(\Magento\Framework\App\Cache\Manager::class); + /** @var Manager $cacheManager */ + $cacheManager = $this->objectManagerProvider->get()->get(Manager::class); $types = $cacheManager->getAvailableTypes(); $cacheManager->clean($types); $this->log->log('Cache cleared successfully'); diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 2b992c30615c2..1f9afb04c07dd 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -3,723 +3,802 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + +namespace Magento\Setup\Test\Unit\Model; + +use Magento\Backend\Setup\ConfigOptionsList; +use Magento\Framework\Config\ConfigOptionsListConstants; +use Magento\Framework\Setup\SchemaListener; +use Magento\Setup\Model\AdminAccount; +use Magento\Setup\Model\DeclarationInstaller; +use Magento\Setup\Model\Installer; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem\DriverPool; +use Magento\Framework\Config\File\ConfigFilePool; +use Magento\Framework\App\State as MFAState; +use Magento\Framework\App\State\CleanupFiles; +use Magento\Framework\Setup\Patch\PatchApplier; +use Magento\Framework\Setup\Patch\PatchApplierFactory; +use Magento\Setup\Validator\DbValidator; +use Magento\Framework\Setup\FilePermissions; +use Magento\Framework\App\DeploymentConfig\Writer; +use Magento\Framework\App\DeploymentConfig\Reader; +use Magento\Framework\App\DeploymentConfig; +use Magento\Framework\Module\ModuleListInterface; +use Magento\Framework\Module\ModuleList\Loader; +use Magento\Setup\Model\AdminAccountFactory; +use Magento\Framework\Setup\LoggerInterface; +use Magento\Framework\Math\Random; +use Magento\Framework\DB\Adapter\AdapterInterface; +use Magento\Setup\Module\ConnectionFactory; +use Magento\Framework\App\MaintenanceMode; +use Magento\Framework\Filesystem; +use Magento\Setup\Model\PhpReadinessCheck; +use Magento\Framework\Model\ResourceModel\Db\Context; +use Magento\Framework\Component\ComponentRegistrar; +use Magento\Framework\Setup\SampleData\State; +use Magento\Setup\Module\DataSetupFactory; +use Magento\Setup\Module\DataSetup; +use Magento\Setup\Module\SetupFactory; +use Magento\Setup\Model\ConfigModel; +use Magento\Setup\Module\Setup; +use Magento\Framework\DB\Ddl\Table; +use Magento\Framework\App\ResourceConnection; +use Magento\Framework\App\Cache\Manager; +use Magento\Framework\Registry; +use Magento\Framework\App\Area; +use Magento\Setup\Controller\ResponseTypeInterface; +use Magento\Framework\Filesystem\Directory\WriteInterface; +use Magento\Setup\Model\ObjectManagerProvider; +use Magento\Framework\ObjectManagerInterface; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; -namespace Magento\Setup\Test\Unit\Model { +/** + * Unit test for Magento\Setup\Model\Installer + * + * @SuppressWarnings(PHPMD.TooManyFields) + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +class InstallerTest extends TestCase +{ + /** + * @var Installer + */ + private $object; - use Magento\Backend\Setup\ConfigOptionsList; - use Magento\Framework\Config\ConfigOptionsListConstants; - use Magento\Framework\Setup\SchemaListener; - use Magento\Setup\Model\AdminAccount; - use Magento\Setup\Model\DeclarationInstaller; - use Magento\Setup\Model\Installer; - use Magento\Framework\App\Filesystem\DirectoryList; - use Magento\Framework\Filesystem\DriverPool; - use Magento\Framework\Config\File\ConfigFilePool; - use Magento\Framework\App\State\CleanupFiles; - use Magento\Framework\Setup\Patch\PatchApplier; - use Magento\Framework\Setup\Patch\PatchApplierFactory; - use Magento\Setup\Validator\DbValidator; + /** + * @var FilePermissions|MockObject + */ + private $filePermissionsMock; /** - * @SuppressWarnings(PHPMD.TooManyFields) - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @var Writer|MockObject */ - class InstallerTest extends \PHPUnit\Framework\TestCase - { - /** - * @var \Magento\Setup\Model\Installer - */ - private $object; - - /** - * @var \Magento\Framework\Setup\FilePermissions|\PHPUnit_Framework_MockObject_MockObject - */ - private $filePermissions; - - /** - * @var \Magento\Framework\App\DeploymentConfig\Writer|\PHPUnit_Framework_MockObject_MockObject - */ - private $configWriter; - - /** - * @var \Magento\Framework\App\DeploymentConfig\Reader|\PHPUnit_Framework_MockObject_MockObject - */ - private $configReader; - - /** - * @var \Magento\Framework\App\DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject - */ - private $config; - - /** - * @var \Magento\Framework\Module\ModuleListInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $moduleList; - - /** - * @var \Magento\Framework\Module\ModuleList\Loader|\PHPUnit_Framework_MockObject_MockObject - */ - private $moduleLoader; - - /** - * @var \Magento\Framework\App\Filesystem\DirectoryList|\PHPUnit_Framework_MockObject_MockObject - */ - private $directoryList; - - /** - * @var \Magento\Setup\Model\AdminAccountFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $adminFactory; - - /** - * @var \Magento\Framework\Setup\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject - */ - private $logger; - - /** - * @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject - */ - private $random; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $connection; - - /** - * @var \Magento\Framework\App\MaintenanceMode|\PHPUnit_Framework_MockObject_MockObject - */ - private $maintenanceMode; - - /** - * @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject - */ - private $filesystem; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $objectManager; - - /** - * @var \Magento\Setup\Model\ConfigModel|\PHPUnit_Framework_MockObject_MockObject - */ - private $configModel; - - /** - * @var CleanupFiles|\PHPUnit_Framework_MockObject_MockObject - */ - private $cleanupFiles; - - /** - * @var DbValidator|\PHPUnit_Framework_MockObject_MockObject - */ - private $dbValidator; - - /** - * @var \Magento\Setup\Module\SetupFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $setupFactory; - - /** - * @var \Magento\Setup\Module\DataSetupFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $dataSetupFactory; - - /** - * @var \Magento\Framework\Setup\SampleData\State|\PHPUnit_Framework_MockObject_MockObject - */ - private $sampleDataState; - - /** - * @var \Magento\Framework\Component\ComponentRegistrar|\PHPUnit_Framework_MockObject_MockObject - */ - private $componentRegistrar; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\PhpReadinessCheck - */ - private $phpReadinessCheck; - - /** - * @var \Magento\Framework\Setup\DeclarationInstaller|\PHPUnit_Framework_MockObject_MockObject - */ - private $declarationInstallerMock; - - /** - * @var SchemaListener|\PHPUnit_Framework_MockObject_MockObject - */ - private $schemaListenerMock; - - /** - * Sample DB configuration segment - * @var array - */ - private static $dbConfig = [ - 'default' => [ - ConfigOptionsListConstants::KEY_HOST => '127.0.0.1', - ConfigOptionsListConstants::KEY_NAME => 'magento', - ConfigOptionsListConstants::KEY_USER => 'magento', - ConfigOptionsListConstants::KEY_PASSWORD => '', - ] - ]; + private $configWriterMock; + + /** + * @var Reader|MockObject + */ + private $configReaderMock; + + /** + * @var DeploymentConfig|MockObject + */ + private $configMock; + + /** + * @var ModuleListInterface|MockObject + */ + private $moduleListMock; + + /** + * @var Loader|MockObject + */ + private $moduleLoaderMock; - /** - * @var \Magento\Framework\Model\ResourceModel\Db\Context|\PHPUnit_Framework_MockObject_MockObject - */ - private $contextMock; - - /** - * @var PatchApplier|\PHPUnit_Framework_MockObject_MockObject - */ - private $patchApplierMock; - - /** - * @var PatchApplierFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $patchApplierFactoryMock; - - protected function setUp() - { - $this->filePermissions = $this->createMock(\Magento\Framework\Setup\FilePermissions::class); - $this->configWriter = $this->createMock(\Magento\Framework\App\DeploymentConfig\Writer::class); - $this->configReader = $this->createMock(\Magento\Framework\App\DeploymentConfig\Reader::class); - $this->config = $this->createMock(\Magento\Framework\App\DeploymentConfig::class); - - $this->moduleList = $this->getMockForAbstractClass(\Magento\Framework\Module\ModuleListInterface::class); - $this->moduleList->expects($this->any())->method('getOne')->willReturn( + /** + * @var AdminAccountFactory|MockObject + */ + private $adminFactoryMock; + + /** + * @var LoggerInterface|MockObject + */ + private $loggerMock; + + /** + * @var Random|MockObject + */ + private $randomMock; + + /** + * @var AdapterInterface|MockObject + */ + private $connectionMock; + + /** + * @var MaintenanceMode|MockObject + */ + private $maintenanceModeMock; + + /** + * @var Filesystem|MockObject + */ + private $filesystemMock; + + /** + * @var ObjectManager|MockObject + */ + private $objectManager; + + /** + * @var ConfigModel|MockObject + */ + private $configModelMock; + + /** + * @var CleanupFiles|MockObject + */ + private $cleanupFilesMock; + + /** + * @var DbValidator|MockObject + */ + private $dbValidatorMock; + + /** + * @var SetupFactory|MockObject + */ + private $setupFactoryMock; + + /** + * @var DataSetupFactory|MockObject + */ + private $dataSetupFactoryMock; + + /** + * @var State|MockObject + */ + private $sampleDataStateMock; + + /** + * @var ComponentRegistrar|MockObject + */ + private $componentRegistrarMock; + + /** + * @var PhpReadinessCheck|MockObject + */ + private $phpReadinessCheckMock; + + /** + * @var DeclarationInstaller|MockObject + */ + private $declarationInstallerMock; + + /** + * @var SchemaListener|MockObject + */ + private $schemaListenerMock; + + /** + * @var Context|MockObject + */ + private $contextMock; + + /** + * @var PatchApplier|MockObject + */ + private $patchApplierMock; + + /** + * @var PatchApplierFactory|MockObject + */ + private $patchApplierFactoryMock; + + /** + * Sample DB configuration segment + * @var array + */ + private static $dbConfig = [ + 'default' => [ + ConfigOptionsListConstants::KEY_HOST => '127.0.0.1', + ConfigOptionsListConstants::KEY_NAME => 'magento', + ConfigOptionsListConstants::KEY_USER => 'magento', + ConfigOptionsListConstants::KEY_PASSWORD => '', + ] + ]; + + /** + * @inheritDoc + */ + protected function setUp(): void + { + $this->filePermissionsMock = $this->createMock(FilePermissions::class); + $this->configWriterMock = $this->createMock(Writer::class); + $this->configReaderMock = $this->createMock(Reader::class); + $this->configMock = $this->createMock(DeploymentConfig::class); + + $this->moduleListMock = $this->getMockForAbstractClass(ModuleListInterface::class); + $this->moduleListMock->expects($this->any()) + ->method('getOne') + ->willReturn( ['setup_version' => '2.0.0'] ); - $this->moduleList->expects($this->any())->method('getNames')->willReturn( + $this->moduleListMock->expects($this->any()) + ->method('getNames') + ->willReturn( ['Foo_One', 'Bar_Two'] ); - $this->moduleLoader = $this->createMock(\Magento\Framework\Module\ModuleList\Loader::class); - $this->directoryList = - $this->createMock(\Magento\Framework\App\Filesystem\DirectoryList::class); - $this->adminFactory = $this->createMock(\Magento\Setup\Model\AdminAccountFactory::class); - $this->logger = $this->getMockForAbstractClass(\Magento\Framework\Setup\LoggerInterface::class); - $this->random = $this->createMock(\Magento\Framework\Math\Random::class); - $this->connection = $this->getMockForAbstractClass(\Magento\Framework\DB\Adapter\AdapterInterface::class); - $this->maintenanceMode = $this->createMock(\Magento\Framework\App\MaintenanceMode::class); - $this->filesystem = $this->createMock(\Magento\Framework\Filesystem::class); - $this->objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class); - $this->contextMock = - $this->createMock(\Magento\Framework\Model\ResourceModel\Db\Context::class); - $this->configModel = $this->createMock(\Magento\Setup\Model\ConfigModel::class); - $this->cleanupFiles = $this->createMock(\Magento\Framework\App\State\CleanupFiles::class); - $this->dbValidator = $this->createMock(\Magento\Setup\Validator\DbValidator::class); - $this->setupFactory = $this->createMock(\Magento\Setup\Module\SetupFactory::class); - $this->dataSetupFactory = $this->createMock(\Magento\Setup\Module\DataSetupFactory::class); - $this->sampleDataState = $this->createMock(\Magento\Framework\Setup\SampleData\State::class); - $this->componentRegistrar = - $this->createMock(\Magento\Framework\Component\ComponentRegistrar::class); - $this->phpReadinessCheck = $this->createMock(\Magento\Setup\Model\PhpReadinessCheck::class); - $this->declarationInstallerMock = $this->createMock(DeclarationInstaller::class); - $this->schemaListenerMock = $this->createMock(SchemaListener::class); - $this->patchApplierFactoryMock = $this->createMock(PatchApplierFactory::class); - $this->patchApplierMock = $this->createMock(PatchApplier::class); - $this->patchApplierFactoryMock->expects($this->any())->method('create')->willReturn( + + $this->moduleLoaderMock = $this->createMock(Loader::class); + $this->adminFactoryMock = $this->createMock(AdminAccountFactory::class); + $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class); + $this->randomMock = $this->createMock(Random::class); + $this->connectionMock = $this->getMockForAbstractClass(AdapterInterface::class); + $this->maintenanceModeMock = $this->createMock(MaintenanceMode::class); + $this->filesystemMock = $this->createMock(Filesystem::class); + $this->contextMock = $this->createMock(Context::class); + $this->configModelMock = $this->createMock(ConfigModel::class); + $this->cleanupFilesMock = $this->createMock(CleanupFiles::class); + $this->dbValidatorMock = $this->createMock(DbValidator::class); + $this->setupFactoryMock = $this->createMock(SetupFactory::class); + $this->dataSetupFactoryMock = $this->createMock(DataSetupFactory::class); + $this->sampleDataStateMock = $this->createMock(State::class); + $this->componentRegistrarMock = $this->createMock(ComponentRegistrar::class); + $this->phpReadinessCheckMock = $this->createMock(PhpReadinessCheck::class); + $this->declarationInstallerMock = $this->createMock(DeclarationInstaller::class); + $this->schemaListenerMock = $this->createMock(SchemaListener::class); + $this->patchApplierFactoryMock = $this->createMock(PatchApplierFactory::class); + $this->patchApplierMock = $this->createMock(PatchApplier::class); + + $this->patchApplierFactoryMock->expects($this->any()) + ->method('create') + ->willReturn( $this->patchApplierMock ); - $this->object = $this->createObject(); - } - /** - * Instantiates the object with mocks - * @param \PHPUnit_Framework_MockObject_MockObject|bool $connectionFactory - * @param \PHPUnit_Framework_MockObject_MockObject|bool $objectManagerProvider - * @return Installer - */ - private function createObject($connectionFactory = false, $objectManagerProvider = false) - { - if (!$connectionFactory) { - $connectionFactory = $this->createMock(\Magento\Setup\Module\ConnectionFactory::class); - $connectionFactory->expects($this->any())->method('create')->willReturn($this->connection); - } - if (!$objectManagerProvider) { - $objectManagerProvider = - $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class); - $objectManagerProvider->expects($this->any())->method('get')->willReturn($this->objectManager); - } - - return new Installer( - $this->filePermissions, - $this->configWriter, - $this->configReader, - $this->config, - $this->moduleList, - $this->moduleLoader, - $this->adminFactory, - $this->logger, - $connectionFactory, - $this->maintenanceMode, - $this->filesystem, - $objectManagerProvider, - $this->contextMock, - $this->configModel, - $this->cleanupFiles, - $this->dbValidator, - $this->setupFactory, - $this->dataSetupFactory, - $this->sampleDataState, - $this->componentRegistrar, - $this->phpReadinessCheck, - $this->declarationInstallerMock - ); + $this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class); + $this->object = $this->createObject(); + } + + /** + * Instantiates the object with mocks + * + * @param ConnectionFactory|MockObject|bool $connectionFactory + * @param ObjectManagerProvider|MockObject|bool $objectManagerProvider + * @return Installer + */ + private function createObject($connectionFactoryMock = false, $objectManagerProviderMock = false) + { + if (!$connectionFactoryMock) { + $connectionFactoryMock = $this->createMock(ConnectionFactory::class); + $connectionFactoryMock->expects($this->any()) + ->method('create') + ->willReturn($this->connectionMock); } - /** - * @param array $request - * @param array $logMessages - * @dataProvider installDataProvider - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function testInstall(array $request, array $logMessages) - { - $this->config->expects($this->atLeastOnce()) + if (!$objectManagerProviderMock) { + $objectManagerProviderMock = $this->createMock(ObjectManagerProvider::class); + $objectManagerProviderMock->expects($this->any()) ->method('get') - ->willReturnMap( - [ - [ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true], - [ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true], - ['modules/Magento_User', null, '1'] - ] - ); - $allModules = ['Foo_One' => [], 'Bar_Two' => []]; - - $this->declarationInstallerMock->expects($this->once())->method('installSchema'); - $this->moduleLoader->expects($this->any())->method('load')->willReturn($allModules); - $setup = $this->createMock(\Magento\Setup\Module\Setup::class); - $table = $this->createMock(\Magento\Framework\DB\Ddl\Table::class); - $connection = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class) - ->setMethods(['getSchemaListener', 'newTable']) - ->getMockForAbstractClass(); - $connection->expects($this->any())->method('getSchemaListener')->willReturn($this->schemaListenerMock); - $setup->expects($this->any())->method('getConnection')->willReturn($connection); - $table->expects($this->any())->method('addColumn')->willReturn($table); - $table->expects($this->any())->method('setComment')->willReturn($table); - $table->expects($this->any())->method('addIndex')->willReturn($table); - $connection->expects($this->any())->method('newTable')->willReturn($table); - $resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class); - $this->contextMock->expects($this->any())->method('getResources')->willReturn($resource); - $resource->expects($this->any())->method('getConnection')->will($this->returnValue($connection)); - $dataSetup = $this->createMock(\Magento\Setup\Module\DataSetup::class); - $dataSetup->expects($this->any())->method('getConnection')->willReturn($connection); - $cacheManager = $this->createMock(\Magento\Framework\App\Cache\Manager::class); - $cacheManager->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->exactly(3))->method('setEnabled')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->exactly(3))->method('clean'); - $cacheManager->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]); - $appState = $this->getMockBuilder(\Magento\Framework\App\State::class) - ->disableOriginalConstructor() - ->disableArgumentCloning() - ->getMock(); - $appState->expects($this->once()) - ->method('setAreaCode') - ->with(\Magento\Framework\App\Area::AREA_GLOBAL); - $registry = $this->createMock(\Magento\Framework\Registry::class); - $this->setupFactory->expects($this->atLeastOnce())->method('create')->with($resource)->willReturn($setup); - $this->dataSetupFactory->expects($this->atLeastOnce())->method('create')->willReturn($dataSetup); - $this->objectManager->expects($this->any()) - ->method('create') - ->will($this->returnValueMap([ - [\Magento\Framework\App\Cache\Manager::class, [], $cacheManager], - [\Magento\Framework\App\State::class, [], $appState], - [ - PatchApplierFactory::class, - ['objectManager' => $this->objectManager], - $this->patchApplierFactoryMock - ], - ])); - $this->patchApplierMock->expects($this->exactly(2))->method('applySchemaPatch')->willReturnMap( + ->willReturn($this->objectManager); + } + + return (new ObjectManager($this))->getObject( + Installer::class, + [ + 'filePermissions' => $this->filePermissionsMock, + 'deploymentConfigWriter' => $this->configWriterMock, + 'deploymentConfigReader' => $this->configReaderMock, + 'moduleList' => $this->moduleListMock, + 'moduleLoader' => $this->moduleLoaderMock, + 'adminAccountFactory' => $this->adminFactoryMock, + 'log' => $this->loggerMock, + 'connectionFactory' => $connectionFactoryMock, + 'maintenanceMode' => $this->maintenanceModeMock, + 'filesystem' => $this->filesystemMock, + [], + 'deploymentConfig' => $this->configMock, + 'objectManagerProvider' => $objectManagerProviderMock, + 'context' => $this->contextMock, + 'setupConfigModel' => $this->configModelMock, + 'cleanupFiles' => $this->cleanupFilesMock, + 'dbValidator' => $this->dbValidatorMock, + 'setupFactory' => $this->setupFactoryMock, + 'dataSetupFactory' => $this->dataSetupFactoryMock, + 'sampleDataState' => $this->sampleDataStateMock, + 'componentRegistrar' => $this->componentRegistrarMock, + 'phpReadinessCheck' => $this->phpReadinessCheckMock + ] + ); + } + + /** + * Test install() + * + * @param array $request + * @param array $logMessages + * @dataProvider installDataProvider + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testInstall(array $request, array $logMessages): void + { + $this->configMock->expects($this->atLeastOnce()) + ->method('get') + ->willReturnMap( [ - ['Bar_Two'], - ['Foo_One'], + [ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTION_DEFAULT, null, true], + [ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY, null, true], + ['modules/Magento_User', null, '1'] ] ); - $this->patchApplierMock->expects($this->exactly(2))->method('applyDataPatch')->willReturnMap( + $allModules = ['Foo_One' => [], 'Bar_Two' => []]; + + $this->declarationInstallerMock->expects($this->once())->method('installSchema'); + $this->moduleLoaderMock->expects($this->any())->method('load')->willReturn($allModules); + + $connectionMock = $this->getMockBuilder(AdapterInterface::class) + ->setMethods(['getSchemaListener', 'newTable']) + ->getMockForAbstractClass(); + $connectionMock->expects($this->any())->method('getSchemaListener')->willReturn($this->schemaListenerMock); + + $setupMock = $this->createMock(Setup::class); + $setupMock->expects($this->any())->method('getConnection')->willReturn($connectionMock); + + $tableMock = $this->createMock(Table::class); + $tableMock->expects($this->any())->method('addColumn')->willReturn($tableMock); + $tableMock->expects($this->any())->method('setComment')->willReturn($tableMock); + $tableMock->expects($this->any())->method('addIndex')->willReturn($tableMock); + + $connectionMock->expects($this->any())->method('newTable')->willReturn($tableMock); + + $resourceMock = $this->createMock(ResourceConnection::class); + $this->contextMock->expects($this->any())->method('getResources')->willReturn($resourceMock); + $resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock)); + + $dataSetupMock = $this->createMock(DataSetup::class); + $dataSetupMock->expects($this->any())->method('getConnection')->willReturn($connectionMock); + + $cacheManagerMock = $this->createMock(Manager::class); + $cacheManagerMock->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']); + $cacheManagerMock->expects($this->exactly(3))->method('setEnabled') + // ->with(['foo', 'bar'], false) + ->willReturn(['foo', 'bar']); + $cacheManagerMock->expects($this->exactly(3))->method('clean'); + $cacheManagerMock->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]); + + $appStateMock = $this->getMockBuilder(MFAState::class) + ->disableOriginalConstructor() + ->disableArgumentCloning() + ->getMock(); + $appStateMock->expects($this->once()) + ->method('setAreaCode') + ->with(Area::AREA_GLOBAL); + + $registryMock = $this->createMock(Registry::class); + + $this->setupFactoryMock->expects($this->atLeastOnce())->method('create')->with($resourceMock)->willReturn($setupMock); + $this->dataSetupFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($dataSetupMock); + $this->objectManager->expects($this->any()) + ->method('create') + ->will($this->returnValueMap([ + [Manager::class, [], $cacheManagerMock], + [MFAState::class, [], $appStateMock], + [ + PatchApplierFactory::class, + ['objectManager' => $this->objectManager], + $this->patchApplierFactoryMock + ], + ])); + + $this->patchApplierMock->expects($this->exactly(2))->method('applySchemaPatch') + ->willReturnMap( [ - ['Bar_Two'], - ['Foo_One'], + ['Bar_Two'], ['Foo_One'] ] ); - $this->objectManager->expects($this->any()) - ->method('get') - ->will($this->returnValueMap([ - [\Magento\Framework\App\State::class, $appState], - [\Magento\Framework\App\Cache\Manager::class, $cacheManager], - [\Magento\Setup\Model\DeclarationInstaller::class, $this->declarationInstallerMock], - [\Magento\Framework\Registry::class, $registry] - ])); - $this->adminFactory->expects($this->any())->method('create')->willReturn( - $this->createMock(\Magento\Setup\Model\AdminAccount::class) - ); - $this->sampleDataState->expects($this->once())->method('hasError')->willReturn(true); - $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn( - ['responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_SUCCESS] + $this->patchApplierMock->expects($this->exactly(2))->method('applyDataPatch')->willReturnMap( + [ + ['Bar_Two'], ['Foo_One'] + ] + ); + $this->objectManager->expects($this->any()) + ->method('get') + ->will($this->returnValueMap([ + [MFAState::class, $appStateMock], + [Manager::class, $cacheManagerMock], + [DeclarationInstaller::class, $this->declarationInstallerMock], + [Registry::class, $registryMock] + ])); + $this->adminFactoryMock->expects($this->any())->method('create')->willReturn( + $this->createMock(AdminAccount::class) + ); + $this->sampleDataStateMock->expects($this->once())->method('hasError')->willReturn(true); + $this->phpReadinessCheckMock->expects($this->once())->method('checkPhpExtensions') + ->willReturn( + ['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS] ); - $this->filePermissions->expects($this->any()) - ->method('getMissingWritablePathsForInstallation') - ->willReturn([]); - $this->filePermissions->expects($this->once()) - ->method('getMissingWritableDirectoriesForDbUpgrade') - ->willReturn([]); - call_user_func_array( - [ - $this->logger->expects($this->exactly(count($logMessages)))->method('log'), - 'withConsecutive' - ], - $logMessages + $this->filePermissionsMock->expects($this->any()) + ->method('getMissingWritablePathsForInstallation') + ->willReturn([]); + $this->filePermissionsMock->expects($this->once()) + ->method('getMissingWritableDirectoriesForDbUpgrade') + ->willReturn([]); + + call_user_func_array( + [ + $this->loggerMock->expects($this->exactly(count($logMessages)))->method('log'), + 'withConsecutive' + ], + $logMessages + ); + + $this->loggerMock->expects($this->exactly(2)) + ->method('logSuccess') + ->withConsecutive( + ['Magento installation complete.'], + ['Magento Admin URI: /'] ); - $this->logger->expects($this->exactly(2)) - ->method('logSuccess') - ->withConsecutive( - ['Magento installation complete.'], - ['Magento Admin URI: /'] - ); - - $this->object->install($request); - } + $this->object->install($request); + } - /** - * @return array - * @SuppressWarnings(PHPMD.ExcessiveMethodLength) - */ - public function installDataProvider() - { - return [ - [ - 'request' => [ - ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1', - ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento', - ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento', - ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key', - ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend', - ], - 'logMessages' => [ - ['Starting Magento installation:'], - ['File permissions check...'], - ['Required extensions check...'], - ['Enabling Maintenance Mode...'], - ['Installing deployment configuration...'], - ['Installing database schema:'], - ['Schema creation/updates:'], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Schema post-updates:'], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Installing user configuration...'], - ['Enabling caches:'], - ['Current status:'], - [print_r(['foo' => 1, 'bar' => 1], true)], - ['Installing data...'], - ['Data install/update:'], - ['Disabling caches:'], - ['Current status:'], - [print_r([], true)], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Data post-updates:'], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Enabling caches:'], - ['Current status:'], - [print_r([], true)], - ['Caches clearing:'], - ['Cache cleared successfully'], - ['Disabling Maintenance Mode:'], - ['Post installation file permissions check...'], - ['Write installation date...'], - ['Sample Data is installed with errors. See log file for details'] - ], + /** + * Install DataProvider + * + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function installDataProvider(): array + { + return [ + [ + 'request' => [ + ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1', + ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento', + ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento', + ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key', + ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend', ], - [ - 'request' => [ - ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1', - ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento', - ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento', - ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key', - ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend', - AdminAccount::KEY_USER => 'admin', - AdminAccount::KEY_PASSWORD => '123', - AdminAccount::KEY_EMAIL => 'admin@example.com', - AdminAccount::KEY_FIRST_NAME => 'John', - AdminAccount::KEY_LAST_NAME => 'Doe', - ], - 'logMessages' => [ - ['Starting Magento installation:'], - ['File permissions check...'], - ['Required extensions check...'], - ['Enabling Maintenance Mode...'], - ['Installing deployment configuration...'], - ['Installing database schema:'], - ['Schema creation/updates:'], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Schema post-updates:'], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Installing user configuration...'], - ['Enabling caches:'], - ['Current status:'], - [print_r(['foo' => 1, 'bar' => 1], true)], - ['Installing data...'], - ['Data install/update:'], - ['Disabling caches:'], - ['Current status:'], - [print_r([], true)], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Data post-updates:'], - ['Module \'Foo_One\':'], - ['Module \'Bar_Two\':'], - ['Enabling caches:'], - ['Current status:'], - [print_r([], true)], - ['Installing admin user...'], - ['Caches clearing:'], - ['Cache cleared successfully'], - ['Disabling Maintenance Mode:'], - ['Post installation file permissions check...'], - ['Write installation date...'], - ['Sample Data is installed with errors. See log file for details'] - ], + 'logMessages' => [ + ['Starting Magento installation:'], + ['File permissions check...'], + ['Required extensions check...'], + ['Enabling Maintenance Mode...'], + ['Installing deployment configuration...'], + ['Installing database schema:'], + ['Schema creation/updates:'], + ['Module \'Foo_One\':'], + ['Module \'Bar_Two\':'], + ['Schema post-updates:'], + ['Module \'Foo_One\':'], + ['Module \'Bar_Two\':'], + ['Installing user configuration...'], + ['Enabling caches:'], + ['Current status:'], + ['foo: 1'], + ['bar: 1'], + ['Installing data...'], + ['Data install/update:'], + ['Disabling caches:'], + ['Current status:'], + ['Module \'Foo_One\':'], + ['Module \'Bar_Two\':'], + ['Data post-updates:'], + ['Module \'Foo_One\':'], + ['Module \'Bar_Two\':'], + ['Enabling caches:'], + ['Current status:'], + ['Caches clearing:'], + ['Cache cleared successfully'], + ['Disabling Maintenance Mode:'], + ['Post installation file permissions check...'], + ['Write installation date...'], + ['Sample Data is installed with errors. See log file for details'] ], - ]; - } + ], + [ + 'request' => [ + ConfigOptionsListConstants::INPUT_KEY_DB_HOST => '127.0.0.1', + ConfigOptionsListConstants::INPUT_KEY_DB_NAME => 'magento', + ConfigOptionsListConstants::INPUT_KEY_DB_USER => 'magento', + ConfigOptionsListConstants::INPUT_KEY_ENCRYPTION_KEY => 'encryption_key', + ConfigOptionsList::INPUT_KEY_BACKEND_FRONTNAME => 'backend', + AdminAccount::KEY_USER => 'admin', + AdminAccount::KEY_PASSWORD => '123', + AdminAccount::KEY_EMAIL => 'admin@example.com', + AdminAccount::KEY_FIRST_NAME => 'John', + AdminAccount::KEY_LAST_NAME => 'Doe', + ], + 'logMessages' => [ + ['Starting Magento installation:'], + ['File permissions check...'], + ['Required extensions check...'], + ['Enabling Maintenance Mode...'], + ['Installing deployment configuration...'], + ['Installing database schema:'], + ['Schema creation/updates:'], + ['Module \'Foo_One\':'], + ['Module \'Bar_Two\':'], + ['Schema post-updates:'], + ['Module \'Foo_One\':'], + ['Module \'Bar_Two\':'], + ['Installing user configuration...'], + ['Enabling caches:'], + ['Current status:'], + ['foo: 1'], + ['bar: 1'], + ['Installing data...'], + ['Data install/update:'], + ['Disabling caches:'], + ['Current status:'], + ['Module \'Foo_One\':'], + ['Module \'Bar_Two\':'], + ['Data post-updates:'], + ['Module \'Foo_One\':'], + ['Module \'Bar_Two\':'], + ['Enabling caches:'], + ['Current status:'], + ['Installing admin user...'], + ['Caches clearing:'], + ['Cache cleared successfully'], + ['Disabling Maintenance Mode:'], + ['Post installation file permissions check...'], + ['Write installation date...'], + ['Sample Data is installed with errors. See log file for details'] + ], + ], + ]; + } - public function testCheckInstallationFilePermissions() - { - $this->filePermissions - ->expects($this->once()) - ->method('getMissingWritablePathsForInstallation') - ->willReturn([]); - $this->object->checkInstallationFilePermissions(); - } + /** + * Test Check installation file permission + */ + public function testCheckInstallationFilePermissions(): void + { + $this->filePermissionsMock->expects($this->once()) + ->method('getMissingWritablePathsForInstallation') + ->willReturn([]); + $this->object->checkInstallationFilePermissions(); + } - /** - * @expectedException \Exception - * @expectedExceptionMessage Missing write permissions to the following paths: - */ - public function testCheckInstallationFilePermissionsError() - { - $this->filePermissions - ->expects($this->once()) - ->method('getMissingWritablePathsForInstallation') - ->willReturn(['foo', 'bar']); - $this->object->checkInstallationFilePermissions(); - } + /** + * Test Check installation file permission error + * + * @expectedException \Exception + * @expectedExceptionMessage Missing write permissions to the following paths: + */ + public function testCheckInstallationFilePermissionsError(): void + { + $this->filePermissionsMock->expects($this->once()) + ->method('getMissingWritablePathsForInstallation') + ->willReturn(['foo', 'bar']); + $this->object->checkInstallationFilePermissions(); + } - public function testCheckExtensions() - { - $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn( - ['responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_SUCCESS] - ); - $this->object->checkExtensions(); - } + /** + * Test check extensions + */ + public function testCheckExtensions(): void + { + $this->phpReadinessCheckMock->expects($this->once())->method('checkPhpExtensions')->willReturn( + ['responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS] + ); + $this->object->checkExtensions(); + } - /** - * @expectedException \Exception - * @expectedExceptionMessage Missing following extensions: 'foo' - */ - public function testCheckExtensionsError() - { - $this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn( + /** + * Test check if extensions has error + * + * @expectedException \Exception + * @expectedExceptionMessage Missing following extensions: 'foo' + */ + public function testCheckExtensionsError(): void + { + $this->phpReadinessCheckMock->expects($this->once())->method('checkPhpExtensions')->willReturn( + [ + 'responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR, + 'data' => ['required' => ['foo', 'bar'], 'missing' => ['foo']] + ] + ); + $this->object->checkExtensions(); + } + + /** + * Test check application file permissions + */ + public function testCheckApplicationFilePermissions(): void + { + $this->filePermissionsMock + ->expects($this->once()) + ->method('getUnnecessaryWritableDirectoriesForApplication') + ->willReturn(['foo', 'bar']); + $expectedMessage = "For security, remove write permissions from these directories: 'foo' 'bar'"; + $this->loggerMock->expects($this->once())->method('log')->with($expectedMessage); + $this->object->checkApplicationFilePermissions(); + $this->assertSame(['message' => [$expectedMessage]], $this->object->getInstallInfo()); + } + + /** + * Test update modules sequence + */ + public function testUpdateModulesSequence(): void + { + $this->cleanupFilesMock->expects($this->once())->method('clearCodeGeneratedFiles')->will( + $this->returnValue( [ - 'responseType' => \Magento\Setup\Controller\ResponseTypeInterface::RESPONSE_TYPE_ERROR, - 'data' => ['required' => ['foo', 'bar'], 'missing' => ['foo']] + "The directory '/generation' doesn't exist - skipping cleanup" ] - ); - $this->object->checkExtensions(); - } + ) + ); + $installer = $this->prepareForUpdateModulesTests(); + + $this->loggerMock->expects($this->at(0))->method('log')->with('Cache cleared successfully'); + $this->loggerMock->expects($this->at(1))->method('log')->with('File system cleanup:'); + $this->loggerMock->expects($this->at(2))->method('log') + ->with('The directory \'/generation\' doesn\'t exist - skipping cleanup'); + $this->loggerMock->expects($this->at(3))->method('log')->with('Updating modules:'); + $installer->updateModulesSequence(false); + } - public function testCheckApplicationFilePermissions() - { - $this->filePermissions - ->expects($this->once()) - ->method('getUnnecessaryWritableDirectoriesForApplication') - ->willReturn(['foo', 'bar']); - $expectedMessage = "For security, remove write permissions from these directories: 'foo' 'bar'"; - $this->logger->expects($this->once())->method('log')->with($expectedMessage); - $this->object->checkApplicationFilePermissions(); - $this->assertSame(['message' => [$expectedMessage]], $this->object->getInstallInfo()); - } + /** + * Test update modules sequence with generated + */ + public function testUpdateModulesSequenceKeepGenerated(): void + { + $this->cleanupFilesMock->expects($this->never())->method('clearCodeGeneratedClasses'); - public function testUpdateModulesSequence() - { - $this->cleanupFiles->expects($this->once())->method('clearCodeGeneratedFiles')->will( - $this->returnValue( + $installer = $this->prepareForUpdateModulesTests(); + + $this->loggerMock->expects($this->at(0))->method('log')->with('Cache cleared successfully'); + $this->loggerMock->expects($this->at(1))->method('log')->with('Updating modules:'); + $installer->updateModulesSequence(true); + } + + /** + * Test Uninstall method + */ + public function testUninstall(): void + { + $this->configMock->expects($this->once()) + ->method('get') + ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) + ->willReturn([]); + $this->configReaderMock->expects($this->once())->method('getFiles')->willReturn([ + 'ConfigOne.php', + 'ConfigTwo.php' + ]); + + $configDirMock = $this->getMockForAbstractClass(WriteInterface::class); + $configDirMock->expects($this->exactly(2)) + ->method('getAbsolutePath') + ->will( + $this->returnValueMap( [ - "The directory '/generation' doesn't exist - skipping cleanup", + ['ConfigOne.php', '/config/ConfigOne.php'], + ['ConfigTwo.php', '/config/ConfigTwo.php'] ] ) ); - $installer = $this->prepareForUpdateModulesTests(); - - $this->logger->expects($this->at(0))->method('log')->with('Cache cleared successfully'); - $this->logger->expects($this->at(1))->method('log')->with('File system cleanup:'); - $this->logger->expects($this->at(2))->method('log') - ->with('The directory \'/generation\' doesn\'t exist - skipping cleanup'); - $this->logger->expects($this->at(3))->method('log')->with('Updating modules:'); - $installer->updateModulesSequence(false); - } - public function testUpdateModulesSequenceKeepGenerated() - { - $this->cleanupFiles->expects($this->never())->method('clearCodeGeneratedClasses'); + $this->filesystemMock->expects($this->any()) + ->method('getDirectoryWrite') + ->will($this->returnValueMap([ + [DirectoryList::CONFIG, DriverPool::FILE, $configDirMock], + ])); + $this->loggerMock->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); + $this->loggerMock->expects($this->at(2)) + ->method('log') + ->with('No database connection defined - skipping database cleanup'); + + $cacheManagerMock = $this->createMock(Manager::class); + $cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); + $cacheManagerMock->expects($this->once())->method('clean'); + + $this->objectManager->expects($this->any()) + ->method('get') + ->with(Manager::class) + ->willReturn($cacheManagerMock); + $this->loggerMock->expects($this->at(1))->method('log')->with('Cache cleared successfully'); + $this->loggerMock->expects($this->at(3))->method('log')->with('File system cleanup:'); + $this->loggerMock + ->expects($this->at(4)) + ->method('log') + ->with("The directory '/var' doesn't exist - skipping cleanup"); + $this->loggerMock + ->expects($this->at(5)) + ->method('log') + ->with("The directory '/static' doesn't exist - skipping cleanup"); + $this->loggerMock + ->expects($this->at(6)) + ->method('log') + ->with("The file '/config/ConfigOne.php' doesn't exist - skipping cleanup"); + $this->loggerMock + ->expects($this->at(7)) + ->method('log') + ->with("The file '/config/ConfigTwo.php' doesn't exist - skipping cleanup"); + $this->loggerMock->expects($this->once())->method('logSuccess')->with('Magento uninstallation complete.'); + $this->cleanupFilesMock->expects($this->once())->method('clearAllFiles')->will( + $this->returnValue( + [ + "The directory '/var' doesn't exist - skipping cleanup", + "The directory '/static' doesn't exist - skipping cleanup" + ] + ) + ); - $installer = $this->prepareForUpdateModulesTests(); + $this->object->uninstall(); + } - $this->logger->expects($this->at(0))->method('log')->with('Cache cleared successfully'); - $this->logger->expects($this->at(1))->method('log')->with('Updating modules:'); - $installer->updateModulesSequence(true); - } + /** + * Test cleanupDb + */ + public function testCleanupDb(): void + { + $this->configMock->expects($this->once()) + ->method('get') + ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) + ->willReturn(self::$dbConfig); + $this->connectionMock->expects($this->at(0))->method('quoteIdentifier') + ->with('magento') + ->willReturn('`magento`'); + $this->connectionMock->expects($this->at(1))->method('query')->with('DROP DATABASE IF EXISTS `magento`'); + $this->connectionMock->expects($this->at(2))->method('query')->with('CREATE DATABASE IF NOT EXISTS `magento`'); + $this->loggerMock->expects($this->once())->method('log')->with('Cleaning up database `magento`'); + $this->object->cleanupDb(); + } - public function testUninstall() - { - $this->config->expects($this->once()) - ->method('get') - ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) - ->willReturn([]); - $this->configReader->expects($this->once())->method('getFiles')->willReturn([ - 'ConfigOne.php', - 'ConfigTwo.php' - ]); - $configDir = $this->getMockForAbstractClass( - \Magento\Framework\Filesystem\Directory\WriteInterface::class - ); - $configDir - ->expects($this->exactly(2)) - ->method('getAbsolutePath') - ->will( - $this->returnValueMap( - [ - ['ConfigOne.php', '/config/ConfigOne.php'], - ['ConfigTwo.php', '/config/ConfigTwo.php'] - ] - ) - ); - $this->filesystem - ->expects($this->any()) - ->method('getDirectoryWrite') - ->will($this->returnValueMap([ - [DirectoryList::CONFIG, DriverPool::FILE, $configDir], - ])); - $this->logger->expects($this->at(0))->method('log')->with('Starting Magento uninstallation:'); - $this->logger - ->expects($this->at(2)) - ->method('log') - ->with('No database connection defined - skipping database cleanup'); - $cacheManager = $this->createMock(\Magento\Framework\App\Cache\Manager::class); - $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->once())->method('clean'); - $this->objectManager->expects($this->any()) - ->method('get') - ->with(\Magento\Framework\App\Cache\Manager::class) - ->willReturn($cacheManager); - $this->logger->expects($this->at(1))->method('log')->with('Cache cleared successfully'); - $this->logger->expects($this->at(3))->method('log')->with('File system cleanup:'); - $this->logger - ->expects($this->at(4)) - ->method('log') - ->with("The directory '/var' doesn't exist - skipping cleanup"); - $this->logger - ->expects($this->at(5)) - ->method('log') - ->with("The directory '/static' doesn't exist - skipping cleanup"); - $this->logger - ->expects($this->at(6)) - ->method('log') - ->with("The file '/config/ConfigOne.php' doesn't exist - skipping cleanup"); - $this->logger - ->expects($this->at(7)) - ->method('log') - ->with("The file '/config/ConfigTwo.php' doesn't exist - skipping cleanup"); - $this->logger->expects($this->once())->method('logSuccess')->with('Magento uninstallation complete.'); - $this->cleanupFiles->expects($this->once())->method('clearAllFiles')->will( - $this->returnValue( - [ - "The directory '/var' doesn't exist - skipping cleanup", - "The directory '/static' doesn't exist - skipping cleanup" - ] - ) - ); + /** + * Prepare mocks for update modules tests and returns the installer to use + * @return Installer + */ + private function prepareForUpdateModulesTests() + { + $allModules = [ + 'Foo_One' => [], + 'Bar_Two' => [], + 'New_Module' => [], + ]; - $this->object->uninstall(); - } + $cacheManagerMock = $this->createMock(Manager::class); + $cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); + $cacheManagerMock->expects($this->once())->method('clean'); - public function testCleanupDb() - { - $this->config->expects($this->once()) - ->method('get') - ->with(ConfigOptionsListConstants::CONFIG_PATH_DB_CONNECTIONS) - ->willReturn(self::$dbConfig); - $this->connection->expects($this->at(0))->method('quoteIdentifier')->with('magento')->willReturn( - '`magento`' - ); - $this->connection->expects($this->at(1))->method('query')->with('DROP DATABASE IF EXISTS `magento`'); - $this->connection->expects($this->at(2))->method('query')->with('CREATE DATABASE IF NOT EXISTS `magento`'); - $this->logger->expects($this->once())->method('log')->with('Cleaning up database `magento`'); - $this->object->cleanupDb(); - } + $this->objectManager->expects($this->any())->method('get') + ->will($this->returnValueMap([ + [Manager::class, $cacheManagerMock] + ])); - /** - * Prepare mocks for update modules tests and returns the installer to use - * @return Installer - */ - private function prepareForUpdateModulesTests() - { - $allModules = [ - 'Foo_One' => [], - 'Bar_Two' => [], - 'New_Module' => [], - ]; - - $cacheManager = $this->createMock(\Magento\Framework\App\Cache\Manager::class); - $cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['foo', 'bar']); - $cacheManager->expects($this->once())->method('clean'); - $this->objectManager->expects($this->any()) - ->method('get') - ->will($this->returnValueMap([ - [\Magento\Framework\App\Cache\Manager::class, $cacheManager] - ])); - $this->moduleLoader->expects($this->once())->method('load')->willReturn($allModules); - - $expectedModules = [ - ConfigFilePool::APP_CONFIG => [ - 'modules' => [ - 'Bar_Two' => 0, - 'Foo_One' => 1, - 'New_Module' => 1 - ] - ] - ]; + $this->moduleLoaderMock->expects($this->once())->method('load') + ->willReturn($allModules); - $this->config->expects($this->atLeastOnce()) - ->method('get') - ->with(ConfigOptionsListConstants::KEY_MODULES) - ->willReturn(true); + $expectedModules = [ + ConfigFilePool::APP_CONFIG => [ + 'modules' => [ + 'Bar_Two' => 0, + 'Foo_One' => 1, + 'New_Module' => 1 + ] + ] + ]; - $newObject = $this->createObject(false, false); - $this->configReader->expects($this->once())->method('load') - ->willReturn(['modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0]]); - $this->configWriter->expects($this->once())->method('saveConfig')->with($expectedModules); + $this->configMock->expects($this->atLeastOnce())->method('get') + ->with(ConfigOptionsListConstants::KEY_MODULES) + ->willReturn(true); - return $newObject; - } - } -} + $this->configReaderMock->expects($this->once())->method('load') + ->willReturn( + [ + 'modules' => ['Bar_Two' => 0, 'Foo_One' => 1, 'Old_Module' => 0] + ] + ); -namespace Magento\Setup\Model { + $this->configWriterMock->expects($this->once()) + ->method('saveConfig') + ->with($expectedModules); - /** - * Mocking autoload function - * - * @returns array - */ - function spl_autoload_functions() - { - return ['mock_function_one', 'mock_function_two']; + return $this->createObject(); } } From 981df7bdc533a1209253976b2677b8af03f2df08 Mon Sep 17 00:00:00 2001 From: Sathish Date: Sat, 4 Apr 2020 17:41:02 +0530 Subject: [PATCH 20/95] Fixed static test --- .../Magento/Setup/Test/Unit/Model/InstallerTest.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php index 1f9afb04c07dd..40a47f46765a2 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/InstallerTest.php @@ -366,7 +366,6 @@ public function testInstall(array $request, array $logMessages): void $cacheManagerMock = $this->createMock(Manager::class); $cacheManagerMock->expects($this->any())->method('getAvailableTypes')->willReturn(['foo', 'bar']); $cacheManagerMock->expects($this->exactly(3))->method('setEnabled') - // ->with(['foo', 'bar'], false) ->willReturn(['foo', 'bar']); $cacheManagerMock->expects($this->exactly(3))->method('clean'); $cacheManagerMock->expects($this->exactly(3))->method('getStatus')->willReturn(['foo' => 1, 'bar' => 1]); @@ -381,8 +380,15 @@ public function testInstall(array $request, array $logMessages): void $registryMock = $this->createMock(Registry::class); - $this->setupFactoryMock->expects($this->atLeastOnce())->method('create')->with($resourceMock)->willReturn($setupMock); - $this->dataSetupFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($dataSetupMock); + $this->setupFactoryMock->expects($this->atLeastOnce()) + ->method('create') + ->with($resourceMock) + ->willReturn($setupMock); + + $this->dataSetupFactoryMock->expects($this->atLeastOnce()) + ->method('create') + ->willReturn($dataSetupMock); + $this->objectManager->expects($this->any()) ->method('create') ->will($this->returnValueMap([ From 2a90e762729951cf92aba632769a8e31a6bec851 Mon Sep 17 00:00:00 2001 From: Mateusz Krzeszowiak Date: Sun, 5 Apr 2020 08:41:06 +0200 Subject: [PATCH 21/95] Load appropriate slider widget on demand to improve performance --- .../web/js/lib/knockout/bindings/range.js | 159 ++---------------- lib/web/mage/touch-slider.js | 151 +++++++++++++++++ 2 files changed, 165 insertions(+), 145 deletions(-) create mode 100644 lib/web/mage/touch-slider.js diff --git a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/range.js b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/range.js index 1dda3254f4613..a2af13033d91e 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/range.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/range.js @@ -7,13 +7,18 @@ define([ 'ko', 'jquery', 'underscore', - '../template/renderer', - 'jquery-ui-modules/slider' + '../template/renderer' ], function (ko, $, _, renderer) { 'use strict'; var isTouchDevice = !_.isUndefined(document.ontouchstart), - sliderFn = 'slider'; + sliderFn = 'slider', + sliderModule = 'jquery-ui-modules/slider'; + + if (isTouchDevice) { + sliderFn = 'touchSlider'; + sliderModule = 'mage/touch-slider'; + } ko.bindingHandlers.range = { @@ -41,7 +46,9 @@ define([ } }); - $(element)[sliderFn](config); + require([sliderModule], function() { + $(element)[sliderFn](config); + }); }, /** @@ -55,149 +62,11 @@ define([ config.value = ko.unwrap(config.value); - $(element)[sliderFn]('option', config); + require([sliderModule], function() { + $(element)[sliderFn]('option', config); + }); } }; renderer.addAttribute('range'); - - if (!isTouchDevice) { - return; - } - - $.widget('mage.touchSlider', $.ui.slider, { - - /** - * Creates instance of widget. - * - * @override - */ - _create: function () { - _.bindAll( - this, - '_mouseDown', - '_mouseMove', - '_onTouchEnd' - ); - - return this._superApply(arguments); - }, - - /** - * Initializes mouse events on element. - * @override - */ - _mouseInit: function () { - var result = this._superApply(arguments); - - this.element - .off('mousedown.' + this.widgetName) - .on('touchstart.' + this.widgetName, this._mouseDown); - - return result; - }, - - /** - * Elements' 'mousedown' event handler polyfill. - * @override - */ - _mouseDown: function (event) { - var prevDelegate = this._mouseMoveDelegate, - result; - - event = this._touchToMouse(event); - result = this._super(event); - - if (prevDelegate === this._mouseMoveDelegate) { - return result; - } - - $(document) - .off('mousemove.' + this.widgetName) - .off('mouseup.' + this.widgetName); - - $(document) - .on('touchmove.' + this.widgetName, this._mouseMove) - .on('touchend.' + this.widgetName, this._onTouchEnd) - .on('tochleave.' + this.widgetName, this._onTouchEnd); - - return result; - }, - - /** - * Documents' 'mousemove' event handler polyfill. - * - * @override - * @param {Event} event - Touch event object. - */ - _mouseMove: function (event) { - event = this._touchToMouse(event); - - return this._super(event); - }, - - /** - * Documents' 'touchend' event handler. - */ - _onTouchEnd: function (event) { - $(document).trigger('mouseup'); - - return this._mouseUp(event); - }, - - /** - * Removes previously assigned touch handlers. - * - * @override - */ - _mouseUp: function () { - this._removeTouchHandlers(); - - return this._superApply(arguments); - }, - - /** - * Removes previously assigned touch handlers. - * - * @override - */ - _mouseDestroy: function () { - this._removeTouchHandlers(); - - return this._superApply(arguments); - }, - - /** - * Removes touch events from document object. - */ - _removeTouchHandlers: function () { - $(document) - .off('touchmove.' + this.widgetName) - .off('touchend.' + this.widgetName) - .off('touchleave.' + this.widgetName); - }, - - /** - * Adds properties to the touch event to mimic mouse event. - * - * @param {Event} event - Touch event object. - * @returns {Event} - */ - _touchToMouse: function (event) { - var orig = event.originalEvent, - touch = orig.touches[0]; - - return _.extend(event, { - which: 1, - pageX: touch.pageX, - pageY: touch.pageY, - clientX: touch.clientX, - clientY: touch.clientY, - screenX: touch.screenX, - screenY: touch.screenY - }); - } - }); - - sliderFn = 'touchSlider'; }); diff --git a/lib/web/mage/touch-slider.js b/lib/web/mage/touch-slider.js new file mode 100644 index 0000000000000..8fa27ea0ab488 --- /dev/null +++ b/lib/web/mage/touch-slider.js @@ -0,0 +1,151 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery', + 'underscore', + 'jquery-ui-modules/slider', +], function ($, _) { + 'use strict'; + + /** + * Adds support for touch events for regular jQuery UI slider. + */ + $.widget('mage.touchSlider', $.ui.slider, { + + /** + * Creates instance of widget. + * + * @override + */ + _create: function () { + _.bindAll( + this, + '_mouseDown', + '_mouseMove', + '_onTouchEnd' + ); + + return this._superApply(arguments); + }, + + /** + * Initializes mouse events on element. + * @override + */ + _mouseInit: function () { + var result = this._superApply(arguments); + + this.element + .off('mousedown.' + this.widgetName) + .on('touchstart.' + this.widgetName, this._mouseDown); + + return result; + }, + + /** + * Elements' 'mousedown' event handler polyfill. + * @override + */ + _mouseDown: function (event) { + var prevDelegate = this._mouseMoveDelegate, + result; + + event = this._touchToMouse(event); + result = this._super(event); + + if (prevDelegate === this._mouseMoveDelegate) { + return result; + } + + $(document) + .off('mousemove.' + this.widgetName) + .off('mouseup.' + this.widgetName); + + $(document) + .on('touchmove.' + this.widgetName, this._mouseMove) + .on('touchend.' + this.widgetName, this._onTouchEnd) + .on('tochleave.' + this.widgetName, this._onTouchEnd); + + return result; + }, + + /** + * Documents' 'mousemove' event handler polyfill. + * + * @override + * @param {Event} event - Touch event object. + */ + _mouseMove: function (event) { + event = this._touchToMouse(event); + + return this._super(event); + }, + + /** + * Documents' 'touchend' event handler. + */ + _onTouchEnd: function (event) { + $(document).trigger('mouseup'); + + return this._mouseUp(event); + }, + + /** + * Removes previously assigned touch handlers. + * + * @override + */ + _mouseUp: function () { + this._removeTouchHandlers(); + + return this._superApply(arguments); + }, + + /** + * Removes previously assigned touch handlers. + * + * @override + */ + _mouseDestroy: function () { + this._removeTouchHandlers(); + + return this._superApply(arguments); + }, + + /** + * Removes touch events from document object. + */ + _removeTouchHandlers: function () { + $(document) + .off('touchmove.' + this.widgetName) + .off('touchend.' + this.widgetName) + .off('touchleave.' + this.widgetName); + }, + + /** + * Adds properties to the touch event to mimic mouse event. + * + * @param {Event} event - Touch event object. + * @returns {Event} + */ + _touchToMouse: function (event) { + var orig = event.originalEvent, + touch = orig.touches[0]; + + return _.extend(event, { + which: 1, + pageX: touch.pageX, + pageY: touch.pageY, + clientX: touch.clientX, + clientY: touch.clientY, + screenX: touch.screenX, + screenY: touch.screenY + }); + } + }); + + return $.mage.touchSlider; +}); From 5a4e93f80eee1d37c63243d4e99d947aa8465a96 Mon Sep 17 00:00:00 2001 From: Quang Do Date: Mon, 6 Apr 2020 16:13:48 +0930 Subject: [PATCH 22/95] Added unit test to assert cache IDs for different ACL roles must not be equal --- .../Product/Form/Modifier/CategoriesTest.php | 91 ++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php index bceafee0f82a4..02fc16c55be07 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php @@ -14,6 +14,9 @@ use Magento\Framework\UrlInterface; use Magento\Store\Model\Store; use Magento\Framework\AuthorizationInterface; +use Magento\Backend\Model\Auth\Session; +use Magento\Authorization\Model\Role; +use Magento\User\Model\User; /** * Class CategoriesTest @@ -52,6 +55,11 @@ class CategoriesTest extends AbstractModifierTest */ private $authorizationMock; + /** + * @var \Magento\Backend\Model\Auth\Session|\PHPUnit_Framework_MockObject_MockObject + */ + private $sessionMock; + protected function setUp() { parent::setUp(); @@ -73,6 +81,10 @@ protected function setUp() $this->authorizationMock = $this->getMockBuilder(AuthorizationInterface::class) ->disableOriginalConstructor() ->getMock(); + $this->sessionMock = $this->getMockBuilder(Session::class) + ->setMethods(['getUser']) + ->disableOriginalConstructor() + ->getMock(); $this->categoryCollectionFactoryMock->expects($this->any()) ->method('create') @@ -89,6 +101,26 @@ protected function setUp() $this->categoryCollectionMock->expects($this->any()) ->method('getIterator') ->willReturn(new \ArrayIterator([])); + + $roleAdmin = $this->getMockBuilder(Role::class) + ->setMethods(['getId']) + ->disableOriginalConstructor() + ->getMock(); + $roleAdmin->expects($this->any()) + ->method('getId') + ->willReturn(0); + + $userAdmin = $this->getMockBuilder(User::class) + ->setMethods(['getRole']) + ->disableOriginalConstructor() + ->getMock(); + $userAdmin->expects($this->any()) + ->method('getRole') + ->willReturn($roleAdmin); + + $this->sessionMock->expects($this->any()) + ->method('getUser') + ->willReturn($userAdmin); } /** @@ -102,11 +134,28 @@ protected function createModel() 'locator' => $this->locatorMock, 'categoryCollectionFactory' => $this->categoryCollectionFactoryMock, 'arrayManager' => $this->arrayManagerMock, - 'authorization' => $this->authorizationMock + 'authorization' => $this->authorizationMock, + 'session' => $this->sessionMock ] ); } + /** + * @param object $object + * @param string $method + * @param array $args + * @return mixed + * @throws \ReflectionException + */ + private function invokeMethod($object, $method, $args = []) + { + $class = new \ReflectionClass(Categories::class); + $method = $class->getMethod($method); + $method->setAccessible(true); + + return $method->invokeArgs($object, $args); + } + public function testModifyData() { $this->assertSame([], $this->getModel()->modifyData([])); @@ -177,4 +226,44 @@ public function modifyMetaLockedDataProvider() { return [[true], [false]]; } + + /** + * Asserts that a user with an ACL role ID of 0 and a user with an ACL role ID of 1 do not have the same cache IDs + * Assumes a store ID of 0 + * + * @throws \ReflectionException + */ + public function testAclCacheIds() + { + $categoriesAdmin = $this->createModel(); + $cacheIdAdmin = $this->invokeMethod($categoriesAdmin, 'getCategoriesTreeCacheId', [0]); + + $roleAclUser = $this->getMockBuilder(Role::class) + ->disableOriginalConstructor() + ->getMock(); + $roleAclUser->expects($this->any()) + ->method('getId') + ->willReturn(1); + + $userAclUser = $this->getMockBuilder(User::class) + ->disableOriginalConstructor() + ->getMock(); + $userAclUser->expects($this->any()) + ->method('getRole') + ->will($this->returnValue($roleAclUser)); + + $this->sessionMock = $this->getMockBuilder(Session::class) + ->setMethods(['getUser']) + ->disableOriginalConstructor() + ->getMock(); + + $this->sessionMock->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($userAclUser)); + + $categoriesAclUser = $this->createModel(); + $cacheIdAclUser = $this->invokeMethod($categoriesAclUser, 'getCategoriesTreeCacheId', [0]); + + $this->assertNotEquals($cacheIdAdmin, $cacheIdAclUser); + } } From e5b64f533b984063d9e735cf6f2b485fca6b721b Mon Sep 17 00:00:00 2001 From: Quang Do Date: Tue, 7 Apr 2020 08:27:27 +0930 Subject: [PATCH 23/95] Update class description to address static test --- .../Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php index 02fc16c55be07..d1df9ae0a5b99 100644 --- a/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php @@ -19,7 +19,7 @@ use Magento\User\Model\User; /** - * Class CategoriesTest + * Tests for \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Categories * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ From f799baa4e3f487d6f10d763baa647bf65a99ec60 Mon Sep 17 00:00:00 2001 From: Mateusz Krzeszowiak Date: Wed, 8 Apr 2020 20:07:56 +0200 Subject: [PATCH 24/95] Fix static tests --- .../Ui/view/base/web/js/lib/knockout/bindings/range.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/range.js b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/range.js index a2af13033d91e..52031dc0c3792 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/range.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/range.js @@ -46,7 +46,7 @@ define([ } }); - require([sliderModule], function() { + require([sliderModule], function () { $(element)[sliderFn](config); }); }, @@ -62,7 +62,7 @@ define([ config.value = ko.unwrap(config.value); - require([sliderModule], function() { + require([sliderModule], function () { $(element)[sliderFn]('option', config); }); } From 62b9453becac492cafce1c0abaf0977c8afa2708 Mon Sep 17 00:00:00 2001 From: Ihor Sviziev Date: Thu, 9 Apr 2020 13:12:48 +0300 Subject: [PATCH 25/95] Load appropriate slider widget on demand to improve performance Fix static tests --- lib/web/mage/touch-slider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web/mage/touch-slider.js b/lib/web/mage/touch-slider.js index 8fa27ea0ab488..6c468a832895b 100644 --- a/lib/web/mage/touch-slider.js +++ b/lib/web/mage/touch-slider.js @@ -6,7 +6,7 @@ define([ 'jquery', 'underscore', - 'jquery-ui-modules/slider', + 'jquery-ui-modules/slider' ], function ($, _) { 'use strict'; From 4c21e460d180de2d76810cddd6a53d256113656c Mon Sep 17 00:00:00 2001 From: Mateusz Krzeszowiak Date: Fri, 10 Apr 2020 19:41:08 +0200 Subject: [PATCH 26/95] Don't load datepicker module until it is actually needed --- .../view/frontend/templates/js/calendar.phtml | 3 +- .../js/lib/knockout/bindings/datepicker.js | 57 ++++++++++--------- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/app/code/Magento/Theme/view/frontend/templates/js/calendar.phtml b/app/code/Magento/Theme/view/frontend/templates/js/calendar.phtml index 55798169cdf75..b42cabde6cd85 100644 --- a/app/code/Magento/Theme/view/frontend/templates/js/calendar.phtml +++ b/app/code/Magento/Theme/view/frontend/templates/js/calendar.phtml @@ -14,7 +14,6 @@