Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Same store name overriding in the store view grid filter #29474

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
<element name="storeViewDropdown" type="text" selector="//select[@name='store_id']/option[contains(.,'{{storeView}}')]" parameterized="true"/>
<element name="inputByCodeRangeFrom" type="input" selector="input.admin__control-text[name='{{code}}[from]']" parameterized="true"/>
<element name="inputByCodeRangeTo" type="input" selector="input.admin__control-text[name='{{code}}[to]']" parameterized="true"/>
<element name="storeViewOptions" type="text" selector=".admin__data-grid-outer-wrap select[name='store_id'] > option[value='{{value}}']" parameterized="true"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminCheckStoreViewOptionsActionGroup">
<annotations>
<description>Goes to the Catalog->Product filters and check store view options at the Store View dropdown</description>
</annotations>
<arguments>
<argument name="storeViewId" type="string"/>
</arguments>
<amOnPage url="{{ProductCatalogPage.url}}" stepKey="OpenProductCatalogPage"/>
<waitForPageLoad stepKey="waitForProductCatalogPage"/>
<click selector="{{AdminProductGridFilterSection.filters}}" stepKey="clickFiltersButton"/>
<click selector="{{AdminProductFiltersSection.storeViewDropDown}}" stepKey="clickStoreViewSwitchDropdown"/>
<waitForElementVisible selector="{{AdminProductFiltersSection.storeViewDropDown}}" stepKey="waitForWebsiteAreVisible"/>
<seeElement selector="{{AdminProductGridFilterSection.storeViewOptions(storeViewId)}}" stepKey="seeStoreViewOption"/>
</actionGroup>
</actionGroups>
19 changes: 19 additions & 0 deletions app/code/Magento/Store/Test/Mftf/Data/StoreData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,23 @@
<data key="store_type">store</data>
<data key="store_action">add</data>
</entity>
<!--Stores views with same name-->
<entity name="customStoreViewSameNameFirst" type="store">
<data key="name">sameNameStoreView</data>
<data key="code" unique="suffix">storeViewCode</data>
<data key="is_active">1</data>
<data key="store_id">null</data>
<data key="store_action">add</data>
<data key="store_type">store</data>
<requiredEntity type="storeGroup">customStoreGroup</requiredEntity>
</entity>
<entity name="customStoreViewSameNameSecond" type="store">
<data key="name">sameNameStoreView</data>
<data key="code" unique="suffix">storeViewCode</data>
<data key="is_active">1</data>
<data key="store_id">null</data>
<data key="store_action">add</data>
<data key="store_type">store</data>
<requiredEntity type="storeGroup">customStoreGroup</requiredEntity>
</entity>
</entities>
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
<element name="emptyText" type="text" selector="//tr[@class='data-grid-tr-no-data even']/td[@class='empty-text']"/>
<element name="websiteName" type="text" selector="//td[@class='a-left col-website_title ']/a[contains(.,'{{websiteName}}')]" parameterized="true"/>
<element name="gridCell" type="text" selector="//table[@class='data-grid']//tr[{{row}}]//td[count(//table[@class='data-grid']//tr//th[contains(., '{{column}}')]/preceding-sibling::th) +1 ]" parameterized="true"/>
<element name="storeViewLinkInNthRow" type="text" selector="tr:nth-of-type({{row}}) &gt; .col-store_title &gt; a" parameterized="true"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminCreateDuplicateNameStoreViewTest">
<annotations>
<features value="Store"/>
<stories value="Create a store view in admin"/>
<title value="Admin should be able to create a Store View with the same name"/>
<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-->
<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>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Magento\Store\Model\System\Store as SystemStore;

/**
* Class Options
* Ui stores options
*/
class Options implements OptionSourceInterface
{
Expand Down Expand Up @@ -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),
];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Store\Ui\Component\Listing\Column\Store;

use Magento\Store\Model\ResourceModel\Group as GroupResource;
use Magento\Store\Model\ResourceModel\Store as StoreResource;
use Magento\Store\Model\ResourceModel\Website as WebsiteResource;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;

/**
* Test for \Magento\Store\Ui\Component\Listing\Column\Store\Options.
*/
class OptionsTest extends TestCase
{
private const DEFAULT_WEBSITE_NAME = 'Main Website';
private const DEFAULT_STORE_GROUP_NAME = 'Main Website Store';
private const DEFAULT_STORE_NAME = 'Default Store View';

/**
* @var OptionsFactory
*/
private $modelFactory;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var WebsiteResource
*/
private $websiteResource;

/**
* @var StoreResource
*/
private $storeResource;

/**
* @var GroupResource
*/
private $groupResource;

/**
* @return void
*/
protected function setUp(): void
{
$objectManager = Bootstrap::getObjectManager();

$this->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;
}
}