Skip to content

Commit e287f39

Browse files
committed
MTO-121: [Variation] Move Anchored Category with Products (cron is ON, "Update on Save")
- Defects fixed
1 parent 8604cce commit e287f39

File tree

6 files changed

+61
-75
lines changed

6 files changed

+61
-75
lines changed

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

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,35 @@ 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
37+
* @param Category|null $newCategory
4038
* @return void
4139
*/
4240
public function processAssert(
4341
BrowserInterface $browser,
4442
Category $category,
4543
CatalogCategoryView $catalogCategoryView,
46-
Category $bottomChildCategory = null,
47-
Category $parentCategory = null,
48-
$breadcrumbsSubCategory = ''
44+
Category $newCategory = null
4945
) {
5046
$this->browser = $browser;
5147

52-
if ($bottomChildCategory !== null) {
53-
$category = $bottomChildCategory;
48+
if ($newCategory !== null) {
49+
$category = $newCategory;
5450
}
5551
$this->openCategory($category);
5652

57-
$breadcrumbs = $this->getBreadcrumbs($category, $parentCategory);
53+
$breadcrumbs = $this->getBreadcrumbs($category);
5854
\PHPUnit_Framework_Assert::assertNotEmpty(
5955
$breadcrumbs,
60-
'No breadcrumbs on category \''. $category->getName() . '\' page.'
56+
'No breadcrumbs on category \'' . $category->getName() . '\' page.'
6157
);
6258
$pageBreadcrumbs = $catalogCategoryView->getBreadcrumbs()->getText();
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-
}
59+
\PHPUnit_Framework_Assert::assertEquals(
60+
$breadcrumbs,
61+
$pageBreadcrumbs,
62+
'Wrong breadcrumbs of category page.'
63+
. "\nExpected: " . $breadcrumbs
64+
. "\nActual: " . $pageBreadcrumbs
65+
);
7766
}
7867

7968
/**
@@ -105,10 +94,9 @@ protected function openCategory(Category $category)
10594
* Prepare and return category breadcrumbs.
10695
*
10796
* @param Category $category
108-
* @param Category|null $parentCategory
10997
* @return string
11098
*/
111-
protected function getBreadcrumbs(Category $category, Category $parentCategory = null)
99+
protected function getBreadcrumbs(Category $category)
112100
{
113101
$breadcrumbs = [];
114102

@@ -120,9 +108,6 @@ protected function getBreadcrumbs(Category $category, Category $parentCategory =
120108
$category = null;
121109
}
122110
}
123-
if ($parentCategory !== null) {
124-
$breadcrumbs[] = $parentCategory->getName();
125-
}
126111
$breadcrumbs[] = self::HOME_PAGE;
127112

128113
return implode(' ', array_reverse($breadcrumbs));

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

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,51 +20,31 @@ class AssertCategoryNavigationMenu extends AbstractConstraint
2020
*/
2121
const DEFAULT_CATEGORY_NAME = 'Default Category';
2222

23-
/**
24-
* List of nested categories names.
25-
*
26-
* @var array
27-
*/
28-
private $nestedCategoriesList = [];
29-
3023
/**
3124
* Assert that relations of categories in navigation menu are correct.
3225
*
3326
* @param CmsIndex $cmsIndex
34-
* @param Category $bottomChildCategory
35-
* @param Category $childCategory
36-
* @param Category $parentCategory
27+
* @param Category $newCategory
3728
* @return void
3829
*/
3930
public function processAssert(
4031
CmsIndex $cmsIndex,
41-
Category $bottomChildCategory,
42-
Category $childCategory,
43-
Category $parentCategory
32+
Category $newCategory
4433
) {
4534
do {
46-
$name = $bottomChildCategory->getName();
47-
if ($name !== $childCategory->getName()) {
48-
$this->nestedCategoriesList[] = $name;
49-
$bottomChildCategory = $bottomChildCategory->getDataFieldConfig('parent_id')['source']
50-
->getParentCategory();
51-
} else {
52-
$this->nestedCategoriesList[] = $childCategory->getName();
53-
break;
54-
}
55-
} while ($name);
35+
$categoriesNames[] = $newCategory->getName();
36+
$newCategory = $newCategory->getDataFieldConfig('parent_id')['source']
37+
->getParentCategory();
38+
} while ($newCategory->getName() != self::DEFAULT_CATEGORY_NAME);
5639

57-
if ($parentCategory->getName() !== self::DEFAULT_CATEGORY_NAME) {
58-
$this->nestedCategoriesList[] = $parentCategory->getName();
59-
}
6040
$cmsIndex->open();
6141

62-
foreach (array_reverse($this->nestedCategoriesList) as $category) {
63-
$cmsIndex->getTopMenu()->hoverCategoryByName($category);
42+
foreach (array_reverse($categoriesNames) as $category) {
6443
\PHPUnit_Framework_Assert::assertTrue(
6544
$cmsIndex->getTopMenu()->isCategoryVisible($category),
6645
'Category ' . $category . ' is not visible in top menu.'
6746
);
47+
$cmsIndex->getTopMenu()->hoverCategoryByName($category);
6848
}
6949
}
7050

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

