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-2021 |
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 = \TestHelperHtml::view(); |
23
|
|
|
$this->context = \TestHelperHtml::getContext(); |
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\MW\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( 5, count( $tags ) ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testHeaderSearch() |
54
|
|
|
{ |
55
|
|
|
$helper = new \Aimeos\MW\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 testHeaderException() |
71
|
|
|
{ |
72
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
73
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
74
|
|
|
->setMethods( array( 'data' ) ) |
75
|
|
|
->getMock(); |
76
|
|
|
|
77
|
|
|
$object->expects( $this->once() )->method( 'data' ) |
78
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
79
|
|
|
|
80
|
|
|
$object->setView( \TestHelperHtml::view() ); |
81
|
|
|
|
82
|
|
|
$this->assertEmpty( $object->header() ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function testBody() |
87
|
|
|
{ |
88
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, array( 'f_catid' => $this->getCatalogItem()->getId() ) ); |
89
|
|
|
$this->view->addHelper( 'param', $helper ); |
90
|
|
|
|
91
|
|
|
$tags = []; |
92
|
|
|
$expire = null; |
93
|
|
|
|
94
|
|
|
$this->object->setView( $this->object->data( $this->view, $tags, $expire ) ); |
95
|
|
|
$output = $this->object->body(); |
96
|
|
|
|
97
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
98
|
|
|
|
99
|
|
|
$this->assertStringContainsString( '<div class="catalog-list-head">', $output ); |
100
|
|
|
$this->assertRegExp( '#<h1>Kaffee</h1>#', $output ); |
101
|
|
|
|
102
|
|
|
$this->assertEquals( '2098-01-01 00:00:00', $expire ); |
103
|
|
|
$this->assertEquals( 5, count( $tags ) ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
public function testBodyPagination() |
108
|
|
|
{ |
109
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, ['l_size' => 2] ); |
110
|
|
|
$this->view->addHelper( 'param', $helper ); |
111
|
|
|
|
112
|
|
|
$output = $this->object->body(); |
113
|
|
|
|
114
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
115
|
|
|
$this->assertStringContainsString( '<nav class="pagination">', $output ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testBodyDefaultAttribute() |
120
|
|
|
{ |
121
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
122
|
|
|
$attrId = $manager->find( 'xs', [], 'product', 'size' )->getId(); |
123
|
|
|
|
124
|
|
|
$context = clone $this->context; |
125
|
|
|
$context->getConfig()->set( 'client/html/catalog/lists/attrid-default', $attrId ); |
126
|
|
|
|
127
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context ); |
128
|
|
|
$this->object->setView( \TestHelperHtml::view() ); |
129
|
|
|
|
130
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, [] ); |
131
|
|
|
$this->view->addHelper( 'param', $helper ); |
132
|
|
|
|
133
|
|
|
$output = $this->object->body(); |
134
|
|
|
|
135
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
136
|
|
|
$this->assertRegExp( '#.*Cafe Noire Cappuccino.*#smu', $output ); |
137
|
|
|
$this->assertRegExp( '#.*Cafe Noire Expresso.*#smu', $output ); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
public function testBodyNoDefaultCat() |
142
|
|
|
{ |
143
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, [] ); |
144
|
|
|
$this->view->addHelper( 'param', $helper ); |
145
|
|
|
|
146
|
|
|
$output = $this->object->body(); |
147
|
|
|
|
148
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
149
|
|
|
$this->assertNotRegExp( '#.*U:TESTPSUB01.*#smu', $output ); |
150
|
|
|
$this->assertNotRegExp( '#.*U:TESTSUB03.*#smu', $output ); |
151
|
|
|
$this->assertNotRegExp( '#.*U:TESTSUB04.*#smu', $output ); |
152
|
|
|
$this->assertNotRegExp( '#.*U:TESTSUB05.*#smu', $output ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
public function testBodyDefaultCat() |
157
|
|
|
{ |
158
|
|
|
$context = clone $this->context; |
159
|
|
|
$context->getConfig()->set( 'client/html/catalog/lists/catid-default', $this->getCatalogItem()->getId() ); |
160
|
|
|
|
161
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context ); |
162
|
|
|
$this->object->setView( \TestHelperHtml::view() ); |
163
|
|
|
|
164
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, [] ); |
165
|
|
|
$this->view->addHelper( 'param', $helper ); |
166
|
|
|
|
167
|
|
|
$output = $this->object->body(); |
168
|
|
|
|
169
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function testBodyMultipleDefaultCat() |
174
|
|
|
{ |
175
|
|
|
$context = clone $this->context; |
176
|
|
|
$catid = $this->getCatalogItem()->getId(); |
177
|
|
|
$context->getConfig()->set( 'client/html/catalog/lists/catid-default', array( $catid, $catid ) ); |
178
|
|
|
|
179
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context ); |
180
|
|
|
$this->object->setView( \TestHelperHtml::view() ); |
181
|
|
|
|
182
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, [] ); |
183
|
|
|
$this->view->addHelper( 'param', $helper ); |
184
|
|
|
|
185
|
|
|
$output = $this->object->body(); |
186
|
|
|
|
187
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
public function testBodyMultipleDefaultCatString() |
192
|
|
|
{ |
193
|
|
|
$context = clone $this->context; |
194
|
|
|
$catid = $this->getCatalogItem()->getId(); |
195
|
|
|
$context->getConfig()->set( 'client/html/catalog/lists/catid-default', $catid . ',' . $catid ); |
196
|
|
|
|
197
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context ); |
198
|
|
|
$this->object->setView( \TestHelperHtml::view() ); |
199
|
|
|
|
200
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, [] ); |
201
|
|
|
$this->view->addHelper( 'param', $helper ); |
202
|
|
|
|
203
|
|
|
$output = $this->object->body(); |
204
|
|
|
|
205
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
|
209
|
|
|
public function testBodyCategoryLevels() |
210
|
|
|
{ |
211
|
|
|
$context = clone $this->context; |
212
|
|
|
$context->getConfig()->set( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
213
|
|
|
|
214
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context ); |
215
|
|
|
$this->object->setView( \TestHelperHtml::view() ); |
216
|
|
|
|
217
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, array( 'f_catid' => $this->getCatalogItem( 'root' )->getId() ) ); |
218
|
|
|
$this->view->addHelper( 'param', $helper ); |
219
|
|
|
|
220
|
|
|
$output = $this->object->body(); |
221
|
|
|
|
222
|
|
|
$this->assertRegExp( '#.*Cafe Noire Cappuccino.*#smu', $output ); |
223
|
|
|
$this->assertRegExp( '#.*Cafe Noire Expresso.*#smu', $output ); |
224
|
|
|
$this->assertRegExp( '#.*Unittest: Bundle.*#smu', $output ); |
225
|
|
|
$this->assertRegExp( '#.*Unittest: Test priced Selection.*#smu', $output ); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
|
229
|
|
|
public function testBodySearchText() |
230
|
|
|
{ |
231
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, array( 'f_search' => '<b>Search result</b>' ) ); |
232
|
|
|
$this->view->addHelper( 'param', $helper ); |
233
|
|
|
|
234
|
|
|
$output = $this->object->body(); |
235
|
|
|
|
236
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
237
|
|
|
$this->assertStringContainsString( '<b>Search result</b>', $output ); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
|
241
|
|
|
public function testBodySearchAttribute() |
242
|
|
|
{ |
243
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, array( 'f_attrid' => array( -1, -2 ) ) ); |
244
|
|
|
$this->view->addHelper( 'param', $helper ); |
245
|
|
|
|
246
|
|
|
$output = $this->object->body(); |
247
|
|
|
|
248
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
public function testBodySearchSupplier() |
253
|
|
|
{ |
254
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, array( 'f_supid' => array( -1, -2 ) ) ); |
255
|
|
|
$this->view->addHelper( 'param', $helper ); |
256
|
|
|
|
257
|
|
|
$output = $this->object->body(); |
258
|
|
|
|
259
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
public function testBodyHtmlException() |
264
|
|
|
{ |
265
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
266
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
267
|
|
|
->setMethods( array( 'data' ) ) |
268
|
|
|
->getMock(); |
269
|
|
|
|
270
|
|
|
$object->expects( $this->once() )->method( 'data' ) |
271
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) ); |
272
|
|
|
|
273
|
|
|
$object->setView( \TestHelperHtml::view() ); |
274
|
|
|
|
275
|
|
|
$this->assertStringContainsString( 'test exception', $object->body() ); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
|
279
|
|
|
public function testBodyFrontendException() |
280
|
|
|
{ |
281
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
282
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
283
|
|
|
->setMethods( array( 'data' ) ) |
284
|
|
|
->getMock(); |
285
|
|
|
|
286
|
|
|
$object->expects( $this->once() )->method( 'data' ) |
287
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) ); |
288
|
|
|
|
289
|
|
|
$object->setView( \TestHelperHtml::view() ); |
290
|
|
|
|
291
|
|
|
$this->assertStringContainsString( 'test exception', $object->body() ); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
|
295
|
|
|
public function testBodyMShopException() |
296
|
|
|
{ |
297
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
298
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
299
|
|
|
->setMethods( array( 'data' ) ) |
300
|
|
|
->getMock(); |
301
|
|
|
|
302
|
|
|
$object->expects( $this->once() )->method( 'data' ) |
303
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
304
|
|
|
|
305
|
|
|
$object->setView( \TestHelperHtml::view() ); |
306
|
|
|
|
307
|
|
|
$this->assertStringContainsString( 'test exception', $object->body() ); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
|
311
|
|
|
public function testBodyException() |
312
|
|
|
{ |
313
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
314
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
315
|
|
|
->setMethods( array( 'data' ) ) |
316
|
|
|
->getMock(); |
317
|
|
|
|
318
|
|
|
$object->expects( $this->once() )->method( 'data' ) |
319
|
|
|
->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
320
|
|
|
|
321
|
|
|
$object->setView( \TestHelperHtml::view() ); |
322
|
|
|
|
323
|
|
|
$this->assertStringContainsString( 'A non-recoverable error occured', $object->body() ); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
|
327
|
|
|
public function testGetSubClient() |
328
|
|
|
{ |
329
|
|
|
$client = $this->object->getSubClient( 'items', 'Standard' ); |
330
|
|
|
$this->assertInstanceOf( '\\Aimeos\\Client\\HTML\\Iface', $client ); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
|
334
|
|
|
public function testGetSubClientInvalid() |
335
|
|
|
{ |
336
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
337
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
|
341
|
|
|
public function testGetSubClientInvalidName() |
342
|
|
|
{ |
343
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
344
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
|
348
|
|
|
public function testInit() |
349
|
|
|
{ |
350
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, array( 'l_type' => 'list' ) ); |
351
|
|
|
$this->view->addHelper( 'param', $helper ); |
352
|
|
|
|
353
|
|
|
$this->object->init(); |
354
|
|
|
|
355
|
|
|
$this->assertEmpty( $this->view->get( 'listErrorList' ) ); |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
|
359
|
|
|
public function testInitHtmlException() |
360
|
|
|
{ |
361
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
362
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
363
|
|
|
->setMethods( array( 'getClientParams' ) ) |
364
|
|
|
->getMock(); |
365
|
|
|
|
366
|
|
|
$object->expects( $this->once() )->method( 'getClientParams' ) |
367
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'text exception' ) ) ); |
368
|
|
|
|
369
|
|
|
$object->setView( $this->view ); |
370
|
|
|
|
371
|
|
|
$object->init(); |
372
|
|
|
|
373
|
|
|
$this->assertIsArray( $this->view->listErrorList ); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
|
377
|
|
|
public function testInitFrontendException() |
378
|
|
|
{ |
379
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
380
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
381
|
|
|
->setMethods( array( 'getClientParams' ) ) |
382
|
|
|
->getMock(); |
383
|
|
|
|
384
|
|
|
$object->expects( $this->once() )->method( 'getClientParams' ) |
385
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'text exception' ) ) ); |
386
|
|
|
|
387
|
|
|
$object->setView( $this->view ); |
388
|
|
|
|
389
|
|
|
$object->init(); |
390
|
|
|
|
391
|
|
|
$this->assertIsArray( $this->view->listErrorList ); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
|
395
|
|
|
public function testInitMShopException() |
396
|
|
|
{ |
397
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
398
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
399
|
|
|
->setMethods( array( 'getClientParams' ) ) |
400
|
|
|
->getMock(); |
401
|
|
|
|
402
|
|
|
$object->expects( $this->once() )->method( 'getClientParams' ) |
403
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception( 'text exception' ) ) ); |
404
|
|
|
|
405
|
|
|
$object->setView( $this->view ); |
406
|
|
|
|
407
|
|
|
$object->init(); |
408
|
|
|
|
409
|
|
|
$this->assertIsArray( $this->view->listErrorList ); |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
|
413
|
|
|
public function testInitException() |
414
|
|
|
{ |
415
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
416
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
417
|
|
|
->setMethods( array( 'getClientParams' ) ) |
418
|
|
|
->getMock(); |
419
|
|
|
|
420
|
|
|
$object->expects( $this->once() )->method( 'getClientParams' ) |
421
|
|
|
->will( $this->throwException( new \RuntimeException( 'text exception' ) ) ); |
422
|
|
|
|
423
|
|
|
$object->setView( $this->view ); |
424
|
|
|
|
425
|
|
|
$object->init(); |
426
|
|
|
|
427
|
|
|
$this->assertIsArray( $this->view->listErrorList ); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
|
431
|
|
|
protected function getCatalogItem( $code = 'cafe' ) |
432
|
|
|
{ |
433
|
|
|
$catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::create( $this->context ); |
434
|
|
|
$search = $catalogManager->filter(); |
435
|
|
|
$search->setConditions( $search->compare( '==', 'catalog.code', $code ) ); |
436
|
|
|
|
437
|
|
|
if( ( $item = $catalogManager->search( $search )->first() ) === null ) { |
438
|
|
|
throw new \RuntimeException( sprintf( 'No catalog item with code "%1$s" found', $code ) ); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
return $item; |
442
|
|
|
} |
443
|
|
|
} |
444
|
|
|
|