Skip to content

Commit 29c4909

Browse files
committed
MTO-121: [Variation] Move Anchored Category with Products (cron is ON, "Update on Save")
- Variations added
1 parent 6e0a786 commit 29c4909

File tree

9 files changed

+303
-16
lines changed

9 files changed

+303
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Tree extends Block
6565
*
6666
* @var string
6767
*/
68-
protected $categoryInTree = '//*[@class="x-tree-node-ct"]/li/div/a/span[contains(text(), "%s")]/..';
68+
protected $categoryInTree = '//ul//li//span[contains(text(), "%s")]';
6969

7070
/**
7171
* Get backend abstract block.

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

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,46 @@ class AssertCategoryBreadcrumbs extends AbstractConstraint
3434
* @param BrowserInterface $browser
3535
* @param Category $category
3636
* @param CatalogCategoryView $catalogCategoryView
37+
* @param Category|null $bottomChildCategory
38+
* @param Category|null $parentCategory
39+
* @param string|null $breadcrumbsSubCategory
3740
* @return void
3841
*/
3942
public function processAssert(
4043
BrowserInterface $browser,
4144
Category $category,
42-
CatalogCategoryView $catalogCategoryView
45+
CatalogCategoryView $catalogCategoryView,
46+
Category $bottomChildCategory = null,
47+
Category $parentCategory = null,
48+
$breadcrumbsSubCategory = ''
4349
) {
4450
$this->browser = $browser;
51+
52+
if ($bottomChildCategory !== null) {
53+
$category = $bottomChildCategory;
54+
}
4555
$this->openCategory($category);
4656

47-
$breadcrumbs = $this->getBreadcrumbs($category);
57+
$breadcrumbs = $this->getBreadcrumbs($category, $parentCategory);
4858
\PHPUnit_Framework_Assert::assertNotEmpty(
4959
$breadcrumbs,
5060
'No breadcrumbs on category \''. $category->getName() . '\' page.'
5161
);
5262
$pageBreadcrumbs = $catalogCategoryView->getBreadcrumbs()->getText();
53-
\PHPUnit_Framework_Assert::assertEquals(
54-
$breadcrumbs,
55-
$pageBreadcrumbs,
56-
'Wrong breadcrumbs of category page.'
57-
. "\nExpected: " . $breadcrumbs
58-
. "\nActual: " . $pageBreadcrumbs
59-
);
63+
if ($breadcrumbsSubCategory !== '') {
64+
\PHPUnit_Framework_Assert::assertTrue(
65+
(bool) strpos($breadcrumbs, str_replace(self::HOME_PAGE . ' ', '', $pageBreadcrumbs)),
66+
'Wrong breadcrumbs of category page.'
67+
);
68+
} else {
69+
\PHPUnit_Framework_Assert::assertEquals(
70+
$breadcrumbs,
71+
$pageBreadcrumbs,
72+
'Wrong breadcrumbs of category page.'
73+
. "\nExpected: " . $breadcrumbs
74+
. "\nActual: " . $pageBreadcrumbs
75+
);
76+
}
6077
}
6178

6279
/**
@@ -88,9 +105,10 @@ protected function openCategory(Category $category)
88105
* Prepare and return category breadcrumbs.
89106
*
90107
* @param Category $category
108+
* @param Category|null $parentCategory
91109
* @return string
92110
*/
93-
protected function getBreadcrumbs(Category $category)
111+
protected function getBreadcrumbs(Category $category, Category $parentCategory = null)
94112
{
95113
$breadcrumbs = [];
96114

@@ -102,6 +120,9 @@ protected function getBreadcrumbs(Category $category)
102120
$category = null;
103121
}
104122
}
123+
if ($parentCategory !== null) {
124+
$breadcrumbs[] = $parentCategory->getName();
125+
}
105126
$breadcrumbs[] = self::HOME_PAGE;
106127

