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\Detail; |
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\Detail\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 testHeader() |
35
|
|
|
{ |
36
|
|
|
$view = $this->object->getView(); |
37
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'd_prodid' => $this->getProductItem()->getId() ) ); |
38
|
|
|
$view->addHelper( 'param', $helper ); |
39
|
|
|
|
40
|
|
|
$tags = []; |
41
|
|
|
$expire = null; |
42
|
|
|
|
43
|
|
|
$this->object->setView( $this->object->data( $this->object->getView(), $tags, $expire ) ); |
44
|
|
|
$output = $this->object->header(); |
45
|
|
|
|
46
|
|
|
$this->assertStringContainsString( '<title>Cafe Noire Expresso | Aimeos</title>', $output ); |
47
|
|
|
$this->assertStringContainsString( '<script defer src="http://baseurl/catalog/stock/?st_pid', $output ); |
48
|
|
|
$this->assertEquals( '2098-01-01 00:00:00', $expire ); |
49
|
|
|
$this->assertEquals( 7, count( $tags ) ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testHeaderException() |
54
|
|
|
{ |
55
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Detail\Standard::class ) |
56
|
|
|
->setConstructorArgs( [$this->context] ) |
57
|
|
|
->setMethods( array( 'data' ) ) |
58
|
|
|
->getMock(); |
59
|
|
|
|
60
|
|
|
$view = $this->object->getView(); |
61
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['d_prodid' => -1] ) ); |
62
|
|
|
$mock->setView( $view ); |
63
|
|
|
|
64
|
|
|
$mock->expects( $this->once() )->method( 'data' ) |
65
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
66
|
|
|
|
67
|
|
|
$mock->header(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testBody() |
72
|
|
|
{ |
73
|
|
|
$view = $this->object->getView(); |
74
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'd_prodid' => $this->getProductItem()->getId() ) ); |
75
|
|
|
$view->addHelper( 'param', $helper ); |
76
|
|
|
|
77
|
|
|
$tags = []; |
78
|
|
|
$expire = null; |
79
|
|
|
|
80
|
|
|
$this->object->setView( $this->object->data( $view, $tags, $expire ) ); |
81
|
|
|
$output = $this->object->body(); |
82
|
|
|
|
83
|
|
|
$this->assertStringStartsWith( '<section class="aimeos catalog-detail"', $output ); |
84
|
|
|
$this->assertStringContainsString( '<div class="catalog-detail-basic', $output ); |
85
|
|
|
$this->assertStringContainsString( '<div class="catalog-detail-image', $output ); |
86
|
|
|
|
87
|
|
|
$this->assertStringContainsString( '<div class="catalog-social">', $output ); |
88
|
|
|
$this->assertRegExp( '/.*facebook.*/', $output ); |
89
|
|
|
|
90
|
|
|
$this->assertStringContainsString( '<div class="catalog-actions', $output ); |
91
|
|
|
$this->assertStringContainsString( 'actions-button-pin', $output ); |
92
|
|
|
$this->assertStringContainsString( 'actions-button-watch', $output ); |
93
|
|
|
$this->assertStringContainsString( 'actions-button-favorite', $output ); |
94
|
|
|
|
95
|
|
|
$this->assertStringContainsString( 'catalog-detail-additional', $output ); |
96
|
|
|
|
97
|
|
|
$this->assertStringContainsString( '<td class="name">size</td>', $output ); |
98
|
|
|
$this->assertStringContainsString( '<span class="attr-name">XS</span>', $output ); |
99
|
|
|
$this->assertStringContainsString( '<td class="name">package-height</td>', $output ); |
100
|
|
|
$this->assertStringContainsString( '<td class="value">10.0</td>', $output ); |
101
|
|
|
|
102
|
|
|
$this->assertStringContainsString( '<span class="media-name">Example image</span>', $output ); |
103
|
|
|
|
104
|
|
|
$this->assertStringContainsString( '<section class="catalog-detail-suggest', $output ); |
105
|
|
|
$this->assertRegExp( '/.*Cappuccino.*/', $output ); |
106
|
|
|
|
107
|
|
|
$this->assertStringContainsString( '<section class="catalog-detail-bought', $output ); |
108
|
|
|
$this->assertRegExp( '/.*Cappuccino.*/', $output ); |
109
|
|
|
|
110
|
|
|
$this->assertStringContainsString( '<div class="catalog-detail-service', $output ); |
111
|
|
|
$this->assertStringContainsString( '<div class="catalog-detail-supplier', $output ); |
112
|
|
|
|
113
|
|
|
$this->assertEquals( '2098-01-01 00:00:00', $expire ); |
114
|
|
|
$this->assertEquals( 7, count( $tags ) ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testBodyByName() |
119
|
|
|
{ |
120
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Detail\Standard( $this->context ); |
121
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
122
|
|
|
|
123
|
|
|
$view = $this->object->getView(); |
124
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'd_name' => 'Cafe-Noire-Expresso' ) ); |
125
|
|
|
$view->addHelper( 'param', $helper ); |
126
|
|
|
|
127
|
|
|
$this->object->setView( $this->object->data( $view ) ); |
128
|
|
|
$output = $this->object->body(); |
129
|
|
|
|
130
|
|
|
$this->assertStringContainsString( '<span class="value" itemprop="sku">CNE</span>', $output ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testBodyDefaultId() |
135
|
|
|
{ |
136
|
|
|
$context = clone $this->context; |
137
|
|
|
$context->getConfig()->set( 'client/html/catalog/detail/prodid-default', $this->getProductItem()->getId() ); |
138
|
|
|
|
139
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Detail\Standard( $context ); |
140
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
141
|
|
|
|
142
|
|
|
$view = $this->object->getView(); |
143
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, [] ); |
144
|
|
|
$view->addHelper( 'param', $helper ); |
145
|
|
|
|
146
|
|
|
$this->object->setView( $this->object->data( $view ) ); |
147
|
|
|
$output = $this->object->body(); |
148
|
|
|
|
149
|
|
|
$this->assertStringContainsString( '<span class="value" itemprop="sku">CNE</span>', $output ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
public function testBodyDefaultCode() |
154
|
|
|
{ |
155
|
|
|
$context = clone $this->context; |
156
|
|
|
$context->getConfig()->set( 'client/html/catalog/detail/prodcode-default', 'CNE' ); |
157
|
|
|
|
158
|
|
|
$this->object = new \Aimeos\Client\Html\Catalog\Detail\Standard( $context ); |
159
|
|
|
$this->object->setView( \TestHelperHtml::getView() ); |
160
|
|
|
|
161
|
|
|
$view = $this->object->getView(); |
162
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, [] ); |
163
|
|
|
$view->addHelper( 'param', $helper ); |
164
|
|
|
|
165
|
|
|
$this->object->setView( $this->object->data( $view ) ); |
166
|
|
|
$output = $this->object->body(); |
167
|
|
|
|
168
|
|
|
$this->assertStringContainsString( '<span class="value" itemprop="sku">CNE</span>', $output ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
public function testBodyCsrf() |
173
|
|
|
{ |
174
|
|
|
$view = $this->object->getView(); |
175
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['d_prodid' => -1] ) ); |
176
|
|
|
$view->detailProductItem = $this->getProductItem(); |
177
|
|
|
|
178
|
|
|
$output = $this->object->body( 1 ); |
179
|
|
|
$output = str_replace( '_csrf_value', '_csrf_new', $output ); |
180
|
|
|
|
181
|
|
|
$this->assertStringContainsString( '<input class="csrf-token" type="hidden" name="_csrf_token" value="_csrf_new"', $output ); |
182
|
|
|
|
183
|
|
|
$output = $this->object->modifyBody( $output, 1 ); |
184
|
|
|
|
185
|
|
|
$this->assertStringContainsString( '<input class="csrf-token" type="hidden" name="_csrf_token" value="_csrf_value"', $output ); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
|
189
|
|
|
public function testBodyAttributes() |
190
|
|
|
{ |
191
|
|
|
$product = $this->getProductItem( 'U:TESTP', array( 'attribute' ) ); |
192
|
|
|
|
193
|
|
|
$view = $this->object->getView(); |
194
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'd_prodid' => $product->getId() ) ); |
195
|
|
|
$view->addHelper( 'param', $helper ); |
196
|
|
|
|
197
|
|
|
$configAttr = $product->getRefItems( 'attribute', null, 'config' ); |
198
|
|
|
|
199
|
|
|
$this->assertGreaterThan( 0, count( $configAttr ) ); |
200
|
|
|
|
201
|
|
|
$output = $this->object->body(); |
202
|
|
|
$this->assertStringContainsString( '<div class="catalog-detail-basket-attribute', $output ); |
203
|
|
|
|
204
|
|
|
foreach( $configAttr as $id => $item ) { |
205
|
|
|
$this->assertRegexp( '#<option class="select-option".*value="' . $id . '">#smU', $output ); |
206
|
|
|
} |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
public function testBodySelection() |
211
|
|
|
{ |
212
|
|
|
$prodId = $this->getProductItem( 'U:TEST' )->getId(); |
213
|
|
|
|
214
|
|
|
$view = $this->object->getView(); |
215
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, array( 'd_prodid' => $prodId ) ); |
216
|
|
|
$view->addHelper( 'param', $helper ); |
217
|
|
|
|
218
|
|
|
$variantAttr1 = $this->getProductItem( 'U:TESTSUB02', array( 'attribute' ) )->getRefItems( 'attribute', null, 'variant' ); |
219
|
|
|
$variantAttr2 = $this->getProductItem( 'U:TESTSUB04', array( 'attribute' ) )->getRefItems( 'attribute', null, 'variant' ); |
220
|
|
|
|
221
|
|
|
$this->assertGreaterThan( 0, count( $variantAttr1 ) ); |
222
|
|
|
$this->assertGreaterThan( 0, count( $variantAttr2 ) ); |
223
|
|
|
|
224
|
|
|
$tags = []; |
225
|
|
|
$expire = null; |
226
|
|
|
|
227
|
|
|
$this->object->setView( $this->object->data( $view, $tags, $expire ) ); |
228
|
|
|
$output = $this->object->body( 1, $tags, $expire ); |
229
|
|
|
|
230
|
|
|
$this->assertStringContainsString( '<div class="catalog-detail-basket-selection', $output ); |
231
|
|
|
|
232
|
|
|
foreach( $variantAttr1 as $id => $item ) { |
233
|
|
|
$this->assertRegexp( '#<option class="select-option" value="' . $id . '">#', $output ); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
foreach( $variantAttr2 as $id => $item ) { |
237
|
|
|
$this->assertRegexp( '#<option class="select-option" value="' . $id . '">#', $output ); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
$this->assertEquals( null, $expire ); |
241
|
|
|
$this->assertEquals( 6, count( $tags ) ); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
|
245
|
|
|
public function testBodyClientHtmlException() |
246
|
|
|
{ |
247
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Detail\Standard::class ) |
248
|
|
|
->setConstructorArgs( [$this->context] ) |
249
|
|
|
->setMethods( array( 'data' ) ) |
250
|
|
|
->getMock(); |
251
|
|
|
|
252
|
|
|
$view = $this->object->getView(); |
253
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['d_prodid' => -1] ) ); |
254
|
|
|
$mock->setView( $view ); |
255
|
|
|
|
256
|
|
|
$mock->expects( $this->once() )->method( 'data' ) |
257
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception() ) ); |
258
|
|
|
|
259
|
|
|
$mock->body(); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
|
263
|
|
|
public function testBodyControllerFrontendException() |
264
|
|
|
{ |
265
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Detail\Standard::class ) |
266
|
|
|
->setConstructorArgs( [$this->context] ) |
267
|
|
|
->setMethods( array( 'data' ) ) |
268
|
|
|
->getMock(); |
269
|
|
|
|
270
|
|
|
$view = $this->object->getView(); |
271
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['d_prodid' => -1] ) ); |
272
|
|
|
$mock->setView( $view ); |
273
|
|
|
|
274
|
|
|
$mock->expects( $this->once() )->method( 'data' ) |
275
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception() ) ); |
276
|
|
|
|
277
|
|
|
$mock->body(); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
public function testBodyMShopException() |
282
|
|
|
{ |
283
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Detail\Standard::class ) |
284
|
|
|
->setConstructorArgs( [$this->context] ) |
285
|
|
|
->setMethods( array( 'data' ) ) |
286
|
|
|
->getMock(); |
287
|
|
|
|
288
|
|
|
$view = $this->object->getView(); |
289
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['d_prodid' => -1] ) ); |
290
|
|
|
$mock->setView( $view ); |
291
|
|
|
|
292
|
|
|
$mock->expects( $this->once() )->method( 'data' ) |
293
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
294
|
|
|
|
295
|
|
|
$mock->body(); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
|
299
|
|
|
public function testBodyException() |
300
|
|
|
{ |
301
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Detail\Standard::class ) |
302
|
|
|
->setConstructorArgs( [$this->context] ) |
303
|
|
|
->setMethods( array( 'data' ) ) |
304
|
|
|
->getMock(); |
305
|
|
|
|
306
|
|
|
$view = $this->object->getView(); |
307
|
|
|
$view->addHelper( 'param', new \Aimeos\MW\View\Helper\Param\Standard( $view, ['d_prodid' => -1] ) ); |
308
|
|
|
$mock->setView( $view ); |
309
|
|
|
|
310
|
|
|
$mock->expects( $this->once() )->method( 'data' ) |
311
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
312
|
|
|
|
313
|
|
|
$mock->body(); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
|
317
|
|
|
public function testGetSubClient() |
318
|
|
|
{ |
319
|
|
|
$client = $this->object->getSubClient( 'service', 'Standard' ); |
320
|
|
|
$this->assertInstanceOf( '\\Aimeos\\Client\\HTML\\Iface', $client ); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
|
324
|
|
|
public function testGetSubClientInvalid() |
325
|
|
|
{ |
326
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
327
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
|
331
|
|
|
public function testGetSubClientInvalidName() |
332
|
|
|
{ |
333
|
|
|
$this->expectException( '\\Aimeos\\Client\\Html\\Exception' ); |
334
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
|
338
|
|
|
public function testInit() |
339
|
|
|
{ |
340
|
|
|
$this->object->init(); |
341
|
|
|
|
342
|
|
|
$this->assertEmpty( $this->object->getView()->get( 'detailErrorList' ) ); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
|
346
|
|
|
public function testInitClientHtmlException() |
347
|
|
|
{ |
348
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Detail\Standard::class ) |
349
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
350
|
|
|
->setMethods( array( 'getClientParams' ) ) |
351
|
|
|
->getMock(); |
352
|
|
|
|
353
|
|
|
$mock->setView( \TestHelperHtml::getView() ); |
354
|
|
|
|
355
|
|
|
$mock->expects( $this->once() )->method( 'getClientParams' ) |
356
|
|
|
->will( $this->throwException( new \Aimeos\Client\Html\Exception() ) ); |
357
|
|
|
|
358
|
|
|
$mock->init(); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
|
362
|
|
|
public function testInitControllerFrontendException() |
363
|
|
|
{ |
364
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Detail\Standard::class ) |
365
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
366
|
|
|
->setMethods( array( 'getClientParams' ) ) |
367
|
|
|
->getMock(); |
368
|
|
|
|
369
|
|
|
$mock->setView( \TestHelperHtml::getView() ); |
370
|
|
|
|
371
|
|
|
$mock->expects( $this->once() )->method( 'getClientParams' ) |
372
|
|
|
->will( $this->throwException( new \Aimeos\Controller\Frontend\Exception() ) ); |
373
|
|
|
|
374
|
|
|
$mock->init(); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
|
378
|
|
|
public function testInitMShopException() |
379
|
|
|
{ |
380
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Detail\Standard::class ) |
381
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
382
|
|
|
->setMethods( array( 'getClientParams' ) ) |
383
|
|
|
->getMock(); |
384
|
|
|
|
385
|
|
|
$mock->setView( \TestHelperHtml::getView() ); |
386
|
|
|
|
387
|
|
|
$mock->expects( $this->once() )->method( 'getClientParams' ) |
388
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
389
|
|
|
|
390
|
|
|
$mock->init(); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
|
394
|
|
|
public function testInitException() |
395
|
|
|
{ |
396
|
|
|
$mock = $this->getMockBuilder( \Aimeos\Client\Html\Catalog\Detail\Standard::class ) |
397
|
|
|
->setConstructorArgs( array( $this->context, [] ) ) |
398
|
|
|
->setMethods( array( 'getClientParams' ) ) |
399
|
|
|
->getMock(); |
400
|
|
|
|
401
|
|
|
$mock->setView( \TestHelperHtml::getView() ); |
402
|
|
|
|
403
|
|
|
$mock->expects( $this->once() )->method( 'getClientParams' ) |
404
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
405
|
|
|
|
406
|
|
|
$mock->init(); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
|
410
|
|
|
protected function getProductItem( $code = 'CNE', $domains = [] ) |
411
|
|
|
{ |
412
|
|
|
$manager = \Aimeos\MShop\Product\Manager\Factory::create( $this->context ); |
413
|
|
|
$search = $manager->filter(); |
414
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', $code ) ); |
415
|
|
|
|
416
|
|
|
if( ( $item = $manager->search( $search, $domains )->first() ) === null ) { |
417
|
|
|
throw new \RuntimeException( sprintf( 'No product item with code "%1$s" found', $code ) ); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
return $item; |
421
|
|
|
} |
422
|
|
|
} |
423
|
|
|
|