Skip to content

Commit 4f9fd3b

Browse files
committed
MAGETWO-63209: Fatal error on category page when changing display mode with flat category on
1 parent d54837d commit 4f9fd3b

File tree

5 files changed

+83
-39
lines changed

5 files changed

+83
-39
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2016 Magento. All rights reserved.
3+
* Copyright © 2017 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

@@ -26,7 +26,8 @@ class AssertCategoryForm extends AbstractAssertForm
2626
* @var array
2727
*/
2828
protected $skippedFixtureFields = [
29-
'parent_id'
29+
'parent_id',
30+
'id'
3031
];
3132

3233
/**

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

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ class AssertCategoryPage extends AbstractConstraint
4242
*/
4343
protected $browser;
4444

45-
/**
46-
* Category with updated data.
47-
*
48-
* @var Category
49-
*/
50-
protected $finalCategory;
51-
5245
/**
5346
* Assert that displayed category data on category page equals to passed from fixture.
5447
*
@@ -69,9 +62,9 @@ public function processAssert(
6962
$this->browser = $browser;
7063
$this->categoryViewPage = $categoryView;
7164
$categoryData = $this->prepareData($fixtureFactory, $category, $initialCategory);
72-
$this->browser->open($this->getCategoryUrl($this->finalCategory));
73-
$this->assertGeneralInformation($this->finalCategory, $categoryData);
74-
$this->assertDisplaySetting($this->finalCategory, $categoryData);
65+
$this->browser->open($this->getCategoryUrl($category));
66+
$this->assertGeneralInformation($category, $categoryData);
67+
$this->assertDisplaySetting($category, $categoryData);
7568
}
7669

7770
/**
@@ -97,30 +90,7 @@ protected function prepareData(FixtureFactory $fixtureFactory, Category $categor
9790
);
9891
$product->persist();
9992

100-
$parentCategory = null;
101-
$cmsBlock = null;
102-
foreach ([$initialCategory, $category] as $item) {
103-
$parentSource = $item->getDataFieldConfig('parent_id')['source'];
104-
if (is_a($parentSource, Category\ParentId::class) && $parentSource->getParentCategory()) {
105-
$parentCategory = $parentSource->getParentCategory();
106-
}
107-
108-
$cmsBlockSource = $category->getDataFieldConfig('landing_page')['source'];
109-
if (is_a($cmsBlockSource, Category\LandingPage::class) && $cmsBlockSource->getCmsBlock()) {
110-
$cmsBlock = $cmsBlockSource->getCmsBlock();
111-
}
112-
}
113-
114-
$data = array_merge(
115-
$initialCategory->getData(),
116-
$category->getData(),
117-
['parent_id' => ['source' => $parentCategory]],
118-
['landing_page' => ['source' => $cmsBlock]]
119-
);
120-
121-
$this->finalCategory = $fixtureFactory->create(Category::class, ['data' => $data]);
122-
123-
return array_merge($initialCategory->getData(), $category->getData());
93+
return $category->getData();
12494
}
12595

12696
/**

dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Category/StoreId.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2016 Magento. All rights reserved.
3+
* Copyright © 2017 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66

@@ -41,6 +41,9 @@ public function __construct(FixtureFactory $fixtureFactory, array $params, array
4141
}
4242
$this->store = $store;
4343
$this->data = $store->getGroupId() . '/' . $store->getName();
44+
} else if (isset($data['source']) && $data['source'] instanceof Store) {
45+
$this->store = $data['source'];
46+
$this->data = $this->store->getGroupId() . '/' . $this->store->getName();
4447
} else {
4548
$this->data = $data;
4649
}

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

Lines changed: 57 additions & 2 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
use Magento\Mtf\TestStep\TestStepFactory;
1415

@@ -65,25 +66,36 @@ class UpdateCategoryEntityTest extends Injectable
6566
*/
6667
protected $testStepFactory;
6768

