Skip to content

Commit 99c443c

Browse files
committed
Merge branch 'mto-121' into pr3
2 parents 981b180 + 904a067 commit 99c443c

File tree

8 files changed

+300
-9
lines changed

8 files changed

+300
-9
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+
private $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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ public function processAssert(
4242
CatalogCategoryView $catalogCategoryView
4343
) {
4444
$this->browser = $browser;
45+
4546
$this->openCategory($category);
4647

4748
$breadcrumbs = $this->getBreadcrumbs($category);
4849
\PHPUnit_Framework_Assert::assertNotEmpty(
4950
$breadcrumbs,
50-
'No breadcrumbs on category \''. $category->getName() . '\' page.'
51+
'No breadcrumbs on category \'' . $category->getName() . '\' page.'
5152
);
5253
$pageBreadcrumbs = $catalogCategoryView->getBreadcrumbs()->getText();
5354
\PHPUnit_Framework_Assert::assertEquals(
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
* Default category name.
20+
*/
21+
const DEFAULT_CATEGORY_NAME = 'Default Category';
22+
23+
/**
24+
* Assert that relations of categories in navigation menu are correct.
25+
*
26+
* @param CmsIndex $cmsIndex
27+
* @param Category $category
28+
* @return void
29+
*/
30+
public function processAssert(
31+
CmsIndex $cmsIndex,
32+
Category $category
33+
) {
34+
do {
35+
$categoriesNames[] = $category->getName();
36+
$category = $category->getDataFieldConfig('parent_id')['source']->getParentCategory();
37+
} while ($category->getName() != self::DEFAULT_CATEGORY_NAME);
38+
39+
$cmsIndex->open();
40+
41+
foreach (array_reverse($categoriesNames) as $category) {
42+
\PHPUnit_Framework_Assert::assertTrue(
43+
$cmsIndex->getTopMenu()->isCategoryVisible($category),
44+
'Category ' . $category . ' is not visible in top menu.'
45+
);
46+
$cmsIndex->getTopMenu()->hoverCategoryByName($category);
47+
}
48+
}
49+
50+
/**
51+
* Returns a string representation of the object.
52+
*
53+
* @return string
54+
*/
55+
public function toString()
56+
{
57+
return 'Topmenu contains correct tree of categories.';
58+
}
59+
}

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: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Catalog\Test\Fixture\Category;
1010
use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryEdit;
1111
use Magento\Catalog\Test\Page\Adminhtml\CatalogCategoryIndex;
12+
use Magento\Mtf\Fixture\FixtureFactory;
1213
use Magento\Mtf\TestCase\Injectable;
1314

1415
/**
@@ -24,7 +25,7 @@
2425
* 6. Verify created category
2526
*
2627
* @group Category_Management
27-
* @ZephyrId MAGETWO-27319
28+
* @ZephyrId MAGETWO-27319, MAGETWO-21202
2829
*/
2930
class MoveCategoryEntityTest extends Injectable
3031
{
@@ -46,33 +47,56 @@ class MoveCategoryEntityTest extends Injectable
4647
*/
4748
private $catalogCategoryEdit;
4849

50+
/**
51+
* Factory for fixtures.
52+
*
53+
* @var FixtureFactory
54+
*/
55+
private $fixtureFactory;
56+
4957
/**
5058
* Inject page end prepare default category.
5159
*
5260
* @param CatalogCategoryIndex $catalogCategoryIndex
5361
* @param CatalogCategoryEdit $catalogCategoryEdit
62+
* @param FixtureFactory $fixtureFactory
5463
* @return void
5564
*/
5665
public function __inject(
5766
CatalogCategoryIndex $catalogCategoryIndex,
58-
CatalogCategoryEdit $catalogCategoryEdit
67+
CatalogCategoryEdit $catalogCategoryEdit,
68+
FixtureFactory $fixtureFactory
5969
) {
6070
$this->catalogCategoryIndex = $catalogCategoryIndex;
6171
$this->catalogCategoryEdit = $catalogCategoryEdit;
72+
$this->fixtureFactory = $fixtureFactory;
6273
}
6374

6475
/**
6576
* Runs test.
6677
*
6778
* @param Category $childCategory
6879
* @param Category $parentCategory
80+
* @param int|null $moveLevel
6981
* @return array
7082
*/
71-
public function test(Category $childCategory, Category $parentCategory)
72-
{
83+
public function test(
84+
Category $childCategory,
85+
Category $parentCategory,
86+
$moveLevel = null
87+
) {
7388
// Preconditions:
7489
$parentCategory->persist();
7590
$childCategory->persist();
91+
$movedCategory = $childCategory;
92+
93+
if (!empty($moveLevel)) {
94+
for ($nestingIterator = 1; $nestingIterator < $moveLevel; $nestingIterator++) {
95+
$childCategory = $childCategory->getDataFieldConfig('parent_id')['source']->getParentCategory();
96+
}
97+
}
98+
99+
$newCategory = $this->getMovedCategoryTree($movedCategory, $parentCategory, $childCategory);
76100

77101
// Steps:
78102
$this->catalogCategoryIndex->open();
@@ -84,9 +108,39 @@ public function test(Category $childCategory, Category $parentCategory)
84108
$this->catalogCategoryEdit->getModalBlock()->acceptWarning();
85109

86110
return [
87-
'category' => $childCategory,
111+
'category' => $newCategory,
88112
'parentCategory' => $parentCategory,
89-
'childCategory' => $childCategory
113+
'childCategory' => $childCategory,
90114
];
91115
}
116+
117+
/**
118+
* Get moved category tree.
119+
*
120+
* @param Category $movedCategory
121+
* @param Category $childCategory
122+
* @param Category $parentCategory
123+
* @return Category
124+
*/
125+
public function getMovedCategoryTree(Category $movedCategory, Category $parentCategory, Category $childCategory)
126+
{
127+
$bottomChildCategory = [];
128+
while ($movedCategory->getName() != $childCategory->getName()) {
129+
$bottomChildCategory[] = $movedCategory->getData();
130+
$movedCategory = $movedCategory->getDataFieldConfig('parent_id')['source']->getParentCategory();
131+
}
132+
$bottomChildCategory[] = $movedCategory->getData();
133+
134+
$newCategory = $parentCategory;
135+
for ($i = count($bottomChildCategory) - 1; $i >= 0; $i--) {
136+
unset($bottomChildCategory[$i]['parent_id']);
137+
$bottomChildCategory[$i]['parent_id']['source'] = $newCategory;
138+
$newCategory = $this->fixtureFactory->createByCode(
139+
'category',
140+
['data' => $bottomChildCategory[$i]]
141+
);
142+
}
143+
144+
return $newCategory;
145+
}
92146
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,26 @@
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" xsi:type="number">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" xsi:type="number">2</data>
33+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryMovedMessage" />
34+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryNavigationMenu" />
35+
<constraint name="Magento\LayeredNavigation\Test\Constraint\AssertCategoryLayeredNavigation" />
36+
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryBreadcrumbs" />
37+
</variation>
1738
</testCase>
1839
</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+
private $categoryName = './/li[@class="item"]//a[contains(text(),"%s")]';
59+
60+
/**
61+
* Locator for element with product quantity.
62+
*
63+
* @var string
64+
*/
65+
private $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 string $name
127+
* @param int $qty
128+
* @return bool
129+
*/
130+
public function isCategoryVisible($name, $qty)
131+
{
132+
return $this->_rootElement->find(
133+
sprintf($this->categoryName, $name) . sprintf($this->productQty, $qty),
134+
Locator::SELECTOR_XPATH
135+
)->isVisible();
136+
}
107137
}

0 commit comments

Comments
 (0)