Skip to content

Commit bce1876

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-95518' into 2.2-develop-mftf-pr10
2 parents 5b4f4f6 + a9d9120 commit bce1876

File tree

79 files changed

+1383
-154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1383
-154
lines changed

app/code/Magento/Catalog/Test/Mftf/ActionGroup/AddProductToCartActionGroup.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
-->
88

99
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10-
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/actionGroupSchema.xsd">
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
1111
<actionGroup name="AddSimpleProductToCart">
1212
<arguments>
1313
<argument name="product" defaultValue="product"/>
1414
</arguments>
1515
<amOnPage stepKey="navigateProductPage" url="/{{product.name}}.html"/>
1616
<click stepKey="addToCart" selector="{{StorefrontProductPageSection.addToCartBtn}}"/>
1717
<waitForElementVisible selector="{{StorefrontProductPageSection.successMsg}}" time="30" stepKey="waitForProductAdded"/>
18-
</actionGroup>.
18+
</actionGroup>
19+
1920
<!--Click Add to Cart button in storefront product page-->
2021
<actionGroup name="addToCartFromStorefrontProductPage">
2122
<arguments>
@@ -28,4 +29,12 @@
2829
<waitForPageLoad stepKey="waitForPageLoad"/>
2930
<see selector="{{StorefrontMessagesSection.success}}" userInput="You added {{productName}} to your shopping cart." stepKey="seeAddToCartSuccessMessage"/>
3031
</actionGroup>
32+
33+
<actionGroup name="StorefrontAddProductToCartQuantityActionGroup" extends="addToCartFromStorefrontProductPage">
34+
<arguments>
35+
<argument name="quantity" type="string" defaultValue="1"/>
36+
</arguments>
37+
<waitForElementVisible selector="{{StorefrontProductPageSection.qtyInput}}" time="30" before="addToCart" stepKey="waitQuantityFieldVisible"/>
38+
<fillField selector="{{StorefrontProductPageSection.qtyInput}}" userInput="{{quantity}}" after="waitQuantityFieldVisible" stepKey="fillQuantityField"/>
39+
</actionGroup>
3140
</actionGroups>

app/code/Magento/Catalog/Test/Mftf/ActionGroup/StorefrontAddToCartCustomOptionsProductPageActionGroup.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<argument name="productName"/>
1414
</arguments>
1515
<click selector="{{StorefrontProductPageSection.addToCartBtn}}" stepKey="addToCart"/>
16-
<waitForPageLoad stepKey="waitForPageLoad"/>
1716
<see selector="{{StorefrontProductPageSection.successMsg}}" userInput="You added {{productName}} to your shopping cart." stepKey="seeAddToCartSuccessMessage"/>
1817
</actionGroup>
1918
</actionGroups>

app/code/Magento/Catalog/Test/Mftf/Page/AdminCategoryEditPage.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@
1616
<section name="AdminCategoryBasicFieldSection"/>
1717
<section name="AdminCategorySEOSection"/>
1818
<section name="AdminCategoryModalSection"/>
19+
<section name="AdminCategoryContentSection"/>
20+
<section name="AdminCategoryDisplaySettingsSection"/>
1921
</page>
2022
</pages>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminCategoryContentSection">
12+
<element name="sectionHeader" type="button" selector="div[data-index='content']" timeout="30"/>
13+
<element name="addCMSBlock" type="select" selector="[name='landing_page']"/>
14+
</section>
15+
</sections>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminCategoryDisplaySettingsSection">
12+
<element name="settingsHeader" type="button" selector="[data-index='display_settings'] strong.admin__collapsible-title" timeout="30"/>
13+
<element name="displayMode" type="button" selector="[name='display_mode']"/>
14+
</section>
15+
</sections>

app/code/Magento/Catalog/Test/Mftf/Section/StorefrontProductPageSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="StorefrontProductPageSection">
1212
<element name="qtyInput" type="button" selector="input.input-text.qty"/>
13-
<element name="addToCartBtn" type="button" selector="button.action.tocart.primary"/>
13+
<element name="addToCartBtn" type="button" selector="button.action.tocart.primary" timeout="30"/>
1414
<element name="successMsg" type="button" selector="div.message-success"/>
1515
<element name="addToWishlist" type="button" selector="a.action.towishlist" timeout="30"/>
1616
<element name="addToCartButtonTitleIsAdding" type="text" selector="//button/span[text()='Adding...']"/>

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/DataProvider.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Store\Model\Store;
1313

