Skip to content

Commit f4ea010

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-63587' into 2.1.8-develop-pr11
2 parents 856f6de + e1e34de commit f4ea010

File tree

10 files changed

+121
-27
lines changed

10 files changed

+121
-27
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public function execute(\Magento\Framework\Event\Observer $observer)
4747
{
4848
/** @var Category $category */
4949
$category = $observer->getEvent()->getCategory();
50-
if ($category->getUrlKey() !== false) {
50+
$useDefaultAttribute = !$category->isObjectNew() && !empty($category->getData('use_default')['url_key']);
51+
if ($category->getUrlKey() !== false && !$useDefaultAttribute) {
5152
$category->setUrlKey($this->categoryUrlPathGenerator->getUrlKey($category))
5253
->setUrlPath($this->categoryUrlPathGenerator->getUrlPath($category));
5354
if (!$category->isObjectNew()) {

app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/CategoryUrlPathAutogeneratorObserverTest.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,34 @@ class CategoryUrlPathAutogeneratorObserverTest extends \PHPUnit_Framework_TestCa
3737
protected function setUp()
3838
{
3939
$this->observer = $this->getMock(
40-
'Magento\Framework\Event\Observer',
41-
['getEvent', 'getCategory'],
40+
\Magento\Framework\Event\Observer::class,
41+
[
42+
'getEvent',
43+
'getCategory'
44+
],
45+
[],
46+
'',
47+
false
48+
);
49+
$this->categoryResource = $this->getMock(
50+
\Magento\Catalog\Model\ResourceModel\Category::class,
51+
[],
4252
[],
4353
'',
4454
false
4555
);
46-
$this->categoryResource = $this->getMock('Magento\Catalog\Model\ResourceModel\Category', [], [], '', false);
4756
$this->category = $this->getMock(
48-
'Magento\Catalog\Model\Category',
49-
['setUrlKey', 'setUrlPath', 'dataHasChangedFor', 'isObjectNew', 'getResource', 'getUrlKey', 'getStoreId'],
57+
\Magento\Catalog\Model\Category::class,
58+
[
59+
'setUrlKey',
60+
'setUrlPath',
61+
'dataHasChangedFor',
62+
'isObjectNew',
63+
'getResource',
64+
'getUrlKey',
65+
'getStoreId',
66+
'getData'
67+
],
5068
[],
5169
'',
5270
false
@@ -55,26 +73,26 @@ protected function setUp()
5573
$this->observer->expects($this->any())->method('getEvent')->willReturnSelf();
5674
$this->observer->expects($this->any())->method('getCategory')->willReturn($this->category);
5775
$this->categoryUrlPathGenerator = $this->getMock(
58-
'Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator',
76+
\Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator::class,
5977
[],
6078
[],
6179
'',
6280
false
6381
);
6482
$this->childrenCategoriesProvider = $this->getMock(
65-
'Magento\CatalogUrlRewrite\Model\Category\ChildrenCategoriesProvider'
83+
\Magento\CatalogUrlRewrite\Model\Category\ChildrenCategoriesProvider::class
6684
);
6785

6886
$this->storeViewService = $this->getMock(
69-
'Magento\CatalogUrlRewrite\Service\V1\StoreViewService',
87+
\Magento\CatalogUrlRewrite\Service\V1\StoreViewService::class,
7088
[],
7189
[],
7290
'',
7391
false
7492
);
7593

7694
$this->categoryUrlPathAutogeneratorObserver = (new ObjectManagerHelper($this))->getObject(
77-
'Magento\CatalogUrlRewrite\Observer\CategoryUrlPathAutogeneratorObserver',
95+
\Magento\CatalogUrlRewrite\Observer\CategoryUrlPathAutogeneratorObserver::class,
7896
[
7997
'categoryUrlPathGenerator' => $this->categoryUrlPathGenerator,
8098
'childrenCategoriesProvider' => $this->childrenCategoriesProvider,
@@ -90,7 +108,7 @@ public function testSetCategoryUrlAndCategoryPath()
90108
$this->category->expects($this->once())->method('setUrlKey')->with('urk_key')->willReturnSelf();
91109
$this->categoryUrlPathGenerator->expects($this->once())->method('getUrlPath')->willReturn('url_path');
92110
$this->category->expects($this->once())->method('setUrlPath')->with('url_path')->willReturnSelf();
93-
$this->category->expects($this->once())->method('isObjectNew')->willReturn(true);
111+
$this->category->expects($this->exactly(2))->method('isObjectNew')->willReturn(true);
94112

95113
$this->categoryUrlPathAutogeneratorObserver->execute($this->observer);
96114
}
@@ -114,7 +132,7 @@ public function testUrlKeyAndUrlPathUpdating()
114132
$this->category->expects($this->once())->method('setUrlKey')->with('url_key')->willReturnSelf();
115133
$this->category->expects($this->once())->method('setUrlPath')->with('url_path')->willReturnSelf();
116134
// break code execution
117-
$this->category->expects($this->once())->method('isObjectNew')->willReturn(true);
135+
$this->category->expects($this->exactly(2))->method('isObjectNew')->willReturn(true);
118136

119137
$this->categoryUrlPathAutogeneratorObserver->execute($this->observer);
120138
}
@@ -128,7 +146,7 @@ public function testUrlPathAttributeNoUpdatingIfCategoryIsNew()
128146
$this->category->expects($this->any())->method('setUrlKey')->willReturnSelf();
129147
$this->category->expects($this->any())->method('setUrlPath')->willReturnSelf();
130148

131-
$this->category->expects($this->once())->method('isObjectNew')->willReturn(true);
149+
$this->category->expects($this->exactly(2))->method('isObjectNew')->willReturn(true);
132150
$this->categoryResource->expects($this->never())->method('saveAttribute');
133151

134152
$this->categoryUrlPathAutogeneratorObserver->execute($this->observer);
@@ -142,7 +160,7 @@ public function testUrlPathAttributeUpdating()
142160
$this->category->expects($this->any())->method('getUrlKey')->willReturn('not_formatted_url_key');
143161
$this->category->expects($this->any())->method('setUrlKey')->willReturnSelf();
144162
$this->category->expects($this->any())->method('setUrlPath')->willReturnSelf();
145-
$this->category->expects($this->once())->method('isObjectNew')->willReturn(false);
163+
$this->category->expects($this->exactly(2))->method('isObjectNew')->willReturn(false);
146164

147165
$this->categoryResource->expects($this->once())->method('saveAttribute')->with($this->category, 'url_path');
148166

@@ -162,7 +180,7 @@ public function testChildrenUrlPathAttributeNoUpdatingIfParentUrlPathIsNotChange
162180
$this->category->expects($this->any())->method('getUrlKey')->willReturn('not_formatted_url_key');
163181
$this->category->expects($this->any())->method('setUrlKey')->willReturnSelf();
164182
$this->category->expects($this->any())->method('setUrlPath')->willReturnSelf();
165-
$this->category->expects($this->once())->method('isObjectNew')->willReturn(false);
183+
$this->category->expects($this->exactly(2))->method('isObjectNew')->willReturn(false);
166184
// break code execution
167185
$this->category->expects($this->once())->method('dataHasChangedFor')->with('url_path')->willReturn(false);
168186

@@ -177,7 +195,7 @@ public function testChildrenUrlPathAttributeUpdatingForSpecificStore()
177195
$this->category->expects($this->any())->method('getUrlKey')->willReturn('not_formatted_url_key');
178196
$this->category->expects($this->any())->method('setUrlKey')->willReturnSelf();
179197
$this->category->expects($this->any())->method('setUrlPath')->willReturnSelf();
180-
$this->category->expects($this->any())->method('isObjectNew')->willReturn(false);
198+
$this->category->expects($this->exactly(2))->method('isObjectNew')->willReturn(false);
181199
$this->category->expects($this->any())->method('dataHasChangedFor')->willReturn(true);
182200
// only for specific store
183201
$this->category->expects($this->atLeastOnce())->method('getStoreId')->willReturn(1);

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ public function fill(FixtureInterface $fixture, SimpleElement $element = null)
5353
$storeSwitcherBlock->find($this->dropdownBlock, Locator::SELECTOR_CSS, 'liselectstore')->setValue($store);
5454
$modalElement = $this->browser->find($this->confirmModal);
5555
/** @var \Magento\Ui\Test\Block\Adminhtml\Modal $modal */
56-
$modal = $this->blockFactory->create('Magento\Ui\Test\Block\Adminhtml\Modal', ['element' => $modalElement]);
56+
$modal = $this->blockFactory->create(
57+
\Magento\Ui\Test\Block\Adminhtml\Modal::class,
58+
['element' => $modalElement]
59+
);
5760
$modal->acceptAlert();
61+
$modal->waitModalWindowToDisappear();
5862
}
63+
5964
return parent::fill($fixture, $element);
6065
}
6166
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/CategoryForm.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<selector>input[name='name']</selector>
2525
</name>
2626
<use_default_name>
27-
<selector>[name="use_default[]"][value="name"]</selector>
27+
<selector>[name="use_default[name]"]</selector>
2828
<input>checkbox</input>
2929
</use_default_name>
3030
</fields>
@@ -90,6 +90,10 @@
9090
<input>input</input>
9191
<selector>input[name='url_key']</selector>
9292
</url_key>
93+
<use_default_url_key>
94+
<input>checkbox</input>
95+
<selector>input[name='use_default[url_key]']</selector>
96+
</use_default_url_key>
9397
<meta_title>
9498
<input>input</input>
9599
<selector>input[name='meta_title']</selector>

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Category/Edit/PageActions.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,39 @@
77
namespace Magento\Catalog\Test\Block\Adminhtml\Category\Edit;
88

99
use Magento\Backend\Test\Block\FormPageActions;
10+
use Magento\Mtf\Client\Locator;
1011

1112
/**
1213
* Category page actions.
1314
*/
1415
class PageActions extends FormPageActions
1516
{
17+
/**
18+
* Top page element to implement a scrolling in case of floating blocks overlay.
19+
*/
20+
const TOP_ELEMENT_TO_SCROLL = 'header.page-header';
21+
1622
/**
1723
* Locator for "OK" button in warning block
1824
*
1925
* @var string
2026
*/
2127
protected $warningBlock = '.ui-widget-content .ui-dialog-buttonset button:first-child';
2228

29+
/**
30+
* Change Store View selector.
31+
*
32+
* @var string
33+
*/
34+
protected $storeChangeButton = '#store-change-button';
35+
36+
/**
37+
* Selector for confirm.
38+
*
39+
* @var string
40+
*/
41+
protected $confirmModal = '.confirm._show[data-role=modal]';
42+
2343
/**
2444
* Click on "Save" button
2545
*
@@ -33,4 +53,23 @@ public function save()
3353
$warningBlock->click();
3454
}
3555
}
56+
57+
/**
58+
* Select Store View.
59+
*
60+
* @param string $name
61+
* @return void
62+
*/
63+
public function selectStoreView($name)
64+
{
65+
$this->browser->find(self::TOP_ELEMENT_TO_SCROLL)->hover();
66+
$this->_rootElement->find($this->storeChangeButton)->click();
67+
$this->waitForElementVisible($name, Locator::SELECTOR_LINK_TEXT);
68+
$this->_rootElement->find($name, Locator::SELECTOR_LINK_TEXT)->click();
69+
$element = $this->browser->find($this->confirmModal);
70+
/** @var \Magento\Ui\Test\Block\Adminhtml\Modal $modal */
71+
$modal = $this->blockFactory->create(\Magento\Ui\Test\Block\Adminhtml\Modal::class, ['element' => $element]);
72+
$modal->acceptAlert();
73+
$this->waitForElementVisible($this->storeChangeButton);
74+
}
3675
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCategoryForm.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class AssertCategoryForm extends AbstractAssertForm
2727
*/
2828
protected $skippedFixtureFields = [
2929
'parent_id',
30-
'id'
30+
'id',
31+
'store_id',
3132
];
3233

3334
/**
@@ -45,7 +46,10 @@ public function processAssert(
4546
) {
4647
$catalogCategoryIndex->open();
4748
$catalogCategoryIndex->getTreeCategories()->selectCategory($category, true);
48-
49+
if ($category->hasData('store_id')) {
50+
$storeName = $category->getStoreId()['source']->getName();
51+
$catalogCategoryEdit->getFormPageActions()->selectStoreView($storeName);
52+
}
4953
$fixtureData = $this->prepareFixtureData($category->getData());
5054
$formData = $catalogCategoryEdit->getEditForm()->getData($category);
5155
$error = $this->verifyData($this->sortData($fixtureData), $this->sortData($formData));

dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<field name="created_at" is_required="" />
2121
<field name="updated_at" is_required="" />
2222
<field name="id" group="null" />
23-
<field name="store_id" source="Magento\Catalog\Test\Fixture\Category\StoreId" />
23+
<field name="store_id" is_required="" group="null" source="Magento\Catalog\Test\Fixture\Category\StoreId" />
2424
<field name="parent_id" is_required="" group="null" source="Magento\Catalog\Test\Fixture\Category\ParentId" />
2525
<field name="path" is_required="" group="null" />
2626
<field name="children_count" is_required="" />
@@ -41,6 +41,7 @@
4141
<field name="use_config_price_range" is_required="0" group="display_setting" />
4242
<field name="layered_navigation_price_step" is_required="0" group="display_setting" />
4343
<field name="url_key" group="seo" />
44+
<field name="use_default_url_key" group="seo" />
4445
<field name="meta_title" is_required="" group="seo" />
4546
<field name="meta_keywords" is_required="" group="seo" />
4647
<field name="meta_description" is_required="" group="seo" />

dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Category.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
</field>
1818
</dataset>
1919

20+
<dataset name="default_with_custom_url">
21+
<field name="name" xsi:type="string">Category%isolation%</field>
22+
<field name="url_key" xsi:type="string">custom%isolation%</field>
23+
<field name="is_active" xsi:type="string">Yes</field>
24+
<field name="include_in_menu" xsi:type="string">Yes</field>
25+
<field name="parent_id" xsi:type="array">
26+
<item name="dataset" xsi:type="string">default_category</item>
27+
</field>
28+
<field name="use_default_url_key" xsi:type="string">Yes</field>
29+
</dataset>
30+
2031
<dataset name="default_category">
2132
<field name="name" xsi:type="string">Default Category</field>
2233
<field name="parent_id" xsi:type="string">1</field>

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,19 @@ class UpdateCategoryEntityTest extends Injectable
6161
/**
6262
* Inject page end prepare default category
6363
*
64-
* @param Category $initialCategory
6564
* @param CatalogCategoryIndex $catalogCategoryIndex
6665
* @param CatalogCategoryEdit $catalogCategoryEdit
6766
* @param FixtureFactory $fixtureFactory
68-
* @return array
67+
* @return void
6968
*/
7069
public function __inject(
71-
Category $initialCategory,
7270
CatalogCategoryIndex $catalogCategoryIndex,
7371
CatalogCategoryEdit $catalogCategoryEdit,
7472
FixtureFactory $fixtureFactory
7573
) {
7674
$this->fixtureFactory = $fixtureFactory;
7775
$this->catalogCategoryIndex = $catalogCategoryIndex;
7876
$this->catalogCategoryEdit = $catalogCategoryEdit;
79-
$initialCategory->persist();
80-
return ['initialCategory' => $initialCategory];
8177
}
8278

8379
/**
@@ -89,6 +85,7 @@ public function __inject(
8985
*/
9086
public function test(Category $category, Category $initialCategory)
9187
{
88+
$initialCategory->persist();
9289
$this->catalogCategoryIndex->open();
9390
$this->catalogCategoryIndex->getTreeCategories()->selectCategory($initialCategory);
9491
$this->catalogCategoryEdit->getEditForm()->fill($category);
@@ -110,11 +107,16 @@ protected function prepareCategory(Category $category, Category $initialCategory
110107
? $category->getDataFieldConfig('parent_id')['source']->getParentCategory()
111108
: $initialCategory->getDataFieldConfig('parent_id')['source']->getParentCategory();
112109

110+
$rewriteData = ['parent_id' => ['source' => $parentCategory]];
111+
if ($category->hasData('store_id')) {
112+
$rewriteData['store_id'] = ['source' => $category->getDataFieldConfig('store_id')['source']->getStore()];
113+
}
114+
113115
$data = [
114116
'data' => array_merge(
115117
$initialCategory->getData(),
116118
$category->getData(),
117-
['parent_id' => ['source' => $parentCategory]]
119+
$rewriteData
118120
)
119121
];
120122

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Category/UpdateCategoryEntityTest.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,14 @@
5151
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
5252
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryWithCustomStoreOnFrontend" />
5353
</variation>
54+
55+
<variation name="UpdateCategoryEntityTestVariation6_CheckCategoryDefaultUrlOnStoreView" summary="Check default URL Key on the custom Store View." ticketId="MAGETWO-69101">
56+
<data name="initialCategory/dataset" xsi:type="string">default_with_custom_url</data>
57+
<data name="category/data/parent_id/dataset" xsi:type="string">default_category</data>
58+
<data name="category/data/store_id/dataset" xsi:type="string">custom</data>
59+
<data name="category/data/use_default_url_key" xsi:type="string">Yes</data>
60+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
61+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryForm" />
62+
</variation>
5463
</testCase>
5564
</config>

0 commit comments

Comments
 (0)