From 1b39196a80c9c4a3d229c121b647b82ae242193d Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Tue, 11 Aug 2020 15:53:48 +0300 Subject: [PATCH 1/3] fix store website name rewrites --- .../Listing/Column/Store/Options.php | 33 ++--- .../Listing/Column/Store/OptionsTest.php | 114 ++++++++++++++++++ 2 files changed, 131 insertions(+), 16 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/Store/Ui/Component/Listing/Column/Store/OptionsTest.php diff --git a/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php b/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php index 907eb74e20fa2..f8aa09cb20a61 100644 --- a/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php +++ b/app/code/Magento/Store/Ui/Component/Listing/Column/Store/Options.php @@ -10,7 +10,7 @@ use Magento\Store\Model\System\Store as SystemStore; /** - * Class Options + * Ui stores options */ class Options implements OptionSourceInterface { @@ -93,37 +93,38 @@ protected function sanitizeName($name) * * @return void */ - protected function generateCurrentOptions() + protected function generateCurrentOptions(): void { $websiteCollection = $this->systemStore->getWebsiteCollection(); $groupCollection = $this->systemStore->getGroupCollection(); $storeCollection = $this->systemStore->getStoreCollection(); - /** @var \Magento\Store\Model\Website $website */ + foreach ($websiteCollection as $website) { $groups = []; - /** @var \Magento\Store\Model\Group $group */ foreach ($groupCollection as $group) { - if ($group->getWebsiteId() == $website->getId()) { + if ($group->getWebsiteId() === $website->getId()) { $stores = []; - /** @var \Magento\Store\Model\Store $store */ foreach ($storeCollection as $store) { - if ($store->getGroupId() == $group->getId()) { - $name = $this->sanitizeName($store->getName()); - $stores[$name]['label'] = str_repeat(' ', 8) . $name; - $stores[$name]['value'] = $store->getId(); + if ($store->getGroupId() === $group->getId()) { + $stores[] = [ + 'label' => str_repeat(' ', 8) . $this->sanitizeName($store->getName()), + 'value' => $store->getId(), + ]; } } if (!empty($stores)) { - $name = $this->sanitizeName($group->getName()); - $groups[$name]['label'] = str_repeat(' ', 4) . $name; - $groups[$name]['value'] = array_values($stores); + $groups[] = [ + 'label' => str_repeat(' ', 4) . $this->sanitizeName($group->getName()), + 'value' => array_values($stores), + ]; } } } if (!empty($groups)) { - $name = $this->sanitizeName($website->getName()); - $this->currentOptions[$name]['label'] = $name; - $this->currentOptions[$name]['value'] = array_values($groups); + $this->currentOptions[] = [ + 'label' => $this->sanitizeName($website->getName()), + 'value' => array_values($groups), + ]; } } } diff --git a/dev/tests/integration/testsuite/Magento/Store/Ui/Component/Listing/Column/Store/OptionsTest.php b/dev/tests/integration/testsuite/Magento/Store/Ui/Component/Listing/Column/Store/OptionsTest.php new file mode 100644 index 0000000000000..e13c4a427464f --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Store/Ui/Component/Listing/Column/Store/OptionsTest.php @@ -0,0 +1,114 @@ +modelFactory = $objectManager->get(OptionsFactory::class); + $this->storeManager = $objectManager->get(StoreManagerInterface::class); + + $this->websiteResource = $objectManager->get(WebsiteResource::class); + $this->groupResource = $objectManager->get(GroupResource::class); + $this->storeResource = $objectManager->get(StoreResource::class); + } + + /** + * To option array test with duplicate website, store group, store view names + * + * @magentoDataFixture Magento/Store/_files/second_website_with_store_group_and_store.php + * + * @return void + */ + public function testToOptionArray(): void + { + $website = $this->storeManager->getWebsite('test'); + $this->websiteResource->save($website->setName(self::DEFAULT_WEBSITE_NAME)); + + $storeGroup = current($website->getGroups()); + $this->groupResource->save($storeGroup->setName(self::DEFAULT_STORE_GROUP_NAME)); + + $store = current($website->getStores()); + $this->storeResource->save($store->setName(self::DEFAULT_STORE_NAME)); + + $model = $this->modelFactory->create(); + $storeIds = [$this->storeManager->getStore('default')->getId(), $store->getId()]; + + $this->assertEquals($this->getExpectedOptions($storeIds), $model->toOptionArray()); + } + + /** + * Returns expected options + * + * @param array $storeIds + * @return array + */ + private function getExpectedOptions(array $storeIds): array + { + $expectedOptions = []; + foreach ($storeIds as $storeId) { + $expectedOptions[] = [ + 'label' => self::DEFAULT_WEBSITE_NAME, + 'value' => [[ + 'label' => str_repeat(' ', 4) . self::DEFAULT_STORE_GROUP_NAME, + 'value' => [[ + 'label' => str_repeat(' ', 8) . self::DEFAULT_STORE_NAME, + 'value' => $storeId, + ]], + ]], + ]; + } + + return $expectedOptions; + } +} From 9a980484c23a78f888708223df55f56090b970c9 Mon Sep 17 00:00:00 2001 From: "taras.gamanov" Date: Tue, 18 Aug 2020 12:00:32 +0300 Subject: [PATCH 2/3] MFTF has been added. --- .../Section/AdminProductGridFilterSection.xml | 1 + .../AdminCheckStoreViewOptionsActionGroup.xml | 24 ++++++++ .../Store/Test/Mftf/Data/StoreData.xml | 19 +++++++ .../AdminStoresGridSection.xml | 1 + .../AdminCreateDuplicateNameStoreViewTest.xml | 55 +++++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 app/code/Magento/Store/Test/Mftf/ActionGroup/AdminCheckStoreViewOptionsActionGroup.xml create mode 100644 app/code/Magento/Store/Test/Mftf/Test/AdminCreateDuplicateNameStoreViewTest.xml diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductGridFilterSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductGridFilterSection.xml index 4e86f14611c24..201affacd9adb 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductGridFilterSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminProductGridFilterSection.xml @@ -38,5 +38,6 @@ + diff --git a/app/code/Magento/Store/Test/Mftf/ActionGroup/AdminCheckStoreViewOptionsActionGroup.xml b/app/code/Magento/Store/Test/Mftf/ActionGroup/AdminCheckStoreViewOptionsActionGroup.xml new file mode 100644 index 0000000000000..ba96633a621c2 --- /dev/null +++ b/app/code/Magento/Store/Test/Mftf/ActionGroup/AdminCheckStoreViewOptionsActionGroup.xml @@ -0,0 +1,24 @@ + + + + + + Goes to the Catalog->Product filters and check store view options at the Store View dropdown + + + + + + + + + + + + diff --git a/app/code/Magento/Store/Test/Mftf/Data/StoreData.xml b/app/code/Magento/Store/Test/Mftf/Data/StoreData.xml index bdb1842cf2959..39664ae10a07d 100644 --- a/app/code/Magento/Store/Test/Mftf/Data/StoreData.xml +++ b/app/code/Magento/Store/Test/Mftf/Data/StoreData.xml @@ -206,4 +206,23 @@ store add + + + sameNameStoreView + storeViewCode + 1 + null + add + store + customStoreGroup + + + sameNameStoreView + storeViewCode + 1 + null + add + store + customStoreGroup + diff --git a/app/code/Magento/Store/Test/Mftf/Section/AdminStoresGridSection/AdminStoresGridSection.xml b/app/code/Magento/Store/Test/Mftf/Section/AdminStoresGridSection/AdminStoresGridSection.xml index e56836c491276..cd7f180d0bb0e 100644 --- a/app/code/Magento/Store/Test/Mftf/Section/AdminStoresGridSection/AdminStoresGridSection.xml +++ b/app/code/Magento/Store/Test/Mftf/Section/AdminStoresGridSection/AdminStoresGridSection.xml @@ -22,5 +22,6 @@ + diff --git a/app/code/Magento/Store/Test/Mftf/Test/AdminCreateDuplicateNameStoreViewTest.xml b/app/code/Magento/Store/Test/Mftf/Test/AdminCreateDuplicateNameStoreViewTest.xml new file mode 100644 index 0000000000000..46caf5b37f4f2 --- /dev/null +++ b/app/code/Magento/Store/Test/Mftf/Test/AdminCreateDuplicateNameStoreViewTest.xml @@ -0,0 +1,55 @@ + + + + + + + + + <description value="Admin should be able to create a Store View with the same name"/> + <group value="storeView"/> + <severity value="AVERAGE"/> + </annotations> + <before> + <!--Create two store views with same name, but different codes--> + <actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/> + <actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createFirstStoreView"> + <argument name="StoreGroup" value="_defaultStoreGroup"/> + <argument name="customStore" value="customStoreViewSameNameFirst"/> + </actionGroup> + <actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createSecondStoreView"> + <argument name="StoreGroup" value="_defaultStoreGroup"/> + <argument name="customStore" value="customStoreViewSameNameSecond"/> + </actionGroup> + </before> + <after> + <!--Delete both store views--> + <actionGroup ref="AdminDeleteStoreViewActionGroup" stepKey="deleteFirstStoreView"> + <argument name="customStore" value="customStoreViewSameNameFirst"/> + </actionGroup> + <actionGroup ref="AdminDeleteStoreViewActionGroup" stepKey="deleteSecondStoreView"> + <argument name="customStore" value="customStoreViewSameNameSecond"/> + </actionGroup> + <actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/> + </after> + <!--Get Id of store views--> + <amOnPage url="{{AdminSystemStorePage.url}}" stepKey="navigateToStoreViews"/> + <click selector="{{AdminStoresGridSection.storeViewLinkInNthRow('2')}}" stepKey="openFirstViewPAge" /> + <grabFromCurrentUrl stepKey="getStoreViewIdFirst" regex="~/store_id/(\d+)/~"/> + <amOnPage url="{{AdminSystemStorePage.url}}" stepKey="navigateToStoreViewsAgain"/> + <click selector="{{AdminStoresGridSection.storeViewLinkInNthRow('3')}}" stepKey="openSecondViewPAge" /> + <grabFromCurrentUrl stepKey="getStoreViewIdSecond" regex="~/store_id/(\d+)/~"/> + <!--Go to catalog -> product grid, open the filter and check the listed store view--> + <actionGroup ref="AdminCheckStoreViewOptionsActionGroup" stepKey="checkFirstStoreView"> + <argument name="storeViewId" value="{$getStoreViewIdFirst}"/> + </actionGroup> + <actionGroup ref="AdminCheckStoreViewOptionsActionGroup" stepKey="checkSecondStoreView"> + <argument name="storeViewId" value="{$getStoreViewIdSecond}"/> + </actionGroup> + </test> +</tests> From 55653494828cc444d846f79838c72b568aee4484 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk <60192090+engcom-Kilo@users.noreply.github.com> Date: Thu, 20 Aug 2020 15:45:52 +0300 Subject: [PATCH 3/3] Update AdminCreateDuplicateNameStoreViewTest.xml Added testCaseId --- .../Test/Mftf/Test/AdminCreateDuplicateNameStoreViewTest.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Store/Test/Mftf/Test/AdminCreateDuplicateNameStoreViewTest.xml b/app/code/Magento/Store/Test/Mftf/Test/AdminCreateDuplicateNameStoreViewTest.xml index 46caf5b37f4f2..ec81424b1acfa 100644 --- a/app/code/Magento/Store/Test/Mftf/Test/AdminCreateDuplicateNameStoreViewTest.xml +++ b/app/code/Magento/Store/Test/Mftf/Test/AdminCreateDuplicateNameStoreViewTest.xml @@ -14,6 +14,7 @@ <description value="Admin should be able to create a Store View with the same name"/> <group value="storeView"/> <severity value="AVERAGE"/> + <testCaseId value="MC-36863"/> </annotations> <before> <!--Create two store views with same name, but different codes-->