Lines changed: 28 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
/**
@@ -66,22 +67,43 @@ public function __inject(
6667
*
6768
* @param Category $childCategory
6869
* @param Category $parentCategory
69-
* @param array $moveLevel
70+
* @param FixtureFactory $fixtureFactory
71+
* @param string|null $moveLevel
7072
* @return array
7173
*/
72-
public function test(Category $childCategory, Category $parentCategory, array $moveLevel = [])
73-
{
74+
public function test(
75+
Category $childCategory,
76+
Category $parentCategory,
77+
FixtureFactory $fixtureFactory,
78+
$moveLevel = null
79+
) {
7480
// Preconditions:
7581
$parentCategory->persist();
7682
$childCategory->persist();
77-
$bottomChildCategory = $childCategory;
83+
$movedCategory = $childCategory;
7884

7985
if (!empty($moveLevel)) {
80-
for ($nestingIterator = 1; $nestingIterator < $moveLevel['child']; $nestingIterator++) {
86+
for ($nestingIterator = 1; $nestingIterator < $moveLevel; $nestingIterator++) {
8187
$childCategory = $childCategory->getDataFieldConfig('parent_id')['source']->getParentCategory();
8288
}
8389
}
8490

91+
while ($movedCategory->getName() != $childCategory->getName()) {
92+
$bottomChildCategory[] = $movedCategory->getData();
93+
$movedCategory = $movedCategory->getDataFieldConfig('parent_id')['source']->getParentCategory();
94+
}
95+
$bottomChildCategory[] = $movedCategory->getData();
96+
97+
$newCategory = $parentCategory;
98+
for ($i = count($bottomChildCategory) - 1; $i >= 0; $i--) {
99+
unset($bottomChildCategory[$i]['parent_id']);
100+
$bottomChildCategory[$i]['parent_id']['source'] = $newCategory;
101+
$newCategory = $fixtureFactory->createByCode(
102+
'category',
103+
['data' => $bottomChildCategory[$i]]
104+
);
105+
}
106+
85107
// Steps:
86108
$this->catalogCategoryIndex->open();
87109
$this->catalogCategoryIndex->getTreeCategories()->expandAllCategories();
@@ -95,7 +117,7 @@ public function test(Category $childCategory, Category $parentCategory, array $m
95117
'category' => $childCategory,
96118
'parentCategory' => $parentCategory,
97119
'childCategory' => $childCategory,
98-
'bottomChildCategory' => $bottomChildCategory,
120+
'newCategory' => $newCategory,
99121
];
100122
}
101123
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<data name="issue" xsi:type="string">MAGETWO-65147: Category is not present in Layered navigation block when anchor is on</data>
1919
<data name="childCategory/dataset" xsi:type="string">default_subcategory_with_anchored_parent</data>
2020
<data name="parentCategory/dataset" xsi:type="string">default</data>
21-
<data name="moveLevel/child" xsi:type="string">2</data>
21+
<data name="moveLevel" xsi:type="string">2</data>
2222
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryMovedMessage" />
2323
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryNavigationMenu" />
2424
<constraint name="Magento\LayeredNavigation\Test\Constraint\AssertCategoryLayeredNavigation" />
@@ -29,8 +29,7 @@
2929
<data name="childCategory/dataset" xsi:type="string">default_subcategory_with_anchored_parent</data>
3030
<data name="childCategory/data/parent_id/dataset" xsi:type="string">default_anchor_subcategory_with_anchored_parent</data>
3131
<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>
32+
<data name="moveLevel" xsi:type="string">2</data>
3433
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryMovedMessage" />
3534
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryNavigationMenu" />
3635
<constraint name="Magento\LayeredNavigation\Test\Constraint\AssertCategoryLayeredNavigation" />

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ public function applyFilter($filter, $linkPattern)
123123
/**
124124
* Check that category with product quantity can be displayed on layered navigation.
125125
*
126-
* @param Category $category
126+
* @param string $name
127127
* @param int $qty
128128
* @return bool
129129
*/
130-
public function isCategoryVisible(Category $category, $qty)
130+
public function isCategoryVisible($name, $qty)
131131
{
132132
return $this->_rootElement->find(
133-
sprintf($this->categoryName, $category->getName()) . sprintf($this->productQty, $qty),
133+
sprintf($this->categoryName, $name) . sprintf($this->productQty, $qty),
134134
Locator::SELECTOR_XPATH
135-
)->isVisible() ? true : false;
135+
)->isVisible();
136136
}
137137
}

dev/tests/functional/tests/app/Magento/LayeredNavigation/Test/Constraint/AssertCategoryLayeredNavigation.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ class AssertCategoryLayeredNavigation extends AbstractConstraint
2828
*
2929
* @param CatalogCategoryView $catalogCategoryView
3030
* @param Category $category
31-
* @param Category $bottomChildCategory
31+
* @param Category $newCategory
3232
* @param BrowserInterface $browser
3333
* @return void
3434
*/
3535
public function processAssert(
3636
CatalogCategoryView $catalogCategoryView,
3737
Category $category,
38-
Category $bottomChildCategory,
38+
Category $newCategory,
3939
BrowserInterface $browser
4040
) {
4141
$this->browser = $browser;
4242
$this->openCategory($category);
4343

4444
\PHPUnit_Framework_Assert::assertTrue(
45-
$catalogCategoryView->getLayeredNavigationBlock()->isCategoryVisible($bottomChildCategory, 1),
46-
'Category ' . $bottomChildCategory->getName() . ' is absent in Layered Navigation.'
45+
$catalogCategoryView->getLayeredNavigationBlock()->isCategoryVisible($newCategory->getName(), 1),
46+
'Category ' . $newCategory->getName() . ' is absent in Layered Navigation.'
4747
);
4848

4949
$productsOnCategoryPage = $catalogCategoryView->getListProductBlock()->getProductNames();
50-
$productsInCategory = $bottomChildCategory->getDataFieldConfig('category_products')['source']->getProducts();
50+
$productsInCategory = $newCategory->getDataFieldConfig('category_products')['source']->getProducts();
5151
foreach ($productsInCategory as $product) {
5252
\PHPUnit_Framework_Assert::assertTrue(
5353
in_array($product->getName(), $productsOnCategoryPage),

0 commit comments

Comments
 (0)