1414
/**
15+
* Catalog search full text search data provider.
16+
*
1517
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1618
* @SuppressWarnings(PHPMD.TooManyFields)
1719
* @api
@@ -571,8 +573,8 @@ public function prepareProductIndex($indexData, $productData, $storeId)
571573
}
572574
}
573575
foreach ($indexData as $entityId => $attributeData) {
574-
foreach ($attributeData as $attributeId => $attributeValue) {
575-
$value = $this->getAttributeValue($attributeId, $attributeValue, $storeId);
576+
foreach ($attributeData as $attributeId => $attributeValues) {
577+
$value = $this->getAttributeValue($attributeId, $attributeValues, $storeId);
576578
if (!empty($value)) {
577579
if (isset($index[$attributeId])) {
578580
$index[$attributeId][$entityId] = $value;
@@ -603,16 +605,16 @@ public function prepareProductIndex($indexData, $productData, $storeId)
603605
* Retrieve attribute source value for search
604606
*
605607
* @param int $attributeId
606-
* @param mixed $valueId
608+
* @param mixed $valueIds
607609
* @param int $storeId
608610
* @return string
609611
*/
610-
private function getAttributeValue($attributeId, $valueId, $storeId)
612+
private function getAttributeValue($attributeId, $valueIds, $storeId)
611613
{
612614
$attribute = $this->getSearchableAttribute($attributeId);
613-
$value = $this->engine->processAttributeValue($attribute, $valueId);
615+
$value = $this->engine->processAttributeValue($attribute, $valueIds);
614616
if (false !== $value) {
615-
$optionValue = $this->getAttributeOptionValue($attributeId, $valueId, $storeId);
617+
$optionValue = $this->getAttributeOptionValue($attributeId, $valueIds, $storeId);
616618
if (null === $optionValue) {
617619
$value = preg_replace('/\s+/iu', ' ', trim(strip_tags($value)));
618620
} else {
@@ -627,13 +629,15 @@ private function getAttributeValue($attributeId, $valueId, $storeId)
627629
* Get attribute option value
628630
*
629631
* @param int $attributeId
630-
* @param int $valueId
632+
* @param int|string $valueIds
631633
* @param int $storeId
632634
* @return null|string
633635
*/
634-
private function getAttributeOptionValue($attributeId, $valueId, $storeId)
636+
private function getAttributeOptionValue($attributeId, $valueIds, $storeId)
635637
{
636638
$optionKey = $attributeId . '-' . $storeId;
639+
$attributeValueIds = explode(',', $valueIds);
640+
$attributeOptionValue = '';
637641
if (!array_key_exists($optionKey, $this->attributeOptions)
638642
) {
639643
$attribute = $this->getSearchableAttribute($attributeId);
@@ -649,6 +653,12 @@ private function getAttributeOptionValue($attributeId, $valueId, $storeId)
649653
}
650654
}
651655

652-
return $this->attributeOptions[$optionKey][$valueId] ?? null;
656+
foreach ($attributeValueIds as $attributeValueId) {
657+
if (isset($this->attributeOptions[$optionKey][$attributeValueId])) {
658+
$attributeOptionValue .= $this->attributeOptions[$optionKey][$attributeValueId] . ' ';
659+
}
660+
}
661+
662+
return empty($attributeOptionValue) ? null : trim($attributeOptionValue);
653663
}
654664
}

app/code/Magento/CatalogUrlRewrite/Model/CategoryUrlPathGenerator.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Magento\Catalog\Api\CategoryRepositoryInterface;
99
use Magento\Catalog\Model\Category;
1010

11+
/**
12+
* Class for generation category url_path.
13+
*/
1114
class CategoryUrlPathGenerator
1215
{
1316
/**
@@ -58,12 +61,13 @@ public function __construct(
5861
}
5962

6063
/**
61-
* Build category URL path
64+
* Build category URL path.
6265
*
6366
* @param \Magento\Catalog\Api\Data\CategoryInterface|\Magento\Framework\Model\AbstractModel $category
67+
* @param null|\Magento\Catalog\Api\Data\CategoryInterface|\Magento\Framework\Model\AbstractModel $parentCategory
6468
* @return string
6569
*/
66-
public function getUrlPath($category)
70+
public function getUrlPath($category, $parentCategory = null)
6771
{
6872
if (in_array($category->getParentId(), [Category::ROOT_CATEGORY_ID, Category::TREE_ROOT_ID])) {
6973
return '';
@@ -77,15 +81,18 @@ public function getUrlPath($category)
7781
return $category->getUrlPath();
7882
}
7983
if ($this->isNeedToGenerateUrlPathForParent($category)) {
80-
$parentPath = $this->getUrlPath(
81-
$this->categoryRepository->get($category->getParentId(), $category->getStoreId())
82-
);
84+
$parentCategory = $parentCategory ??
85+
$this->categoryRepository->get($category->getParentId(), $category->getStoreId());
86+
$parentPath = $this->getUrlPath($parentCategory);
8387
$path = $parentPath === '' ? $path : $parentPath . '/' . $path;
8488
}
89+
8590
return $path;
8691
}
8792

8893
/**
94+
* Define whether we should generate URL path for parent.
95+
*
8996
* @param \Magento\Catalog\Model\Category $category
9097
* @return bool
9198
*/

app/code/Magento/CatalogUrlRewrite/Observer/CategoryUrlPathAutogeneratorObserver.php

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use Magento\Framework\Event\ObserverInterface;
1414
use Magento\Store\Model\Store;
1515

16+
/**
17+
* Class observer to initiate generation category url_path.
18+
*/
1619
class CategoryUrlPathAutogeneratorObserver implements ObserverInterface
1720
{
1821
/**
@@ -46,6 +49,8 @@ public function __construct(
4649
}
4750

4851
/**
52+
* Generate Category Url Path.
53+
*
4954
* @param \Magento\Framework\Event\Observer $observer
5055
* @return void
5156
* @throws \Magento\Framework\Exception\LocalizedException
@@ -57,21 +62,39 @@ public function execute(\Magento\Framework\Event\Observer $observer)
5762
$useDefaultAttribute = !$category->isObjectNew() && !empty($category->getData('use_default')['url_key']);
5863
if ($category->getUrlKey() !== false && !$useDefaultAttribute) {
5964
$resultUrlKey = $this->categoryUrlPathGenerator->getUrlKey($category);
60-
if (empty($resultUrlKey)) {
61-
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid URL key'));
62-
}
63-
$category->setUrlKey($resultUrlKey)
64-
->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
65-
if (!$category->isObjectNew()) {
66-
$category->getResource()->saveAttribute($category, 'url_path');
67-
if ($category->dataHasChangedFor('url_path')) {
68-
$this->updateUrlPathForChildren($category);
69-
}
65+
$this->updateUrlKey($category, $resultUrlKey);
66+
} else if ($useDefaultAttribute) {
67+
$resultUrlKey = $category->formatUrlKey($category->getOrigData('name'));
68+
$this->updateUrlKey($category, $resultUrlKey);
69+
$category->setUrlKey(null)->setUrlPath(null);
70+
}
71+
}
72+
73+
/**
74+
* Update Url Key.
75+
*
76+
* @param Category $category
77+
* @param string $urlKey
78+
* @throws \Magento\Framework\Exception\LocalizedException
79+
*/
80+
private function updateUrlKey(Category $category, string $urlKey)
81+
{
82+
if (empty($urlKey)) {
83+
throw new \Magento\Framework\Exception\LocalizedException(__('Invalid URL key'));
84+
}
85+
$category->setUrlKey($urlKey)
86+
->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
87+
if (!$category->isObjectNew()) {
88+
$category->getResource()->saveAttribute($category, 'url_path');
89+
if ($category->dataHasChangedFor('url_path')) {
90+
$this->updateUrlPathForChildren($category);
7091
}
7192
}
7293
}
7394

7495
/**
96+
* Update URL path for children.
97+
*
7598
* @param Category $category
7699
* @return void
77100
*/
@@ -94,8 +117,13 @@ protected function updateUrlPathForChildren(Category $category)
94117
}
95118
} else {
96119
foreach ($children as $child) {
120+
/** @var Category $child */
97121
$child->setStoreId($category->getStoreId());
98-
$this->updateUrlPathForCategory($child);
122+
if ($child->getParentId() === $category->getId()) {
123+
$this->updateUrlPathForCategory($child, $category);
124+
} else {
125+
$this->updateUrlPathForCategory($child);
126+
}
99127
}
100128
}
101129
}
@@ -112,13 +140,16 @@ protected function isGlobalScope($storeId)
112140
}
113141

