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-2020 |
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
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelperHtml::getContext(); |
22
|
|
|
|
23
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $this->context ); |
24
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
protected function tearDown() : void |
29
|
|
|
{ |
30
|
|
|
unset( $this->object ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public function testGetHeader() |
35
|
|
|
{ |
36
|
|
|
$view = $this->object->getView(); |
37
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_catid' => $this->getCatalogItem()->getId() ) ); |
38
|
|
|
$view->addHelper( 'param', $helper ); |
39
|
|
|
|
40
|
|
|
$tags = []; |
41
|
|
|
$expire = null; |
42
|
|
|
|
43
|
|
|
$this->object->setView( $this->object->addData( $view, $tags, $expire ) ); |
44
|
|
|
$output = $this->object->getHeader(); |
45
|
|
|
|
46
|
|
|
$this->assertStringContainsString( '<title>Kaffee</title>', $output ); |
47
|
|
|
$this->assertEquals( '2098-01-01 00:00:00', $expire ); |
48
|
|
|
$this->assertEquals( 5, count( $tags ) ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function testGetHeaderSearch() |
53
|
|
|
{ |
54
|
|
|
$view = $this->object->getView(); |
55
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_search' => '<b>Search result</b>' ) ); |
56
|
|
|
$view->addHelper( 'param', $helper ); |
57
|
|
|
|
58
|
|
|
$tags = []; |
59
|
|
|
$expire = null; |
60
|
|
|
|
61
|
|
|
$this->object->setView( $this->object->addData( $view, $tags, $expire ) ); |
62
|
|
|
$output = $this->object->getHeader(); |
63
|
|
|
|
64
|
|
|
$this->assertRegexp( '#<title>[^>]*Search result[^<]*</title>#', $output ); |
65
|
|
|
$this->assertEquals( null, $expire ); |
66
|
|
|
$this->assertEquals( 1, count( $tags ) ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testGetHeaderException() |
71
|
|
|
{ |
72
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
73
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
74
|
|
|
->setMethods( array( 'addData' ) ) |
75
|
|
|
->getMock(); |
76
|
|
|
|
77
|
|
|
$object->expects( $this->once() )->method( 'addData' ) |
78
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
79
|
|
|
|
80
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
81
|
|
|
|
82
|
|
|
$this->assertEmpty( $object->getHeader() ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function testGetBody() |
87
|
|
|
{ |
88
|
|
|
$view = $this->object->getView(); |
89
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_catid' => $this->getCatalogItem()->getId() ) ); |
90
|
|
|
$view->addHelper( 'param', $helper ); |
91
|
|
|
|
92
|
|
|
$tags = []; |
93
|
|
|
$expire = null; |
94
|
|
|
|
95
|
|
|
$this->object->setView( $this->object->addData( $view, $tags, $expire ) ); |
96
|
|
|
$output = $this->object->getBody(); |
97
|
|
|
|
98
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
99
|
|
|
|
100
|
|
|
$this->assertStringContainsString( '<div class="catalog-list-head">', $output ); |
101
|
|
|
$this->assertRegExp( '#<h1>Kaffee</h1>#', $output ); |
102
|
|
|
|
103
|
|
|
$this->assertEquals( '2098-01-01 00:00:00', $expire ); |
104
|
|
|
$this->assertEquals( 5, count( $tags ) ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testGetBodyPagination() |
109
|
|
|
{ |
110
|
|
|
$view = $this->object->getView(); |
111
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, ['l_size' => 2] ); |
112
|
|
|
$view->addHelper( 'param', $helper ); |
113
|
|
|
|
114
|
|
|
$output = $this->object->getBody(); |
115
|
|
|
|
116
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
117
|
|
|
$this->assertStringContainsString( '<nav class="pagination">', $output ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
public function testGetBodyNoDefaultCat() |
122
|
|
|
{ |
123
|
|
|
$view = $this->object->getView(); |
124
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, [] ); |
125
|
|
|
$view->addHelper( 'param', $helper ); |
126
|
|
|
|
127
|
|
|
$output = $this->object->getBody(); |
128
|
|
|
|
129
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
130
|
|
|
$this->assertNotRegExp( '#.*U:TESTPSUB01.*#smu', $output ); |
131
|
|
|
$this->assertNotRegExp( '#.*U:TESTSUB03.*#smu', $output ); |
132
|
|
|
$this->assertNotRegExp( '#.*U:TESTSUB04.*#smu', $output ); |
133
|
|
|
$this->assertNotRegExp( '#.*U:TESTSUB05.*#smu', $output ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testGetBodyDefaultCat() |
138
|
|
|
{ |
139
|
|
|
$context = clone $this->context; |
140
|
|
|
$context->getConfig()->set( 'client/html/catalog/lists/catid-default', $this->getCatalogItem()->getId() ); |
141
|
|
|
|
142
|
|
|
$paths = \TestHelperHtml::getHtmlTemplatePaths(); |
143
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context, $paths ); |
|
|
|
|
144
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
145
|
|
|
|
146
|
|
|
$view = $this->object->getView(); |
147
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, [] ); |
148
|
|
|
$view->addHelper( 'param', $helper ); |
149
|
|
|
|
150
|
|
|
$output = $this->object->getBody(); |
151
|
|
|
|
152
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
public function testGetBodyMultipleDefaultCat() |
157
|
|
|
{ |
158
|
|
|
$context = clone $this->context; |
159
|
|
|
$catid = $this->getCatalogItem()->getId(); |
160
|
|
|
$context->getConfig()->set( 'client/html/catalog/lists/catid-default', array( $catid, $catid ) ); |
161
|
|
|
|
162
|
|
|
$paths = \TestHelperHtml::getHtmlTemplatePaths(); |
163
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context, $paths ); |
|
|
|
|
164
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
165
|
|
|
|
166
|
|
|
$view = $this->object->getView(); |
167
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, [] ); |
168
|
|
|
$view->addHelper( 'param', $helper ); |
169
|
|
|
|
170
|
|
|
$output = $this->object->getBody(); |
171
|
|
|
|
172
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
public function testGetBodyMultipleDefaultCatString() |
177
|
|
|
{ |
178
|
|
|
$context = clone $this->context; |
179
|
|
|
$catid = $this->getCatalogItem()->getId(); |
180
|
|
|
$context->getConfig()->set( 'client/html/catalog/lists/catid-default', $catid . ',' . $catid ); |
181
|
|
|
|
182
|
|
|
$paths = \TestHelperHtml::getHtmlTemplatePaths(); |
183
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context, $paths ); |
|
|
|
|
184
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
185
|
|
|
|
186
|
|
|
$view = $this->object->getView(); |
187
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, [] ); |
188
|
|
|
$view->addHelper( 'param', $helper ); |
189
|
|
|
|
190
|
|
|
$output = $this->object->getBody(); |
191
|
|
|
|
192
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list home categories coffee"', $output ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
public function testGetBodyCategoryLevels() |
197
|
|
|
{ |
198
|
|
|
$context = clone $this->context; |
199
|
|
|
$context->getConfig()->set( 'client/html/catalog/lists/levels', \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ); |
200
|
|
|
|
201
|
|
|
$paths = \TestHelperHtml::getHtmlTemplatePaths(); |
202
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Lists\Standard( $context, $paths ); |
|
|
|
|
203
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
204
|
|
|
|
205
|
|
|
$view = $this->object->getView(); |
206
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_catid' => $this->getCatalogItem( 'root' )->getId() ) ); |
207
|
|
|
$view->addHelper( 'param', $helper ); |
208
|
|
|
|
209
|
|
|
$output = $this->object->getBody(); |
210
|
|
|
|
211
|
|
|
$this->assertRegExp( '#.*Cafe Noire Cappuccino.*#smu', $output ); |
212
|
|
|
$this->assertRegExp( '#.*Cafe Noire Expresso.*#smu', $output ); |
213
|
|
|
$this->assertRegExp( '#.*Unittest: Bundle.*#smu', $output ); |
214
|
|
|
$this->assertRegExp( '#.*Unittest: Test priced Selection.*#smu', $output ); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
|
218
|
|
|
public function testGetBodySearchText() |
219
|
|
|
{ |
220
|
|
|
$view = $this->object->getView(); |
221
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_search' => '<b>Search result</b>' ) ); |
222
|
|
|
$view->addHelper( 'param', $helper ); |
223
|
|
|
|
224
|
|
|
$output = $this->object->getBody(); |
225
|
|
|
|
226
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
227
|
|
|
$this->assertStringContainsString( '<b>Search result</b>', $output ); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
|
231
|
|
|
public function testGetBodySearchAttribute() |
232
|
|
|
{ |
233
|
|
|
$view = $this->object->getView(); |
234
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_attrid' => array( -1, -2 ) ) ); |
235
|
|
|
$view->addHelper( 'param', $helper ); |
236
|
|
|
|
237
|
|
|
$output = $this->object->getBody(); |
238
|
|
|
|
239
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
|
243
|
|
|
public function testGetBodySearchSupplier() |
244
|
|
|
{ |
245
|
|
|
$view = $this->object->getView(); |
246
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'f_supid' => array( -1, -2 ) ) ); |
247
|
|
|
$view->addHelper( 'param', $helper ); |
248
|
|
|
|
249
|
|
|
$output = $this->object->getBody(); |
250
|
|
|
|
251
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-list', $output ); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
|
255
|
|
|
public function testGetBodyHtmlException() |
256
|
|
|
{ |
257
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
258
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
259
|
|
|
->setMethods( array( 'addData' ) ) |
260
|
|
|
->getMock(); |
261
|
|
|
|
262
|
|
|
$object->expects( $this->once() )->method( 'addData' ) |
263
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'test exception' ) ) ); |
264
|
|
|
|
265
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
266
|
|
|
|
267
|
|
|
$this->assertStringContainsString( 'test exception', $object->getBody() ); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
|
271
|
|
|
public function testGetBodyFrontendException() |
272
|
|
|
{ |
273
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
274
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
275
|
|
|
->setMethods( array( 'addData' ) ) |
276
|
|
|
->getMock(); |
277
|
|
|
|
278
|
|
|
$object->expects( $this->once() )->method( 'addData' ) |
279
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'test exception' ) ) ); |
280
|
|
|
|
281
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
282
|
|
|
|
283
|
|
|
$this->assertStringContainsString( 'test exception', $object->getBody() ); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
|
287
|
|
|
public function testGetBodyMShopException() |
288
|
|
|
{ |
289
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
290
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
291
|
|
|
->setMethods( array( 'addData' ) ) |
292
|
|
|
->getMock(); |
293
|
|
|
|
294
|
|
|
$object->expects( $this->once() )->method( 'addData' ) |
295
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception( 'test exception' ) ) ); |
296
|
|
|
|
297
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
298
|
|
|
|
299
|
|
|
$this->assertStringContainsString( 'test exception', $object->getBody() ); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
|
303
|
|
|
public function testGetBodyException() |
304
|
|
|
{ |
305
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
306
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
307
|
|
|
->setMethods( array( 'addData' ) ) |
308
|
|
|
->getMock(); |
309
|
|
|
|
310
|
|
|
$object->expects( $this->once() )->method( 'addData' ) |
311
|
|
|
->will( $this->throwException( new \RuntimeException( 'test exception' ) ) ); |
312
|
|
|
|
313
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
314
|
|
|
|
315
|
|
|
$this->assertStringContainsString( 'A non-recoverable error occured', $object->getBody() ); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
|
319
|
|
|
public function testGetSubClient() |
320
|
|
|
{ |
321
|
|
|
$client = $this->object->getSubClient( 'items', 'Standard' ); |
322
|
|
|
$this->assertInstanceOf( '\\Aimeos\\Client\\HTML\\Iface', $client ); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
|
326
|
|
|
public function testGetSubClientInvalid() |
327
|
|
|
{ |
328
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
329
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
|
333
|
|
|
public function testGetSubClientInvalidName() |
334
|
|
|
{ |
335
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
336
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
|
340
|
|
|
public function testProcess() |
341
|
|
|
{ |
342
|
|
|
$view = $this->object->getView(); |
343
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'l_type' => 'list' ) ); |
344
|
|
|
$view->addHelper( 'param', $helper ); |
345
|
|
|
|
346
|
|
|
$this->object->process(); |
347
|
|
|
|
348
|
|
|
$this->assertEmpty( $this->object->getView()->get( 'listErrorList' ) ); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
|
352
|
|
|
public function testProcessHtmlException() |
353
|
|
|
{ |
354
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
355
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
356
|
|
|
->setMethods( array( 'getClientParams' ) ) |
357
|
|
|
->getMock(); |
358
|
|
|
|
359
|
|
|
$object->expects( $this->once() )->method( 'getClientParams' ) |
360
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception( 'text exception' ) ) ); |
361
|
|
|
|
362
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
363
|
|
|
|
364
|
|
|
$object->process(); |
365
|
|
|
|
366
|
|
|
$this->assertIsArray( $object->getView()->listErrorList ); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
|
370
|
|
|
public function testProcessFrontendException() |
371
|
|
|
{ |
372
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
373
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
374
|
|
|
->setMethods( array( 'getClientParams' ) ) |
375
|
|
|
->getMock(); |
376
|
|
|
|
377
|
|
|
$object->expects( $this->once() )->method( 'getClientParams' ) |
378
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception( 'text exception' ) ) ); |
379
|
|
|
|
380
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
381
|
|
|
|
382
|
|
|
$object->process(); |
383
|
|
|
|
384
|
|
|
$this->assertIsArray( $object->getView()->listErrorList ); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
|
388
|
|
|
public function testProcessMShopException() |
389
|
|
|
{ |
390
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
391
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
392
|
|
|
->setMethods( array( 'getClientParams' ) ) |
393
|
|
|
->getMock(); |
394
|
|
|
|
395
|
|
|
$object->expects( $this->once() )->method( 'getClientParams' ) |
396
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception( 'text exception' ) ) ); |
397
|
|
|
|
398
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
399
|
|
|
|
400
|
|
|
$object->process(); |
401
|
|
|
|
402
|
|
|
$this->assertIsArray( $object->getView()->listErrorList ); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
|
406
|
|
|
public function testProcessException() |
407
|
|
|
{ |
408
|
|
|
$object = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Lists\Standard::class ) |
409
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
410
|
|
|
->setMethods( array( 'getClientParams' ) ) |
411
|
|
|
->getMock(); |
412
|
|
|
|
413
|
|
|
$object->expects( $this->once() )->method( 'getClientParams' ) |
414
|
|
|
->will( $this->throwException( new \RuntimeException( 'text exception' ) ) ); |
415
|
|
|
|
416
|
|
|
$object->setView( \TestHelperHtml::getView() ); |
417
|
|
|
|
418
|
|
|
$object->process(); |
419
|
|
|
|
420
|
|
|
$this->assertIsArray( $object->getView()->listErrorList ); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
|
424
|
|
|
protected function getCatalogItem( $code = 'cafe' ) |
425
|
|
|
{ |
426
|
|
|
$catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::create( $this->context ); |
427
|
|
|
$search = $catalogManager->filter(); |
428
|
|
|
$search->setConditions( $search->compare( '==', 'catalog.code', $code ) ); |
|
|
|
|
429
|
|
|
|
430
|
|
|
if( ( $item = $catalogManager->search( $search )->first() ) === null ) { |
431
|
|
|
throw new \RuntimeException( sprintf( 'No catalog item with code "%1$s" found', $code ) ); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
return $item; |
435
|
|
|
} |
436
|
|
|
} |
437
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.