107128
return implode(' ', array_reverse($breadcrumbs));
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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\Cms\Test\Page\CmsIndex;
10+
use Magento\Catalog\Test\Fixture\Category;
11+
use Magento\Mtf\Constraint\AbstractConstraint;
12+
13+
/**
14+
* Assert that relations of categories in navigation menu are correct.
15+
*/
16+
class AssertCategoryNavigationMenu extends AbstractConstraint
17+
{
18+
/**
19+
* Array for category tree.
20+
*
21+
* @var array
22+
*/
23+
private $categoryTree = [];
24+
25+
/**
26+
* Assert that relations of categories in navigation menu are correct.
27+
*
28+
* @param CmsIndex $cmsIndex
29+
* @param Category $bottomChildCategory
30+
* @param Category $childCategory
31+
* @param Category $parentCategory
32+
* @return void
33+
*/
34+
public function processAssert(
35+
CmsIndex $cmsIndex,
36+
Category $bottomChildCategory,
37+
Category $childCategory,
38+
Category $parentCategory
39+
) {
40+
41+
do {
42+
$name = $bottomChildCategory->getName();
43+
if ($name !== $childCategory->getName()) {
44+
$this->categoryTree[] = $name;
45+
$bottomChildCategory = $bottomChildCategory->getDataFieldConfig('parent_id')['source']
46+
->getParentCategory();
47+
} else {
48+
$this->categoryTree[] = $childCategory->getName();
49+
break;
50+
}
51+
} while ($name);
52+
53+
if ($parentCategory->getName() !== 'Default Category') {
54+
$this->categoryTree[] = $parentCategory->getName();
55+
}
56+
$cmsIndex->open();
57+
58+
foreach (array_reverse($this->categoryTree) as $category) {
59+
$cmsIndex->getTopMenu()->hoverCategoryByName($category);
60+
\PHPUnit_Framework_Assert::assertTrue(
61+
$cmsIndex->getTopMenu()->isCategoryVisible($category),
62+
'Category ' . $category . ' is not visible in top menu.'
63+
);
64+
}
65+
}
66+
67+
/**
68+
* Assert success message that relations of categories in navigation menu are correct.
69+
*
70+
* @return string
71+
*/
72+
public function toString()
73+
{
74+
return 'Topmenu contains correct tree of categories';
75+
}
76+
}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@
6565
<field name="include_in_menu" xsi:type="string">Yes</field>
6666
</dataset>
6767