114142
/**
143+
* Update URL path for category.
144+
*
115145
* @param Category $category
146+
* @param Category|null $parentCategory
116147
* @return void
117148
*/
118-
protected function updateUrlPathForCategory(Category $category)
149+
protected function updateUrlPathForCategory(Category $category, Category $parentCategory = null)
119150
{
120151
$category->unsUrlPath();
121-
$category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
152+
$category->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category, $parentCategory));
122153
$category->getResource()->saveAttribute($category, 'url_path');
123154
}
124155
}

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/CategoryUrlPathGeneratorTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,61 @@ public function testGetUrlPathWithParent(
157157
$this->assertEquals($result, $this->categoryUrlPathGenerator->getUrlPath($this->category));
158158
}
159159

160+
/**
161+
* @return array
162+
*/
163+
public function getUrlPathWithParentCategoryDataProvider(): array
164+
{
165+
$requireGenerationLevel = CategoryUrlPathGenerator::MINIMAL_CATEGORY_LEVEL_FOR_PROCESSING;
166+
$noGenerationLevel = CategoryUrlPathGenerator::MINIMAL_CATEGORY_LEVEL_FOR_PROCESSING - 1;
167+
return [
168+
[13, 'url-key', false, $requireGenerationLevel, 10, 'parent-path', 'parent-path/url-key'],
169+
[13, 'url-key', false, $requireGenerationLevel, Category::TREE_ROOT_ID, null, 'url-key'],
170+
[13, 'url-key', true, $noGenerationLevel, Category::TREE_ROOT_ID, null, 'url-key'],
171+
];
172+
}
173+
174+
/**
175+
* Test receiving Url Path when parent category is presented.
176+
*
177+
* @param int $parentId
178+
* @param string $urlKey
179+
* @param bool $isCategoryNew
180+
* @param bool $level
181+
* @param int $parentCategoryParentId
182+
* @param null|string $parentUrlPath
183+
* @param string $result
184+
* @dataProvider getUrlPathWithParentCategoryDataProvider
185+
*/
186+
public function testGetUrlPathWithParentCategory(
187+
int $parentId,
188+
string $urlKey,
189+
bool $isCategoryNew,
190+
bool $level,
191+
int $parentCategoryParentId,
192+
$parentUrlPath,
193+
string $result
194+
) {
195+
$urlPath = null;
196+
$this->category->expects($this->any())->method('getParentId')->willReturn($parentId);
197+
$this->category->expects($this->any())->method('getLevel')->willReturn($level);
198+
$this->category->expects($this->any())->method('getUrlPath')->willReturn($urlPath);
199+
$this->category->expects($this->any())->method('getUrlKey')->willReturn($urlKey);
200+
$this->category->expects($this->any())->method('isObjectNew')->willReturn($isCategoryNew);
201+
202+
$methods = ['getUrlPath', 'getParentId'];
203+
$parentCategoryMock = $this->createPartialMock(\Magento\Catalog\Model\Category::class, $methods);
204+
$parentCategoryMock->expects($this->any())->method('getParentId')->willReturn($parentCategoryParentId);
205+
$parentCategoryMock->expects($this->any())->method('getUrlPath')->willReturn($parentUrlPath);
206+
207+
$this->categoryRepository->expects($this->any())
208+
->method('get')
209+
->with($parentCategoryParentId)
210+
->willReturn($parentCategoryMock);
211+
212+
$this->assertEquals($result, $this->categoryUrlPathGenerator->getUrlPath($this->category, $parentCategoryMock));
213+
}
214+
160215
/**
161216
* @return array
162217
*/

0 commit comments

Comments
 (0)