Skip to content

Commit 2d063f3

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

File tree

5 files changed

+60
-40
lines changed

5 files changed

+60
-40
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,15 @@ class AssertCategoryBreadcrumbs extends AbstractConstraint
3434
* @param BrowserInterface $browser
3535
* @param Category $category
3636
* @param CatalogCategoryView $catalogCategoryView
37-
* @param Category|null $newCategory
3837
* @return void
3938
*/
4039
public function processAssert(
4140
BrowserInterface $browser,
4241
Category $category,
43-
CatalogCategoryView $catalogCategoryView,
44-
Category $newCategory = null
42+
CatalogCategoryView $catalogCategoryView
4543
) {
4644
$this->browser = $browser;
4745

48-
if ($newCategory !== null) {
49-
$category = $newCategory;
50-
}
5146
$this->openCategory($category);
5247

5348
$breadcrumbs = $this->getBreadcrumbs($category);

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@ class AssertCategoryNavigationMenu extends AbstractConstraint
2424
* Assert that relations of categories in navigation menu are correct.
2525
*
2626
* @param CmsIndex $cmsIndex
27-
* @param Category $newCategory
27+
* @param Category $category
2828
* @return void
2929
*/
3030
public function processAssert(
3131
CmsIndex $cmsIndex,
32-
Category $newCategory
32+
Category $category
3333
) {
3434
do {
35-
$categoriesNames[] = $newCategory->getName();
36-
$newCategory = $newCategory->getDataFieldConfig('parent_id')['source']
37-
->getParentCategory();
38-
} while ($newCategory->getName() != self::DEFAULT_CATEGORY_NAME);
35+
$categoriesNames[] = $category->getName();
36+
$category = $category->getDataFieldConfig('parent_id')['source']->getParentCategory();
37+
} while ($category->getName() != self::DEFAULT_CATEGORY_NAME);
3938

4039
$cmsIndex->open();
4140

@@ -49,7 +48,7 @@ public function processAssert(
4948
}
5049

5150
/**
52-
* Assert success message that relations of categories in navigation menu are correct.
51+
* Returns a string representation of the object.
5352
*
5453
* @return string
5554
*/

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

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,34 +47,42 @@ class MoveCategoryEntityTest extends Injectable
4747
*/
4848
private $catalogCategoryEdit;
4949

50+
/**
51+
* Factory for fixtures.
52+
*
53+
* @var FixtureFactory
54+
*/
55+
private $fixtureFactory;
56+
5057
/**
5158
* Inject page end prepare default category.
5259
*
5360
* @param CatalogCategoryIndex $catalogCategoryIndex
5461
* @param CatalogCategoryEdit $catalogCategoryEdit
62+
* @param FixtureFactory $fixtureFactory
5563
* @return void
5664
*/
5765
public function __inject(
5866
CatalogCategoryIndex $catalogCategoryIndex,
59-
CatalogCategoryEdit $catalogCategoryEdit
67+
CatalogCategoryEdit $catalogCategoryEdit,
68+
FixtureFactory $fixtureFactory
6069
) {
6170
$this->catalogCategoryIndex = $catalogCategoryIndex;
6271
$this->catalogCategoryEdit = $catalogCategoryEdit;
72+
$this->fixtureFactory = $fixtureFactory;
6373
}
6474

6575
/**
6676
* Runs test.
6777
*
6878
* @param Category $childCategory
6979
* @param Category $parentCategory
70-
* @param FixtureFactory $fixtureFactory
71-
* @param string|null $moveLevel
80+
* @param int|null $moveLevel
7281
* @return array
7382
*/
7483
public function test(
7584
Category $childCategory,
7685
Category $parentCategory,
77-
FixtureFactory $fixtureFactory,
7886
$moveLevel = null
7987
) {
8088
// Preconditions:
@@ -88,21 +96,7 @@ public function test(
8896
}
8997
}
9098

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-
}
99+
$newCategory = $this->getMovedCategoryTree($movedCategory, $parentCategory, $childCategory);
106100

