Skip to content

Commit 1a0c885

Browse files
committed
MAGETWO-63209: Fatal error on category page when changing display mode with flat category on
1 parent 68a4068 commit 1a0c885

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

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

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,51 +46,46 @@ class AssertCategoryPage extends AbstractConstraint
4646
* Assert that displayed category data on category page equals to passed from fixture.
4747
*
4848
* @param Category $category
49-
* @param Category $initialCategory
5049
* @param FixtureFactory $fixtureFactory
5150
* @param CatalogCategoryView $categoryView
5251
* @param BrowserInterface $browser
5352
* @return void
5453
*/
5554
public function processAssert(
5655
Category $category,
57-
Category $initialCategory,
5856
FixtureFactory $fixtureFactory,
5957
CatalogCategoryView $categoryView,
6058
BrowserInterface $browser
6159
) {
6260
$this->browser = $browser;
6361
$this->categoryViewPage = $categoryView;
64-
$categoryData = $this->prepareData($fixtureFactory, $category, $initialCategory);
62+
$this->prepareData($fixtureFactory, $category);
6563
$this->browser->open($this->getCategoryUrl($category));
66-
$this->assertGeneralInformation($category, $categoryData);
67-
$this->assertDisplaySetting($category, $categoryData);
64+
$this->assertGeneralInformation($category);
65+
$this->assertDisplaySetting($category);
6866
}
6967

7068
/**
7169
* Prepare comparison data.
7270
*
7371
* @param FixtureFactory $fixtureFactory
7472
* @param Category $category
75-
* @param Category $initialCategory
76-
* @return array
73+
* @return void
7774
*/
78-
protected function prepareData(FixtureFactory $fixtureFactory, Category $category, Category $initialCategory)
75+
protected function prepareData(FixtureFactory $fixtureFactory, Category $category)
7976
{
8077
$product = $fixtureFactory->createByCode(
8178
'catalogProductSimple',
8279
[
8380
'dataset' => 'default',
8481
'data' => [
8582
'category_ids' => [
86-
'category' => $initialCategory,
83+
'category' => $category,
8784
],
8885
]
8986
]
9087
);
9188
$product->persist();
92-
93-
return $category->getData();
9489
}
9590

9691
/**
@@ -120,10 +115,9 @@ protected function getCategoryUrl(Category $category)
120115
* Assert category general information.
121116
*
122117
* @param Category $category
123-
* @param array $categoryData
124118
* @return void
125119
*/
126-
protected function assertGeneralInformation(Category $category, array $categoryData)
120+
protected function assertGeneralInformation(Category $category)
127121
{
128122
$categoryUrl = $this->getCategoryUrl($category);
129123
\PHPUnit_Framework_Assert::assertEquals(
@@ -134,24 +128,24 @@ protected function assertGeneralInformation(Category $category, array $categoryD
134128
. "\nActual: " . $this->browser->getUrl()
135129
);
136130

137-
if (isset($categoryData['name'])) {
131+
if ($category->getName()) {
138132
$title = $this->categoryViewPage->getTitleBlock()->getTitle();
139133
\PHPUnit_Framework_Assert::assertEquals(
140-
$categoryData['name'],
134+
$category->getName(),
141135
$title,
142136
'Wrong page title.'
143-
. "\nExpected: " . $categoryData['name']
137+
. "\nExpected: " . $category->getName()
144138
. "\nActual: " . $title
145139
);
146140
}
147141

148-
if (isset($categoryData['description'])) {
142+
if ($category->getDescription()) {
149143
$description = $this->categoryViewPage->getViewBlock()->getDescription();
150144
\PHPUnit_Framework_Assert::assertEquals(
151-
$categoryData['description'],
145+
$category->getDescription(),
152146
$description,
153147
'Wrong category description.'
154-
. "\nExpected: " . $categoryData['description']
148+
. "\nExpected: " . $category->getDescription()
155149
. "\nActual: " . $description
156150
);
157151
}
@@ -161,15 +155,14 @@ protected function assertGeneralInformation(Category $category, array $categoryD
161155
* Assert category display settings.
162156
*
163157
* @param Category $category
164-
* @param array $categoryData
165158
* @return void
166159
*/
167-
protected function assertDisplaySetting(Category $category, array $categoryData)
160+
protected function assertDisplaySetting(Category $category)
168161
{
169162
if (
170-
isset($categoryData['landing_page'])
171-
&& isset($categoryData['display_mode'])
172-
&& in_array($categoryData['display_mode'], $this->visibleCmsBlockMode)
163+
$category->getLandingPage()
164+
&& $category->getDisplayMode()
165+
&& in_array($category->getDisplayMode(), $this->visibleCmsBlockMode)
173166
) {
174167
/** @var LandingPage $sourceLandingPage */
175168
$sourceLandingPage = $category->getDataFieldConfig('landing_page')['source'];
@@ -184,8 +177,8 @@ protected function assertDisplaySetting(Category $category, array $categoryData)
184177
. "\nActual: " . $pageContent
185178
);
186179
}
187-
if (isset($categoryData['default_sort_by'])) {
188-
$sortBy = strtolower($categoryData['default_sort_by']);
180+
if ($category->getDefaultSortBy()) {
181+
$sortBy = strtolower($category->getDefaultSortBy());
189182
$sortType = $this->categoryViewPage->getTopToolbar()->getSelectSortType();
190183
\PHPUnit_Framework_Assert::assertEquals(
191184
$sortBy,
@@ -196,9 +189,9 @@ protected function assertDisplaySetting(Category $category, array $categoryData)
196189
);
197190
}
198191

199-
if (isset($categoryData['available_sort_by'])) {
192+
if ($category->getAvailableSortBy()) {
200193
$availableSortType = array_filter(
201-
$categoryData['available_sort_by'],
194+
$category->getAvailableSortBy(),
202195
function (&$value) {
203196
return $value !== '-' && ucfirst($value);
204197
}

0 commit comments

Comments
 (0)