Skip to content

Commit 67c1a2d

Browse files
author
Vadim Zubovich
committed
Merge branch 'MTO-91-new' into 'iteration2-pr-new'
MTO-91: [Test] Url rewrites in catalog categories after changing url key for sto… …re view and moving category - Functional test implemented. See merge request !96
2 parents eac993b + d3019a6 commit 67c1a2d

File tree

9 files changed

+300
-0
lines changed

9 files changed

+300
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = '.page-title';
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)->click();
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/Block/Adminhtml/Category/Tree.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ class Tree extends Block
6060
*/
6161
protected $header = 'header';
6262

63+
/**
64+
* Xpath locator for category in tree.
65+
*
66+
* @var string
67+
*/
68+
protected $categoryInTree = '//*[@class="x-tree-node-ct"]/li/div/a/span[contains(text(), "%s")]/..';
69+
6370
/**
6471
* Get backend abstract block.
6572
*
@@ -153,6 +160,26 @@ public function isCategoryVisible(Category $category)
153160
->isElementVisible($categoryPath);
154161
}
155162

163+
/**
164+
* Assign child category to the parent.
165+
*
166+
* @param string $parentCategoryName
167+
* @param string $childCategoryName
168+
*
169+
* @return void
170+
*/
171+
public function assignCategory($parentCategoryName, $childCategoryName)
172+
{
173+
$this->_rootElement->find(sprintf($this->categoryInTree, $childCategoryName), Locator::SELECTOR_XPATH)->click();
174+
$this->getTemplateBlock()->waitLoader();
175+
$targetElement = $this->_rootElement->find(
176+
sprintf($this->categoryInTree, $parentCategoryName),
177+
Locator::SELECTOR_XPATH
178+
);
179+
$this->_rootElement->find(sprintf($this->categoryInTree, $childCategoryName), Locator::SELECTOR_XPATH)
180+
->dragAndDrop($targetElement);
181+
}
182+
156183
/**
157184
* Expand all categories tree.
158185
*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/Theme/Test/Block/Html/Topmenu.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ function () use ($category) {
6363
$category[0]->click();
6464
}
6565

66+
/**
67+
* Hover on category from top menu by name.
68+
*
69+
* @param string $categoryName
70+
* @return void
71+
*/
72+
public function hoverCategoryByName($categoryName)
73+
{
74+
$rootElement = $this->_rootElement;
75+
$category = $this->waitLoadTopMenu($categoryName);
76+
if ($category[1]) {
77+
$rootElement->waitUntil(
78+
function () use ($category) {
79+
return $category[0]->isVisible() ? true : null;
80+
}
81+
);
82+
}
83+
$category[0]->hover();
84+
}
85+
6686
/**
6787
* Check is visible category in top menu by name
6888
*

dev/tests/functional/tests/app/Magento/Ui/Test/Block/Adminhtml/Modal.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,27 @@ class Modal extends Block
4141
*/
4242
protected $inputFieldSelector = '[data-role="promptField"]';
4343

44+
/**
45+
* Locator value for accept warning button.
46+
*
47+
* @var string
48+
*/
49+
protected $acceptWarningSelector = '.action-primary';
50+
4451
/**
4552
* Modal overlay selector.
4653
*
4754
* @var string
4855
*/
4956
protected $modalOverlay = '.modals-overlay';
5057

