|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
|
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
namespace Aimeos\Client\Html\Catalog\Lists; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private $object; |
|
16
|
|
|
private $context; |
|
17
|
|
|
private $view; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() : void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->view = \TestHelper::view(); |
|
23
|
|
|
$this->context = \TestHelper::context(); |
|
24
|
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $this->context ); |
|
26
|
|
|
$this->object->setView( $this->view ); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
protected function tearDown() : void |
|
31
|
|
|
{ |
|
32
|
|
|
unset( $this->object, $this->context, $this->view ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
public function testHeader() |
|
37
|
|
|
{ |
|
38
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, array( 'f_catid' => $this->getCatalogItem()->getId() ) ); |
|
39
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
40
|
|
|
|
|
41
|
|
|
$tags = []; |
|
42
|
|
|
$expire = null; |
|
43
|
|
|
|
|
44
|
|
|
$this->object->setView( $this->object->data( $this->view, $tags, $expire ) ); |
|
45
|
|
|
$output = $this->object->header(); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertStringContainsString( '<title>Kaffee | Aimeos</title>', $output ); |
|
48
|
|
|
$this->assertEquals( '2098-01-01 00:00:00', $expire ); |
|
49
|
|
|
$this->assertEquals( 6, count( $tags ) ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
public function testHeaderSearch() |
|
54
|
|
|
{ |
|
55
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, array( 'f_search' => '<b>Search result</b>' ) ); |
|
56
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
57
|
|
|
|
|
58
|
|
|
$tags = []; |
|
59
|
|
|
$expire = null; |
|
60
|
|
|
|
|
61
|
|
|
$this->object->setView( $this->object->data( $this->view, $tags, $expire ) ); |
|
62
|
|
|
$output = $this->object->header(); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertRegexp( '#<title>[^>]*Search result[^<]* | Aimeos</title>#', $output ); |
|
65
|
|
|
$this->assertEquals( null, $expire ); |
|
66
|
|
|
$this->assertEquals( 1, count( $tags ) ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
public function testBody() |
|
71
|
|
|
{ |
|
72
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, array( 'f_catid' => $this->getCatalogItem()->getId() ) ); |
|
73
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
74
|
|
|
|
|
75
|
|
|
$tags = []; |
|
76
|
|
|
$expire = null; |
|
77
|
|
|
|
|
78
|
|
|
$this->object->setView( $this->object->data( $this->view, $tags, $expire ) ); |
|
79
|
|
|
$output = $this->object->body(); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertStringContainsString( '<div class="catalog-list-head">', $output ); |
|
84
|
|
|
$this->assertRegExp( '#<h1>Kaffee</h1>#', $output ); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertEquals( '2098-01-01 00:00:00', $expire ); |
|
87
|
|
|
$this->assertEquals( 6, count( $tags ) ); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
public function testBodyPagination() |
|
92
|
|
|
{ |
|
93
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, ['l_size' => 2] ); |
|
94
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
95
|
|
|
|
|
96
|
|
|
$output = $this->object->body(); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
|
99
|
|
|
$this->assertStringContainsString( '<nav class="pagination">', $output ); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
public function testBodyDefaultAttribute() |
|
104
|
|
|
{ |
|
105
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
|
106
|
|
|
$attrId = $manager->find( 'xs', [], 'product', 'size' )->getId(); |
|
107
|
|
|
|
|
108
|
|
|
$context = clone $this->context; |
|
109
|
|
|
$context->config()->set( 'client/html/catalog/lists/attrid-default', $attrId ); |
|
110
|
|
|
|
|
111
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context ); |
|
112
|
|
|
$this->object->setView( \TestHelper::view() ); |
|
113
|
|
|
|
|
114
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, [] ); |
|
115
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
116
|
|
|
|
|
117
|
|
|
$output = $this->object->body(); |
|
118
|
|
|
|
|
119
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
|
120
|
|
|
$this->assertRegExp( '#.*Cafe Noire Cappuccino.*#smu', $output ); |
|
121
|
|
|
$this->assertRegExp( '#.*Cafe Noire Expresso.*#smu', $output ); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
public function testBodyNoDefaultCat() |
|
126
|
|
|
{ |
|
127
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, [] ); |
|
128
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
129
|
|
|
|
|
130
|
|
|
$output = $this->object->body(); |
|
131
|
|
|
|
|
132
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
|
133
|
|
|
$this->assertNotRegExp( '#.*U:TESTPSUB01.*#smu', $output ); |
|
134
|
|
|
$this->assertNotRegExp( '#.*U:TESTSUB03.*#smu', $output ); |
|
135
|
|
|
$this->assertNotRegExp( '#.*U:TESTSUB04.*#smu', $output ); |
|
136
|
|
|
$this->assertNotRegExp( '#.*U:TESTSUB05.*#smu', $output ); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
|
|
140
|
|
|
public function testBodyDefaultCat() |
|
141
|
|
|
{ |
|
142
|
|
|
$context = clone $this->context; |
|
143
|
|
|
$context->config()->set( 'client/html/catalog/lists/catid-default', $this->getCatalogItem()->getId() ); |
|
144
|
|
|
|
|
145
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context ); |
|
146
|
|
|
$this->object->setView( \TestHelper::view() ); |
|
147
|
|
|
|
|
148
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, [] ); |
|
149
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
150
|
|
|
|
|
151
|
|
|
$output = $this->object->body(); |
|
152
|
|
|
|
|
153
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
public function testBodyMultipleDefaultCat() |
|
158
|
|
|
{ |
|
159
|
|
|
$context = clone $this->context; |
|
160
|
|
|
$catid = $this->getCatalogItem()->getId(); |
|
161
|
|
|
$context->config()->set( 'client/html/catalog/lists/catid-default', array( $catid, $catid ) ); |
|
162
|
|
|
|
|
163
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context ); |
|
164
|
|
|
$this->object->setView( \TestHelper::view() ); |
|
165
|
|
|
|
|
166
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, [] ); |
|
167
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
168
|
|
|
|
|
169
|
|
|
$output = $this->object->body(); |
|
170
|
|
|
|
|
171
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
|
|
175
|
|
|
public function testBodyMultipleDefaultCatString() |
|
176
|
|
|
{ |
|
177
|
|
|
$context = clone $this->context; |
|
178
|
|
|
$catid = $this->getCatalogItem()->getId(); |
|
179
|
|
|
$context->config()->set( 'client/html/catalog/lists/catid-default', $catid . ',' . $catid ); |
|
180
|
|
|
|
|
181
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context ); |
|
182
|
|
|
$this->object->setView( \TestHelper::view() ); |
|
183
|
|
|
|
|
184
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, [] ); |
|
185
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
186
|
|
|
|
|
187
|
|
|
$output = $this->object->body(); |
|
188
|
|
|
|
|
189
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
public function testBodyCategoryLevels() |
|
194
|
|
|
{ |
|
195
|
|
|
$context = clone $this->context; |
|
196
|
|
|
$context->config()->set( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
|
197
|
|
|
|
|
198
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context ); |
|
199
|
|
|
$this->object->setView( \TestHelper::view() ); |
|
200
|
|
|
|
|
201
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, array( 'f_catid' => $this->getCatalogItem( 'root' )->getId() ) ); |
|
202
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
203
|
|
|
|
|
204
|
|
|
$output = $this->object->body(); |
|
205
|
|
|
|
|
206
|
|
|
$this->assertRegExp( '#.*Cafe Noire Cappuccino.*#smu', $output ); |
|
207
|
|
|
$this->assertRegExp( '#.*Cafe Noire Expresso.*#smu', $output ); |
|
208
|
|
|
$this->assertRegExp( '#.*Unittest: Bundle.*#smu', $output ); |
|
209
|
|
|
$this->assertRegExp( '#.*Unittest: Test priced Selection.*#smu', $output ); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
public function testBodySearchText() |
|
214
|
|
|
{ |
|
215
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, array( 'f_search' => '<b>Search result</b>' ) ); |
|
216
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
217
|
|
|
|
|
218
|
|
|
$output = $this->object->body(); |
|
219
|
|
|
|
|
220
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
|
221
|
|
|
$this->assertStringContainsString( '<b>Search result</b>', $output ); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
public function testBodySearchAttribute() |
|
226
|
|
|
{ |
|
227
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, array( 'f_attrid' => array( -1, -2 ) ) ); |
|
228
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
229
|
|
|
|
|
230
|
|
|
$output = $this->object->body(); |
|
231
|
|
|
|
|
232
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
|
|
236
|
|
|
public function testBodySearchSupplier() |
|
237
|
|
|
{ |
|
238
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, array( 'f_supid' => array( -1, -2 ) ) ); |
|
239
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
240
|
|
|
|
|
241
|
|
|
$output = $this->object->body(); |
|
242
|
|
|
|
|
243
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
|
|
247
|
|
|
public function testBodySearchPrice() |
|
248
|
|
|
{ |
|
249
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, array( 'f_price' => 20 ) ); |
|
250
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
251
|
|
|
|
|
252
|
|
|
$output = $this->object->body(); |
|
253
|
|
|
|
|
254
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
|
|
258
|
|
|
public function testBodySearchRadius() |
|
259
|
|
|
{ |
|
260
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, array( 'f_point' => [52.5, 10], 'f_dist' => 115 ) ); |
|
261
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
262
|
|
|
|
|
263
|
|
|
$output = $this->object->body(); |
|
264
|
|
|
|
|
265
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
|
|
269
|
|
|
public function testInit() |
|
270
|
|
|
{ |
|
271
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, array( 'l_type' => 'list' ) ); |
|
272
|
|
|
$this->view->addHelper( 'param', $helper ); |
|
273
|
|
|
|
|
274
|
|
|
$this->object->init(); |
|
275
|
|
|
|
|
276
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
protected function getCatalogItem( $code = 'cafe' ) |
|
281
|
|
|
{ |
|
282
|
|
|
$catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::create( $this->context ); |
|
283
|
|
|
$search = $catalogManager->filter(); |
|
284
|
|
|
$search->setConditions( $search->compare( '==', 'catalog.code', $code ) ); |
|
285
|
|
|
|
|
286
|
|
|
if( ( $item = $catalogManager->search( $search )->first() ) === null ) { |
|
287
|
|
|
throw new \RuntimeException( sprintf( 'No catalog item with code "%1$s" found', $code ) ); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
return $item; |
|
291
|
|
|
} |
|
292
|
|
|
} |
|
293
|
|
|
|