69+
/**
70+
* Fixture create factory.
71+
*
72+
* @var FixtureFactory
73+
*/
74+
protected $fixtureFactory;
75+
6876
/**
6977
* Inject page end prepare default category.
7078
*
7179
* @param Category $initialCategory
7280
* @param CatalogCategoryIndex $catalogCategoryIndex
7381
* @param CatalogCategoryEdit $catalogCategoryEdit
7482
* @param TestStepFactory $testStepFactory
83+
* @param FixtureFactory $fixtureFactory
7584
* @return array
7685
*/
7786
public function __inject(
7887
Category $initialCategory,
7988
CatalogCategoryIndex $catalogCategoryIndex,
8089
CatalogCategoryEdit $catalogCategoryEdit,
81-
TestStepFactory $testStepFactory
90+
TestStepFactory $testStepFactory,
91+
FixtureFactory $fixtureFactory
8292
) {
8393
$this->catalogCategoryIndex = $catalogCategoryIndex;
8494
$this->catalogCategoryEdit = $catalogCategoryEdit;
8595
$this->testStepFactory = $testStepFactory;
96+
$this->fixtureFactory = $fixtureFactory;
8697
$initialCategory->persist();
98+
8799
return ['initialCategory' => $initialCategory];
88100
}
89101

@@ -93,7 +105,7 @@ public function __inject(
93105
* @param Category $category
94106
* @param Category $initialCategory
95107
* @param string $configData
96-
* @return void
108+
* @return array
97109
*/
98110
public function test(Category $category, Category $initialCategory, $configData = null)
99111
{
@@ -110,6 +122,49 @@ public function test(Category $category, Category $initialCategory, $configData
110122
$this->catalogCategoryIndex->getTreeCategories()->selectCategory($initialCategory);
111123
$this->catalogCategoryEdit->getEditForm()->fill($category);
112124
$this->catalogCategoryEdit->getFormPageActions()->save();
125+
126+
return ['category' => $this->prepareCategory($category, $initialCategory)];
127+
}
128+
129+
/**
130+
* Prepare category fixture with updated data.
131+
*
132+
* @param Category $category
133+
* @param Category $initialCategory
134+
* @return Category
135+
*/
136+
private function prepareCategory(Category $category, Category $initialCategory)
137+
{
138+
$parentCategory = null;
139+
$cmsBlock = null;
140+
$store = null;
141+
142+
foreach ([$initialCategory, $category] as $item) {
143+
$parentSource = $item->getDataFieldConfig('parent_id')['source'];
144+
if (is_a($parentSource, Category\ParentId::class) && $parentSource->getParentCategory()) {
145+
$parentCategory = $parentSource->getParentCategory();
146+
}
147+
148+
$cmsBlockSource = $category->getDataFieldConfig('landing_page')['source'];
149+
if (is_a($cmsBlockSource, Category\LandingPage::class) && $cmsBlockSource->getCmsBlock()) {
150+
$cmsBlock = $cmsBlockSource->getCmsBlock();
151+
}
152+
153+
$storeSource = $category->getDataFieldConfig('store_id')['source'];
154+
if (is_a($storeSource, Category\StoreId::class) && $storeSource->getStore()) {
155+
$store = $storeSource->getStore();
156+
}
157+
}
158+
159+
$data = array_merge(
160+
$initialCategory->getData(),
161+
$category->getData(),
162+
['parent_id' => ['source' => $parentCategory]],
163+
['landing_page' => ['source' => $cmsBlock]],
164+
['store_id' => ['source' => $store]]
165+
);
166+
167+
return $this->fixtureFactory->create(Category::class, ['data' => $data]);
113168
}
114169

115170
/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2017 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="../../../../../vendor/magento/mtf/Magento/Mtf/TestRunner/etc/testRunner.xsd">
10+
<rule scope="testsuite">
11+
<allow>
12+
<class value="Magento\Catalog\Test\TestCase\Category\UpdateCategoryEntityTest"/>
13+
</allow>
14+
</rule>
15+
</config>

0 commit comments

Comments
 (0)