@@ -22,11 +22,30 @@ class AssertCategoryPage extends AbstractConstraint
22
22
const SEVERITY = 'low ' ;
23
23
/* end tags */
24
24
25
+ /**
26
+ * CMS Block display mode
27
+ *
28
+ * @var array
29
+ */
25
30
protected $ visibleCmsBlockMode = [
26
31
'Static block only ' ,
27
32
'Static block and products '
28
33
];
29
34
35
+ /**
36
+ * Category view page
37
+ *
38
+ * @var CatalogCategoryView
39
+ */
40
+ protected $ categoryViewPage ;
41
+
42
+ /**
43
+ * Browser instance
44
+ *
45
+ * @var Browser
46
+ */
47
+ protected $ browser ;
48
+
30
49
/**
31
50
* Assert that displayed category data on category page equals to passed from fixture.
32
51
*
@@ -44,6 +63,22 @@ public function processAssert(
44
63
CatalogCategoryView $ categoryView ,
45
64
Browser $ browser
46
65
) {
66
+ $ this ->browser = $ browser ;
67
+ $ this ->categoryViewPage = $ categoryView ;
68
+ $ categoryData = $ this ->prepareData ($ fixtureFactory , $ category , $ initialCategory );
69
+ $ this ->browser ->open ($ this ->getCategoryUrl ($ category ));
70
+ $ this ->assertGeneralInformation ($ category , $ categoryData );
71
+ $ this ->assertDisplaySetting ($ category , $ categoryData );
72
+ }
73
+
74
+ /**
75
+ * @param FixtureFactory $fixtureFactory
76
+ * @param Category $category
77
+ * @param Category $initialCategory
78
+ * @return array
79
+ */
80
+ protected function prepareData (FixtureFactory $ fixtureFactory , Category $ category , Category $ initialCategory )
81
+ {
47
82
$ product = $ fixtureFactory ->createByCode (
48
83
'catalogProductSimple ' ,
49
84
[
@@ -55,25 +90,45 @@ public function processAssert(
55
90
]
56
91
]
57
92
);
58
- $ categoryData = array_merge ($ initialCategory ->getData (), $ category ->getData ());
93
+ $ product ->persist ();
94
+
95
+ return array_merge ($ initialCategory ->getData (), $ category ->getData ());
96
+ }
97
+
98
+ /**
99
+ * Get category url to open
100
+ *
101
+ * @param Category $category
102
+ * @return string
103
+ */
104
+ protected function getCategoryUrl (Category $ category )
105
+ {
59
106
$ categoryUrlKey = $ category ->hasData ('url_key ' )
60
107
? strtolower ($ category ->getUrlKey ())
61
108
: trim (strtolower (preg_replace ('#[^0-9a-z%]+#i ' , '- ' , $ category ->getName ())), '- ' );
62
- $ categoryUrl = $ _ENV ['app_frontend_url ' ] . $ categoryUrlKey . '.html ' ;
63
-
64
- $ product ->persist ();
65
- $ browser ->open ($ categoryUrl );
109
+ return $ _ENV ['app_frontend_url ' ] . $ categoryUrlKey . '.html ' ;
110
+ }
66
111
112
+ /**
113
+ * Assert category general information
114
+ *
115
+ * @param Category $category
116
+ * @param array $categoryData
117
+ * @return void
118
+ */
119
+ protected function assertGeneralInformation (Category $ category , array $ categoryData )
120
+ {
121
+ $ categoryUrl = $ this ->getCategoryUrl ($ category );
67
122
\PHPUnit_Framework_Assert::assertEquals (
68
123
$ categoryUrl ,
69
- $ browser ->getUrl (),
124
+ $ this -> browser ->getUrl (),
70
125
'Wrong page URL. '
71
126
. "\nExpected: " . $ categoryUrl
72
- . "\nActual: " . $ browser ->getUrl ()
127
+ . "\nActual: " . $ this -> browser ->getUrl ()
73
128
);
74
129
75
130
if (isset ($ categoryData ['name ' ])) {
76
- $ title = $ categoryView ->getTitleBlock ()->getTitle ();
131
+ $ title = $ this -> categoryViewPage ->getTitleBlock ()->getTitle ();
77
132
\PHPUnit_Framework_Assert::assertEquals (
78
133
$ categoryData ['name ' ],
79
134
$ title ,
@@ -84,7 +139,7 @@ public function processAssert(
84
139
}
85
140
86
141
if (isset ($ categoryData ['description ' ])) {
87
- $ description = $ categoryView ->getViewBlock ()->getDescription ();
142
+ $ description = $ this -> categoryViewPage ->getViewBlock ()->getDescription ();
88
143
\PHPUnit_Framework_Assert::assertEquals (
89
144
$ categoryData ['description ' ],
90
145
$ description ,
@@ -93,7 +148,17 @@ public function processAssert(
93
148
. "\nActual: " . $ description
94
149
);
95
150
}
151
+ }
96
152
153
+ /**
154
+ * Assert category display settings
155
+ *
156
+ * @param Category $category
157
+ * @param array $categoryData
158
+ * @return void
159
+ */
160
+ protected function assertDisplaySetting (Category $ category , array $ categoryData )
161
+ {
97
162
if (
98
163
isset ($ categoryData ['landing_page ' ])
99
164
&& isset ($ categoryData ['display_mode ' ])
@@ -102,7 +167,7 @@ public function processAssert(
102
167
/** @var LandingPage $sourceLandingPage */
103
168
$ sourceLandingPage = $ category ->getDataFieldConfig ('landing_page ' )['source ' ];
104
169
$ fixtureContent = $ sourceLandingPage ->getCmsBlock ()->getContent ();
105
- $ pageContent = $ categoryView ->getViewBlock ()->getContent ();
170
+ $ pageContent = $ this -> categoryViewPage ->getViewBlock ()->getContent ();
106
171
107
172
\PHPUnit_Framework_Assert::assertEquals (
108
173
$ fixtureContent ,
@@ -112,10 +177,9 @@ public function processAssert(
112
177
. "\nActual: " . $ pageContent
113
178
);
114
179
}
115
-
116
180
if (isset ($ categoryData ['default_sort_by ' ])) {
117
181
$ sortBy = strtolower ($ categoryData ['default_sort_by ' ]);
118
- $ sortType = $ categoryView ->getTopToolbar ()->getSelectSortType ();
182
+ $ sortType = $ this -> categoryViewPage ->getTopToolbar ()->getSelectSortType ();
119
183
\PHPUnit_Framework_Assert::assertEquals (
120
184
$ sortBy ,
121
185
$ sortType ,
@@ -134,7 +198,7 @@ function (&$value) {
134
198
);
135
199
if ($ availableSortType ) {
136
200
$ availableSortType = array_values ($ availableSortType );
137
- $ availableSortTypeOnPage = $ categoryView ->getTopToolbar ()->getSortType ();
201
+ $ availableSortTypeOnPage = $ this -> categoryViewPage ->getTopToolbar ()->getSortType ();
138
202
\PHPUnit_Framework_Assert::assertEquals (
139
203
$ availableSortType ,
140
204
$ availableSortTypeOnPage ,
0 commit comments