58+
/**
59+
* Selector for spinner element.
60+
*
61+
* @var string
62+
*/
63+
protected $loadingMask = '[data-role="loader"]';
64+
5165
/**
5266
* Press OK on an alert, confirm, prompt a dialog.
5367
*
@@ -59,6 +73,18 @@ public function acceptAlert()
5973
$this->_rootElement->find($this->acceptButtonSelector)->click();
6074
}
6175

76+
/**
77+
* Press OK on a warning popup.
78+
*
79+
* @return void
80+
*/
81+
public function acceptWarning()
82+
{
83+
$this->waitModalAnimationFinished();
84+
$this->_rootElement->find($this->acceptWarningSelector)->click();
85+
$this->waitForElementNotVisible($this->loadingMask);
86+
}
87+
6288
/**
6389
* Press Cancel on an alert, confirm, prompt a dialog.
6490
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\UrlRewrite\Test\Constraint;
8+
9+
use Magento\Catalog\Test\Fixture\Category;
10+
use Magento\Cms\Test\Page\CmsIndex;
11+
use Magento\Mtf\Constraint\AbstractConstraint;
12+
use Magento\Mtf\Client\BrowserInterface;
13+
use Magento\Store\Test\Fixture\Store;
14+
15+
/**
16+
* Class AssertCategoryUrlWithCustomStoreView.
17+
*/
18+
class AssertCategoryUrlWithCustomStoreView extends AbstractConstraint
19+
{
20+
/**
21+
* Assert that displayed category data on category page equals to passed from fixture.
22+
*
23+
* @param Store $storeView
24+
* @param Category $childCategory
25+
* @param Category $parentCategory
26+
* @param Category $categoryUpdates
27+
* @param CmsIndex $cmsIndex
28+
* @param BrowserInterface $browser
29+
*/
30+
public function processAssert(
31+
Store $storeView,
32+
Category $childCategory,
33+
Category $parentCategory,
34+
Category $categoryUpdates,
35+
CmsIndex $cmsIndex,
36+
BrowserInterface $browser
37+
) {
38+
$cmsIndex->open();
39+
$cmsIndex->getStoreSwitcherBlock()->selectStoreView($storeView->getName());
40+
$cmsIndex->getTopmenu()->hoverCategoryByName($parentCategory->getName());
41+
$cmsIndex->getTopmenu()->selectCategoryByName(
42+
$childCategory->getName()
43+
);
44+
$actualUrl = strtolower($parentCategory->getUrlKey() . '/' . $categoryUpdates->getUrlKey());
45+
$result = (bool)strpos($browser->getUrl(), $actualUrl);
46+
47+
\PHPUnit_Framework_Assert::assertTrue(
48+
$result,
49+
"Category URL is not correct."
50+
);
51+
}
52+
53+
/**
54+
* Returns a string representation of the object.
55+
*
56+
* @return string
57+
*/
58+
public function toString()
59+
{
60+
return 'Category URL is correct.';
61+
}
62+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\UrlRewrite\Test\TestCase;
8+
9+
use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryIndex;
10+
use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryEdit;
11+
use Magento\Catalog\Test\Fixture\Category;
12+
use Magento\Mtf\TestCase\Injectable;
13+
use Magento\Store\Test\Fixture\Store;
14+
15+
/**
16+
* Test for Url rewrites in catalog categories after changing url key for store view and moving category.
17+
*
18+
* Preconditions:
19+
* 1. Create additional Store View in Main Website Store.
20+
* 2. Create sub-categories "first-test" and "second-test" in Default Category.
21+
* 3. Add one or more any products to created sub-categories.
22+
* 4. Reindex and clean caches.
23+
*
24+
* Steps:
25+
* 1. Log in to backend.
26+
* 2. Navigate to Products > Categories.
27+
* 3. On the categories editing page change store view to created additional view.
28+
* 4. Change URL key for category "first-test" from default to "first-test-2". Save.
29+
* 5. Change store view to "All store views".
30+
* 6. Move category "first-test" inside "second-test".
31+
* 7. Perform all assertions.
32+
*
33+
* @ZephyrId MAGETWO-45385
34+
*/
35+
class CategoryUrlRewriteTest extends Injectable
36+
{
37+
/**
38+
* CatalogCategoryIndex page.
39+
*
40+
* @var CatalogCategoryIndex
41+
*/
42+
private $catalogCategoryIndex;
43+
44+
/**
45+
* CatalogCategoryEdit page.
46+
*
47+
* @var CatalogCategoryEdit
48+
*/
49+
private $catalogCategoryEdit;
50+
51+
/**
52+
* Inject page end prepare default category.
53+
*
54+
* @param CatalogCategoryIndex $catalogCategoryIndex
55+
* @param CatalogCategoryEdit $catalogCategoryEdit
56+
* @return array
57+
*/
58+
public function __inject(
59+
CatalogCategoryIndex $catalogCategoryIndex,
60+
CatalogCategoryEdit $catalogCategoryEdit
61+
) {
62+
$this->catalogCategoryIndex = $catalogCategoryIndex;
63+
$this->catalogCategoryEdit = $catalogCategoryEdit;
64+
}
65+
66+
/**
67+
* Runs test.
68+
*
69+
* @param Store $storeView
70+
* @param Category $childCategory
71+
* @param Category $parentCategory
72+
* @param Category $categoryUpdates
73+
* @return array
74+
*/
75+
public function test(Store $storeView, Category $childCategory, Category $parentCategory, Category $categoryUpdates)
76+
{
77+
//Preconditions:
78+
$storeView->persist();
79+
$parentCategory->persist();
80+
$childCategory->persist();
81+
82+
// Steps:
83+
$this->catalogCategoryIndex->open();
84+
$this->catalogCategoryIndex->getTreeCategories()->selectCategory($childCategory);
85+
$this->catalogCategoryEdit->getFormPageActions()->selectStoreView($storeView->getName());
86+
$this->catalogCategoryEdit->getEditForm()->fill($categoryUpdates);
87+
$this->catalogCategoryEdit->getFormPageActions()->save();
88+
$this->catalogCategoryIndex->getTreeCategories()->assignCategory(
89+
$parentCategory->getName(),
90+
$childCategory->getName()
91+
);
92+
$this->catalogCategoryEdit->getModalBlock()->acceptWarning();
93+
94+
return [
95+
'storeView' => $storeView,
96+
'childCategory' => $childCategory,
97+
'parentCategory' => $parentCategory
98+
];
99+
}
100+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2016 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\UrlRewrite\Test\TestCase\CategoryUrlRewriteTest" summary="Check url rewrites in catalog categories after changing url key for store view and moving category." ticketId="MAGETWO-45385">
10+
<variation name="CategoryUrlRewriteTestVariation1">
11+
<data name="storeView/dataset" xsi:type="string">custom</data>
12+
<data name="childCategory/dataset" xsi:type="string">default</data>
13+
<data name="childCategory/data/category_products/dataset" xsi:type="string">catalogProductSimple::default</data>
14+
<data name="parentCategory/dataset" xsi:type="string">default</data>
15+
<data name="parentCategory/data/category_products/dataset" xsi:type="string">catalogProductSimple::default</data>
16+
<data name="categoryUpdates/data/use_default_url_key" xsi:type="string">No</data>
17+
<data name="categoryUpdates/data/url_key" xsi:type="string">UrlKey%isolation%</data>
18+
<constraint name="Magento\UrlRewrite\Test\Constraint\AssertCategoryUrlWithCustomStoreView" />
19+
</variation>
20+
</testCase>
21+
</config>

0 commit comments

Comments
 (0)