Skip to content

Commit 3adf326

Browse files
author
Oleksandr Iegorov
committed
MAGETWO-61549: Use default URL Key
1 parent 3c37373 commit 3adf326

File tree

6 files changed

+125
-7
lines changed

6 files changed

+125
-7
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public function fill(FixtureInterface $fixture, SimpleElement $element = null)
5959
);
6060
$modal->acceptAlert();
6161
}
62+
if ($fixture->hasData('use_default_url_key')) {
63+
$this->openContainer('seo');
64+
}
65+
6266
return parent::fill($fixture, $element);
6367
}
6468
}

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

Lines changed: 1 addition & 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>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Fixture\Category;
10+
use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryEdit;
11+
use Magento\Mtf\Constraint\AbstractConstraint;
12+
13+
/**
14+
* Class AssertCategoryCheckDefaultUrl
15+
* Assert that category form contains proper values of the url key related fields after category save
16+
*/
17+
class AssertCategoryCheckDefaultUrl extends AbstractConstraint
18+
{
19+
/* tags */
20+
const SEVERITY = 'low';
21+
/* end tags */
22+
23+
protected $urlKeyRelatedFields = [
24+
'url_key',
25+
'use_default_url_key'
26+
];
27+
28+
/**
29+
* Assert that displayed category data on edit page correct
30+
*
31+
* @param CatalogCategoryEdit $catalogCategoryEdit
32+
* @param Category $category
33+
* @return void
34+
*/
35+
public function processAssert(
36+
CatalogCategoryEdit $catalogCategoryEdit,
37+
Category $category
38+
) {
39+
40+
$catalogCategoryEdit->getEditForm()->openSection('seo');
41+
$formData = $catalogCategoryEdit->getEditForm()->getSection('seo')->getFieldsData();
42+
$formData = $this->prepareFormData($formData);
43+
$fixtureData = $this->prepareFixtureData($category->getData());
44+
\PHPUnit_Framework_Assert::assertEquals($fixtureData, $formData, 'Incorrect Url Key');
45+
}
46+
47+
/**
48+
* Prepares form data for comparison.
49+
*
50+
* @param array $data
51+
* @return array
52+
*/
53+
protected function prepareFormData(array $data)
54+
{
55+
$preparedData = [
56+
'url_key' => null,
57+
'use_default_url_key' => null
58+
];
59+
if (!empty($data['url_key'])) {
60+
$preparedData['url_key'] = $data['url_key'];
61+
}
62+
if (!empty($data['use_default_url_key'])) {
63+
$preparedData['use_default_url_key'] = $data['use_default_url_key'];
64+
}
65+
return $preparedData;
66+
}
67+
68+
/**
69+
* Prepares fixture data for comparison.
70+
*
71+
* @param array $data
72+
* @return array
73+
*/
74+
protected function prepareFixtureData(array $data)
75+
{
76+
$preparedData = [
77+
'url_key' => null,
78+
'use_default_url_key' => 'yes'
79+
];
80+
if (!empty($data['url_key'])) {
81+
$preparedData['url_key'] = $data['url_key'];
82+
}
83+
if (!empty($data['use_default_url_key'])) {
84+
$preparedData['use_default_url_key'] = $data['use_default_url_key'];
85+
}
86+
return $preparedData;
87+
}
88+
89+
/**
90+
* Returns a string representation of the object.
91+
*
92+
* @return string
93+
*/
94+
public function toString()
95+
{
96+
return 'Category URL key is correct';
97+
}
98+
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@
99
<repository class="Magento\Catalog\Test\Repository\Category">
1010
<dataset name="default">
1111
<field name="name" xsi:type="string">Category%isolation%</field>
12-
<field name="url_key" xsi:type="string">category%isolation%</field>
12+
<field name="url_key" xsi:type="string">cccategory%isolation%</field>
13+
<field name="is_active" xsi:type="string">Yes</field>
14+
<field name="include_in_menu" xsi:type="string">Yes</field>
15+
<field name="parent_id" xsi:type="array">
16+
<item name="dataset" xsi:type="string">default_category</item>
17+
</field>
18+
</dataset>
19+
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>
1323
<field name="is_active" xsi:type="string">Yes</field>
1424
<field name="include_in_menu" xsi:type="string">Yes</field>
1525
<field name="parent_id" xsi:type="array">
1626
<item name="dataset" xsi:type="string">default_category</item>
1727
</field>
28+
<field name="use_default_url_key" xsi:type="string">Yes</field>
1829
</dataset>
1930

2031
<dataset name="default_category">

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,19 @@ class UpdateCategoryEntityTest extends Injectable
6060
/**
6161
* Inject page end prepare default category
6262
*
63-
* @param Category $initialCategory
6463
* @param CatalogCategoryIndex $catalogCategoryIndex
6564
* @param CatalogCategoryEdit $catalogCategoryEdit
6665
* @param FixtureFactory $fixtureFactory
67-
* @return array
66+
* @return void
6867
*/
6968
public function __inject(
70-
Category $initialCategory,
7169
CatalogCategoryIndex $catalogCategoryIndex,
7270
CatalogCategoryEdit $catalogCategoryEdit,
7371
FixtureFactory $fixtureFactory
7472
) {
7573
$this->fixtureFactory = $fixtureFactory;
7674
$this->catalogCategoryIndex = $catalogCategoryIndex;
7775
$this->catalogCategoryEdit = $catalogCategoryEdit;
78-
$initialCategory->persist();
79-
return ['initialCategory' => $initialCategory];
8076
}
8177

8278
/**
@@ -88,6 +84,7 @@ public function __inject(
8884
*/
8985
public function test(Category $category, Category $initialCategory)
9086
{
87+
$initialCategory->persist();
9188
$this->catalogCategoryIndex->open();
9289
$this->catalogCategoryIndex->getTreeCategories()->selectCategory($initialCategory);
9390
$this->catalogCategoryEdit->getEditForm()->fill($category);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,13 @@
5959
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
6060
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryOnCustomStore" />
6161
</variation>
62+
<variation name="UpdateCategoryEntityTestVariation6_CheckCategoryDefaultUrlOnStoreView" summary="Check default URL Key on the custom Store View." ticketId="MAGETWO-64337">
63+
<data name="initialCategory/dataset" xsi:type="string">default_with_custom_url</data>
64+
<data name="category/data/parent_id/dataset" xsi:type="string">default_category</data>
65+
<data name="category/data/store_id/dataset" xsi:type="string">custom</data>
66+
<data name="category/data/use_default_url_key" xsi:type="string">Yes</data>
67+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategorySaveMessage" />
68+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryCheckDefaultUrl" />
69+
</variation>
6270
</testCase>
6371
</config>

0 commit comments

Comments
 (0)