107101
// Steps:
108102
$this->catalogCategoryIndex->open();
@@ -113,11 +107,45 @@ public function test(
113107
);
114108
$this->catalogCategoryEdit->getModalBlock()->acceptWarning();
115109

110+
if ($newCategory != null) {
111+
$childCategory = $newCategory;
112+
}
113+
116114
return [
117115
'category' => $childCategory,
118116
'parentCategory' => $parentCategory,
119117
'childCategory' => $childCategory,
120118
'newCategory' => $newCategory,
121119
];
122120
}
121+
122+
/**
123+
* Get moved category tree.
124+
*
125+
* @param Category $movedCategory
126+
* @param Category $childCategory
127+
* @param Category $parentCategory
128+
* @return Category
129+
*/
130+
public function getMovedCategoryTree(Category $movedCategory, Category $parentCategory, Category $childCategory)
131+
{
132+
$bottomChildCategory = [];
133+
while ($movedCategory->getName() != $childCategory->getName()) {
134+
$bottomChildCategory[] = $movedCategory->getData();
135+
$movedCategory = $movedCategory->getDataFieldConfig('parent_id')['source']->getParentCategory();
136+
}
137+
$bottomChildCategory[] = $movedCategory->getData();
138+
139+
$newCategory = $parentCategory;
140+
for ($i = count($bottomChildCategory) - 1; $i >= 0; $i--) {
141+
unset($bottomChildCategory[$i]['parent_id']);
142+
$bottomChildCategory[$i]['parent_id']['source'] = $newCategory;
143+
$newCategory = $this->fixtureFactory->createByCode(
144+
'category',
145+
['data' => $bottomChildCategory[$i]]
146+
);
147+
}
148+
149+
return $newCategory;
150+
}
123151
}

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

Lines changed: 2 additions & 2 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" xsi:type="string">2</data>
21+
<data name="moveLevel" xsi:type="number">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,7 +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" xsi:type="string">2</data>
32+
<data name="moveLevel" xsi:type="number">2</data>
3333
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryMovedMessage" />
3434
<constraint name="Magento\Catalog\Test\Constraint\AssertCategoryNavigationMenu" />
3535
<constraint name="Magento\LayeredNavigation\Test\Constraint\AssertCategoryLayeredNavigation" />

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,24 @@ class AssertCategoryLayeredNavigation extends AbstractConstraint
2828
*
2929
* @param CatalogCategoryView $catalogCategoryView
3030
* @param Category $category
31-
* @param Category $newCategory
3231
* @param BrowserInterface $browser
3332
* @return void
3433
*/
3534
public function processAssert(
3635
CatalogCategoryView $catalogCategoryView,
3736
Category $category,
38-
Category $newCategory,
3937
BrowserInterface $browser
4038
) {
4139
$this->browser = $browser;
42-
$this->openCategory($category);
40+
$this->openCategory($category->getDataFieldConfig('parent_id')['source']->getParentCategory());
4341

4442
\PHPUnit_Framework_Assert::assertTrue(
45-
$catalogCategoryView->getLayeredNavigationBlock()->isCategoryVisible($newCategory->getName(), 1),
46-
'Category ' . $newCategory->getName() . ' is absent in Layered Navigation.'
43+
$catalogCategoryView->getLayeredNavigationBlock()->isCategoryVisible($category->getName(), 1),
44+
'Category ' . $category->getName() . ' is absent in Layered Navigation.'
4745
);
4846

4947
$productsOnCategoryPage = $catalogCategoryView->getListProductBlock()->getProductNames();
50-
$productsInCategory = $newCategory->getDataFieldConfig('category_products')['source']->getProducts();
48+
$productsInCategory = $category->getDataFieldConfig('category_products')['source']->getProducts();
5149
foreach ($productsInCategory as $product) {
5250
\PHPUnit_Framework_Assert::assertTrue(
5351
in_array($product->getName(), $productsOnCategoryPage),

0 commit comments

Comments
 (0)