68+
<dataset name="default_anchor_subcategory_with_anchored_parent">
69+
<field name="name" xsi:type="string">DefaultSubcategory%isolation%</field>
70+
<field name="url_key" xsi:type="string">default-subcategory-%isolation%</field>
71+
<field name="parent_id" xsi:type="array">
72+
<item name="dataset" xsi:type="string">default_anchor_subcategory</item>
73+
</field>
74+
<field name="is_active" xsi:type="string">Yes</field>
75+
<field name="is_anchor" xsi:type="string">Yes</field>
76+
<field name="include_in_menu" xsi:type="string">Yes</field>
77+
</dataset>
78+
6879
<dataset name="root_category">
6980
<field name="parent_id" xsi:type="string">%id%</field>
7081
<field name="name" xsi:type="string">RootCategory%isolation%</field>
@@ -134,5 +145,29 @@
134145
<item name="dataset" xsi:type="string">catalogProductSimple::default</item>
135146
</field>
136147
</dataset>
148+
149+
<dataset name="default_anchored_category">
150+
<field name="name" xsi:type="string">Category%isolation%</field>
151+
<field name="url_key" xsi:type="string">category%isolation%</field>
152+
<field name="is_active" xsi:type="string">Yes</field>
153+
<field name="include_in_menu" xsi:type="string">Yes</field>
154+
<field name="is_anchor" xsi:type="string">Yes</field>
155+
<field name="parent_id" xsi:type="array">
156+
<item name="dataset" xsi:type="string">default_category</item>
157+
</field>
158+
</dataset>
159+
160+
<dataset name="default_subcategory_with_anchored_parent">
161+
<field name="name" xsi:type="string">DefaultSubcategory%isolation%</field>
162+
<field name="url_key" xsi:type="string">default-subcategory-%isolation%</field>
163+
<field name="parent_id" xsi:type="array">
164+
<item name="dataset" xsi:type="string">default_anchored_category</item>
165+
</field>
166+
<field name="is_active" xsi:type="string">Yes</field>
167+
<field name="include_in_menu" xsi:type="string">Yes</field>
168+
<field name="category_products" xsi:type="array">
169+
<item name="dataset" xsi:type="string">catalogProductSimple::default</item>
170+
</field>
171+
</dataset>
137172
</repository>
138173
</config>

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* 6. Verify created category
2525
*
2626
* @group Category_Management
27-
* @ZephyrId MAGETWO-27319
27+
* @ZephyrId MAGETWO-27319, MAGETWO-21202
2828
*/
2929
class MoveCategoryEntityTest extends Injectable
3030
{
@@ -66,13 +66,21 @@ public function __inject(
6666
*
6767
* @param Category $childCategory
6868
* @param Category $parentCategory
69+
* @param array|null $moveLevel
6970
* @return array
7071
*/
71-
public function test(Category $childCategory, Category $parentCategory)
72+
public function test(Category $childCategory, Category $parentCategory, array $moveLevel = null)
7273
{
7374
// Preconditions:
7475
$parentCategory->persist();
7576
$childCategory->persist();
77+
$bottomChildCategory = $childCategory;
78+
79+
if ($moveLevel !== null) {
80+
for ($nestingIterator = 1; $nestingIterator < $moveLevel['child']; $nestingIterator++) {
81+
$childCategory = $childCategory->getDataFieldConfig('parent_id')['source']->getParentCategory();
82+
}
83+
}
7684

7785
// Steps:
7886
$this->catalogCategoryIndex->open();
@@ -86,7 +94,8 @@ public function test(Category $childCategory, Category $parentCategory)
8694
return [
8795
'category' => $childCategory,
8896
'parentCategory' => $parentCategory,
89-
'childCategory' => $childCategory
97+
'childCategory' => $childCategory,
98+
'bottomChildCategory' => $bottomChildCategory,
9099
];
91100
}
92101
}

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,27 @@
1414
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryMovedMessage" />
1515
<constraint name="Magento\UrlRewrite\Test\Constraint\AssertUrlRewriteCategoryInGrid" />
1616
</variation>
17+
<variation name="MoveCategoryEntityTestVariation2" summary="Move default subcategory with anchored parent to default subcategory" ticketId="MAGETWO-21202">
18+
<data name="issue" xsi:type="string">MAGETWO-65147: Category is not present in Layered navigation block when anchor is on</data>
19+
<data name="childCategory/dataset" xsi:type="string">default_subcategory_with_anchored_parent</data>
20+
<data name="parentCategory/dataset" xsi:type="string">default</data>
21+
<data name="moveLevel/child" xsi:type="string">2</data>
22+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryMovedMessage" />
23+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryNavigationMenu" />
24+
<constraint name="Magento\LayeredNavigation\Test\Constraint\AssertCategoryLayeredNavigation" />
25+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryBreadcrumbs" />
26+
</variation>
27+
<variation name="MoveCategoryEntityTestVariation3" summary="Move default anchored subcategory with anchored parent to default subcategory" ticketId="MAGETWO-21202">
28+
<data name="issue" xsi:type="string">MAGETWO-65147: Category is not present in Layered navigation block when anchor is on</data>
29+
<data name="childCategory/dataset" xsi:type="string">default_subcategory_with_anchored_parent</data>
30+
<data name="childCategory/data/parent_id/dataset" xsi:type="string">default_anchor_subcategory_with_anchored_parent</data>
31+
<data name="parentCategory/dataset" xsi:type="string">default_category</data>
32+
<data name="moveLevel/child" xsi:type="string">2</data>
33+
<data name="breadcrumbsSubCategory" xsi:type="string">Yes</data>
34+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryMovedMessage" />
35+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryNavigationMenu" />
36+
<constraint name="Magento\LayeredNavigation\Test\Constraint\AssertCategoryLayeredNavigation" />
37+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryBreadcrumbs" />
38+
</variation>
1739
</testCase>
1840
</config>

dev/tests/functional/tests/app/Magento/LayeredNavigation/Test/Block/Navigation.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Mtf\Block\Block;
1010
use Magento\Mtf\Client\Locator;
11+
use Magento\Catalog\Test\Fixture\Category;
1112

1213
/**
1314
* Catalog layered navigation view block.
@@ -49,6 +50,20 @@ class Navigation extends Block
4950
*/
5051
protected $expandFilterButton = '[data]';
5152

53+
/**
54+
* Locator for category name.
55+
*
56+
* @var string
57+
*/
58+
protected $categoryName = './/li[@class="item"]//a[contains(text(),"%s")]';
59+
60+
/**
61+
* Locator for element with product quantity.
62+
*
63+
* @var string
64+
*/
65+
protected $productQty = '/following-sibling::span[contains(text(), "%s")]';
66+
5267
/**
5368
* Remove all applied filters.
5469
*
@@ -78,7 +93,7 @@ public function getFilters()
7893
}
7994

8095
/**
81-
* Apply Layerd Navigation filter.
96+
* Apply Layered Navigation filter.
8297
*
8398
* @param string $filter
8499
* @param string $linkPattern
@@ -104,4 +119,19 @@ public function applyFilter($filter, $linkPattern)
104119
}
105120
throw new \Exception("Can't find {$filter} filter link by pattern: {$linkPattern}");
106121
}
122+
123+
/**
124+
* Check that category with product quantity can be displayed on layered navigation.
125+
*
126+
* @param Category $category
127+
* @param int $qty
128+
* @return bool
129+
*/
130+
public function isCategoryVisible(Category $category, $qty)
131+
{
132+
return $this->_rootElement->find(
133+
sprintf($this->categoryName, $category->getName()) . sprintf($this->productQty, $qty),
134+
Locator::SELECTOR_XPATH
135+
)->isVisible() ? true : false;
136+
}
107137
}

0 commit comments

Comments
 (0)