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-2025 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Client\Html\Basket\Standard; |
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
|
|
|
\Aimeos\Controller\Frontend::cache( true ); |
23
|
|
|
\Aimeos\MShop::cache( true ); |
24
|
|
|
|
25
|
|
|
$this->context = \TestHelper::context(); |
26
|
|
|
|
27
|
|
|
$this->view = \TestHelper::view(); |
28
|
|
|
$this->view->standardBasket = \Aimeos\MShop::create( $this->context, 'order' )->create(); |
29
|
|
|
|
30
|
|
|
$this->object = new \Aimeos\Client\Html\Basket\Standard\Standard( $this->context ); |
31
|
|
|
$this->object = new \Aimeos\Client\Html\Common\Decorator\Exceptions( $this->object, $this->context ); |
32
|
|
|
$this->object->setView( $this->view ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
protected function tearDown() : void |
37
|
|
|
{ |
38
|
|
|
\Aimeos\Controller\Frontend::create( $this->context, 'basket' )->clear(); |
39
|
|
|
\Aimeos\Controller\Frontend::cache( false ); |
40
|
|
|
\Aimeos\MShop::cache( false ); |
41
|
|
|
|
42
|
|
|
unset( $this->object, $this->context, $this->view ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testHeader() |
47
|
|
|
{ |
48
|
|
|
$tags = []; |
49
|
|
|
$expire = null; |
50
|
|
|
|
51
|
|
|
$this->object->setView( $this->object->data( $this->view, $tags, $expire ) ); |
52
|
|
|
$output = $this->object->header(); |
53
|
|
|
|
54
|
|
|
$this->assertStringContainsString( '<title>Basket | Aimeos</title>', $output ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function testBody() |
59
|
|
|
{ |
60
|
|
|
$output = $this->object->body(); |
61
|
|
|
|
62
|
|
|
$this->assertStringContainsString( '<div class="section aimeos basket-standard', $output ); |
63
|
|
|
$this->assertStringContainsString( '<div class="common-summary-detail', $output ); |
64
|
|
|
$this->assertStringContainsString( '<div class="basket-standard-coupon', $output ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testBodyAddSingle() |
69
|
|
|
{ |
70
|
|
|
$param = array( |
71
|
|
|
'b_action' => 'add', |
72
|
|
|
'b_prodid' => $this->getProductItem( 'CNE' )->getId(), |
73
|
|
|
'b_quantity' => 1, |
74
|
|
|
'b_stocktype' => 'default', |
75
|
|
|
); |
76
|
|
|
|
77
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
78
|
|
|
$this->view->addHelper( 'param', $helper ); |
79
|
|
|
|
80
|
|
|
$this->object->init(); |
81
|
|
|
$output = $this->object->body(); |
82
|
|
|
|
83
|
|
|
$this->assertMatchesRegularExpression( '#<div class="price.+19.00 .+</div>#smU', $output ); |
84
|
|
|
$this->assertMatchesRegularExpression( '#<div class="total.+<div class="price.+19.00 .+</div>#smU', $output ); |
85
|
|
|
$this->assertMatchesRegularExpression( '#<div class="tax.+<div class="price.+3.03 .+</div>#smU', $output ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testBodyAddMulti() |
90
|
|
|
{ |
91
|
|
|
$param = array( |
92
|
|
|
'b_action' => 'add', |
93
|
|
|
'b_prod' => array( |
94
|
|
|
array( |
95
|
|
|
'prodid' => $this->getProductItem( 'CNC' )->getId(), |
96
|
|
|
'quantity' => 1, |
97
|
|
|
'stocktype' => 'default', |
98
|
|
|
), |
99
|
|
|
array( |
100
|
|
|
'prodid' => $this->getProductItem( 'CNE' )->getId(), |
101
|
|
|
'quantity' => 1, |
102
|
|
|
'stocktype' => 'default', |
103
|
|
|
), |
104
|
|
|
), |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
108
|
|
|
$this->view->addHelper( 'param', $helper ); |
109
|
|
|
|
110
|
|
|
$this->object->init(); |
111
|
|
|
$output = $this->object->body(); |
112
|
|
|
|
113
|
|
|
$this->assertMatchesRegularExpression( '#<div class="price.+19.00 .+</div>#smU', $output ); |
114
|
|
|
$this->assertMatchesRegularExpression( '#<div class="price.+630.00 .+</div>#smU', $output ); |
115
|
|
|
$this->assertMatchesRegularExpression( '#<div class="total.+<div class="price.+649.00 .+</div>#smU', $output ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testBodyAddVariantAttribute() |
120
|
|
|
{ |
121
|
|
|
$attrManager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
122
|
|
|
|
123
|
|
|
$search = $attrManager->filter(); |
124
|
|
|
$expr = array( |
125
|
|
|
$search->compare( '==', 'attribute.domain', 'product' ), |
126
|
|
|
$search->or( array( |
127
|
|
|
$search->and( array( |
128
|
|
|
$search->compare( '==', 'attribute.code', '30' ), |
129
|
|
|
$search->compare( '==', 'attribute.type', 'length' ), |
130
|
|
|
) ), |
131
|
|
|
$search->and( array( |
132
|
|
|
$search->compare( '==', 'attribute.code', '30' ), |
133
|
|
|
$search->compare( '==', 'attribute.type', 'width' ), |
134
|
|
|
) ), |
135
|
|
|
) ), |
136
|
|
|
); |
137
|
|
|
$search->setConditions( $search->and( $expr ) ); |
138
|
|
|
$attributes = $attrManager->search( $search ); |
139
|
|
|
|
140
|
|
|
$param = array( |
141
|
|
|
'b_action' => 'add', |
142
|
|
|
'b_prodid' => $this->getProductItem( 'U:TEST' )->getId(), |
143
|
|
|
'b_quantity' => 2, |
144
|
|
|
'b_attrvarid' => $attributes->keys()->toArray(), |
145
|
|
|
); |
146
|
|
|
|
147
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
148
|
|
|
$this->view->addHelper( 'param', $helper ); |
149
|
|
|
|
150
|
|
|
$this->object->init(); |
151
|
|
|
$output = $this->object->body(); |
152
|
|
|
|
153
|
|
|
$this->assertMatchesRegularExpression( '#<li class="attr-item.*<span class="value">.*30.*</span>.*</li>.*<li class="attr-item.*<span class="value">.*30.*</span>.*</li>#smU', $output ); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
|
157
|
|
|
public function testBodyAddConfigAttribute() |
158
|
|
|
{ |
159
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
160
|
|
|
|
161
|
|
|
$search = $manager->filter(); |
162
|
|
|
$expr = array( |
163
|
|
|
$search->compare( '==', 'attribute.code', 'white' ), |
164
|
|
|
$search->compare( '==', 'attribute.domain', 'product' ), |
165
|
|
|
$search->compare( '==', 'attribute.type', 'color' ), |
166
|
|
|
); |
167
|
|
|
$search->setConditions( $search->and( $expr ) ); |
168
|
|
|
|
169
|
|
|
if( ( $attribute = $manager->search( $search )->first() ) === null ) { |
170
|
|
|
throw new \RuntimeException( 'No attribute' ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$param = array( |
174
|
|
|
'b_action' => 'add', |
175
|
|
|
'b_prodid' => $this->getProductItem( 'CNE' )->getId(), |
176
|
|
|
'b_quantity' => 2, |
177
|
|
|
'b_attrconfid' => ['id' => [0 => $attribute->getId()], 'qty' => [0 =>1]], |
178
|
|
|
'b_stocktype' => 'default', |
179
|
|
|
); |
180
|
|
|
|
181
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
182
|
|
|
$this->view->addHelper( 'param', $helper ); |
183
|
|
|
|
184
|
|
|
$this->object->init(); |
185
|
|
|
$output = $this->object->body(); |
186
|
|
|
|
187
|
|
|
$this->assertMatchesRegularExpression( '#<li class="attr-item.*<span class="value">.*weiß.*</span>.*</li>#smU', $output ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
public function testBodyAddCustomAttribute() |
192
|
|
|
{ |
193
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
194
|
|
|
|
195
|
|
|
$search = $manager->filter(); |
196
|
|
|
$expr = array( |
197
|
|
|
$search->compare( '==', 'attribute.code', 'custom' ), |
198
|
|
|
$search->compare( '==', 'attribute.domain', 'product' ), |
199
|
|
|
$search->compare( '==', 'attribute.type', 'date' ), |
200
|
|
|
); |
201
|
|
|
$search->setConditions( $search->and( $expr ) ); |
202
|
|
|
|
203
|
|
|
if( ( $attribute = $manager->search( $search )->first() ) === null ) { |
204
|
|
|
throw new \RuntimeException( 'No attribute' ); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
$param = array( |
208
|
|
|
'b_action' => 'add', |
209
|
|
|
'b_prodid' => $this->getProductItem( 'U:TESTP' )->getId(), |
210
|
|
|
'b_quantity' => 2, |
211
|
|
|
'b_attrcustid' => array( $attribute->getId() => '2000-01-01' ), |
212
|
|
|
'b_stocktype' => 'default', |
213
|
|
|
); |
214
|
|
|
|
215
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
216
|
|
|
$this->view->addHelper( 'param', $helper ); |
217
|
|
|
|
218
|
|
|
$this->object->init(); |
219
|
|
|
$output = $this->object->body(); |
220
|
|
|
|
221
|
|
|
$this->assertMatchesRegularExpression( '#<li class="attr-item.*<span class="value">.*2000-01-01.*</span>.*</li>#smU', $output ); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
public function testBodyEditSingle() |
226
|
|
|
{ |
227
|
|
|
$this->addProduct( 'CNE', 2, 'default' ); |
228
|
|
|
|
229
|
|
|
$param = array( |
230
|
|
|
'b_action' => 'edit', |
231
|
|
|
'b_position' => 0, |
232
|
|
|
'b_quantity' => 1, |
233
|
|
|
); |
234
|
|
|
|
235
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
236
|
|
|
$this->view->addHelper( 'param', $helper ); |
237
|
|
|
|
238
|
|
|
$this->object->init(); |
239
|
|
|
$output = $this->object->body(); |
240
|
|
|
|
241
|
|
|
$this->assertMatchesRegularExpression( '#<div class="price.+19.00 .+</div>#smU', $output ); |
242
|
|
|
$this->assertMatchesRegularExpression( '#<div class="total.+<div class="price.+19.00 .+</div>#smU', $output ); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
public function testBodyEditMulti() |
247
|
|
|
{ |
248
|
|
|
$this->addProduct( 'CNE', 1, 'default' ); |
249
|
|
|
$this->addProduct( 'CNC', 2, 'default' ); |
250
|
|
|
|
251
|
|
|
$param = array( |
252
|
|
|
'b_action' => 'edit', |
253
|
|
|
'b_prod' => array( |
254
|
|
|
array( |
255
|
|
|
'position' => 0, |
256
|
|
|
'quantity' => 2, |
257
|
|
|
), |
258
|
|
|
array( |
259
|
|
|
'position' => 1, |
260
|
|
|
'quantity' => 1, |
261
|
|
|
), |
262
|
|
|
), |
263
|
|
|
); |
264
|
|
|
|
265
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
266
|
|
|
$this->view->addHelper( 'param', $helper ); |
267
|
|
|
|
268
|
|
|
$this->object->init(); |
269
|
|
|
$output = $this->object->body(); |
270
|
|
|
|
271
|
|
|
$this->assertMatchesRegularExpression( '#<div class="price.+38.00 .+</div>#smU', $output ); |
272
|
|
|
$this->assertMatchesRegularExpression( '#<div class="price.+630.00 .+</div>#smU', $output ); |
273
|
|
|
$this->assertMatchesRegularExpression( '#<div class="total.+<div class="price.+668.00 .+</div>#smU', $output ); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
public function testBodyDeleteSingle() |
278
|
|
|
{ |
279
|
|
|
$this->addProduct( 'CNE', 2, 'default' ); |
280
|
|
|
$this->addProduct( 'CNC', 1, 'default' ); |
281
|
|
|
|
282
|
|
|
$param = array( |
283
|
|
|
'b_action' => 'delete', |
284
|
|
|
'b_position' => 1, |
285
|
|
|
); |
286
|
|
|
|
287
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
288
|
|
|
$this->view->addHelper( 'param', $helper ); |
289
|
|
|
|
290
|
|
|
$this->object->init(); |
291
|
|
|
$output = $this->object->body(); |
292
|
|
|
|
293
|
|
|
$this->assertMatchesRegularExpression( '#<div class="price.+38.00 .+</div>#smU', $output ); |
294
|
|
|
$this->assertMatchesRegularExpression( '#<div class="total.+<div class="price.+38.00 .+</div>#smU', $output ); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
|
298
|
|
|
public function testBodyDeleteMulti() |
299
|
|
|
{ |
300
|
|
|
$this->addProduct( 'CNE', 1, 'default' ); |
301
|
|
|
$this->addProduct( 'CNC', 1, 'default' ); |
302
|
|
|
|
303
|
|
|
$param = array( |
304
|
|
|
'b_action' => 'delete', |
305
|
|
|
'b_position' => array( 0, 1 ), |
306
|
|
|
); |
307
|
|
|
|
308
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
309
|
|
|
$this->view->addHelper( 'param', $helper ); |
310
|
|
|
|
311
|
|
|
$this->object->init(); |
312
|
|
|
$output = $this->object->body(); |
313
|
|
|
|
314
|
|
|
$this->assertMatchesRegularExpression( '#<div class="total.+<div class="price.+0.00 .+</div>#smU', $output ); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
|
318
|
|
|
public function testBodyDeleteInvalid() |
319
|
|
|
{ |
320
|
|
|
$param = array( |
321
|
|
|
'b_action' => 'delete', |
322
|
|
|
'b_position' => -1, |
323
|
|
|
); |
324
|
|
|
|
325
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
326
|
|
|
$this->view->addHelper( 'param', $helper ); |
327
|
|
|
|
328
|
|
|
$this->object->init(); |
329
|
|
|
|
330
|
|
|
$this->assertEquals( 1, count( $this->view->get( 'errors', [] ) ) ); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
|
334
|
|
|
public function testBodyAddCoupon() |
335
|
|
|
{ |
336
|
|
|
$controller = \Aimeos\Controller\Frontend::create( $this->context, 'basket' ); |
337
|
|
|
$controller->addProduct( $this->getProductItem( 'CNC' ), 1 ); |
338
|
|
|
|
339
|
|
|
|
340
|
|
|
$param = array( 'b_coupon' => '90AB' ); |
341
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
342
|
|
|
$this->view->addHelper( 'param', $helper ); |
343
|
|
|
|
344
|
|
|
$this->object->init(); |
345
|
|
|
|
346
|
|
|
$controller = \Aimeos\Controller\Frontend::create( $this->context, 'basket' ); |
347
|
|
|
$this->view->standardBasket = $controller->get(); |
348
|
|
|
$output = $this->object->body(); |
349
|
|
|
|
350
|
|
|
$this->assertStringContainsString( '<span class="coupon-code">90AB</span>', $output ); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
|
354
|
|
|
public function testBodyDeleteCoupon() |
355
|
|
|
{ |
356
|
|
|
$controller = \Aimeos\Controller\Frontend::create( $this->context, 'basket' ); |
357
|
|
|
$controller->addProduct( $this->getProductItem( 'CNC' ), 1 ); |
358
|
|
|
|
359
|
|
|
|
360
|
|
|
$param = array( 'b_coupon' => '90AB' ); |
361
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
362
|
|
|
$this->view->addHelper( 'param', $helper ); |
363
|
|
|
|
364
|
|
|
$this->object->init(); |
365
|
|
|
|
366
|
|
|
|
367
|
|
|
$param = array( 'b_action' => 'coupon-delete', 'b_coupon' => '90AB' ); |
368
|
|
|
|
369
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
370
|
|
|
$this->view->addHelper( 'param', $helper ); |
371
|
|
|
|
372
|
|
|
$this->object->init(); |
373
|
|
|
|
374
|
|
|
$controller = \Aimeos\Controller\Frontend::create( $this->context, 'basket' ); |
375
|
|
|
$this->view->standardBasket = $controller->get(); |
376
|
|
|
$output = $this->object->body(); |
377
|
|
|
|
378
|
|
|
$this->assertStringNotContainsString( '<span class="coupon-code">', $output ); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
|
382
|
|
|
public function testBodyOverwriteCoupon() |
383
|
|
|
{ |
384
|
|
|
$this->context->config()->set( 'client/html/basket/standard/coupon/overwrite', true ); |
385
|
|
|
|
386
|
|
|
$controller = \Aimeos\Controller\Frontend::create( $this->context, 'basket' ); |
387
|
|
|
$controller->addProduct( $this->getProductItem( 'CNC' ), 1 ); |
388
|
|
|
|
389
|
|
|
|
390
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, ['b_coupon' => '90AB'] ); |
391
|
|
|
$this->view->addHelper( 'param', $helper ); |
392
|
|
|
|
393
|
|
|
$this->object->init(); |
394
|
|
|
|
395
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, ['b_coupon' => 'OPQR'] ); |
396
|
|
|
$this->view->addHelper( 'param', $helper ); |
397
|
|
|
|
398
|
|
|
$this->object->init(); |
399
|
|
|
|
400
|
|
|
$controller = \Aimeos\Controller\Frontend::create( $this->context, 'basket' ); |
401
|
|
|
$this->view->standardBasket = $controller->get(); |
402
|
|
|
$output = $this->object->body(); |
403
|
|
|
|
404
|
|
|
$this->assertStringContainsString( 'OPQR', $output ); |
405
|
|
|
$this->assertStringNotContainsString( '90AB', $output ); |
406
|
|
|
} |
407
|
|
|
|
408
|
|
|
|
409
|
|
|
public function testGetSubClientInvalid() |
410
|
|
|
{ |
411
|
|
|
$this->expectException( \LogicException::class ); |
412
|
|
|
$this->object->getSubClient( 'invalid', 'invalid' ); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
|
416
|
|
|
public function testGetSubClientInvalidName() |
417
|
|
|
{ |
418
|
|
|
$this->expectException( \LogicException::class ); |
419
|
|
|
$this->object->getSubClient( '$$$', '$$$' ); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
|
423
|
|
|
/** |
424
|
|
|
* @param string $code |
425
|
|
|
* @param integer $quantity |
426
|
|
|
* @param string $stockType |
427
|
|
|
*/ |
428
|
|
|
protected function addProduct( $code, $quantity, $stockType ) |
429
|
|
|
{ |
430
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
431
|
|
|
$search = $manager->filter(); |
432
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', $code ) ); |
433
|
|
|
|
434
|
|
|
if( ( $item = $manager->search( $search )->first() ) === null ) { |
435
|
|
|
throw new \RuntimeException( sprintf( 'No product item with code "%1$s" found', $code ) ); |
436
|
|
|
} |
437
|
|
|
|
438
|
|
|
$param = array( |
439
|
|
|
'b_action' => 'add', |
440
|
|
|
'b_prodid' => $item->getId(), |
441
|
|
|
'b_quantity' => $quantity, |
442
|
|
|
'b_stocktype' => $stockType, |
443
|
|
|
); |
444
|
|
|
|
445
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
446
|
|
|
$this->view->addHelper( 'param', $helper ); |
447
|
|
|
|
448
|
|
|
$this->object->init(); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
|
452
|
|
|
/** |
453
|
|
|
* @param string $code |
454
|
|
|
*/ |
455
|
|
|
protected function getProductItem( $code ) |
456
|
|
|
{ |
457
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'product' ); |
458
|
|
|
$search = $manager->filter(); |
459
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', $code ) ); |
460
|
|
|
|
461
|
|
|
if( ( $item = $manager->search( $search, ['price'] )->first() ) === null ) { |
462
|
|
|
throw new \RuntimeException( sprintf( 'No product item with code "%1$s" found', $code ) ); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
return $item; |
466
|
|
|
} |
467
|
|
|
} |
468
|
|
|
|