1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2025 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Product\Item; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $values; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->values = array( |
22
|
|
|
'product.id' => 1, |
23
|
|
|
'product.siteid' => '1.33.99.', |
24
|
|
|
'product.type' => 'test', |
25
|
|
|
'product.status' => 1, |
26
|
|
|
'product.code' => 'TEST', |
27
|
|
|
'product.dataset' => 'Shirts', |
28
|
|
|
'product.url' => 'test_product', |
29
|
|
|
'product.label' => 'testproduct', |
30
|
|
|
'product.config' => array( 'css-class' => 'test' ), |
31
|
|
|
'product.datestart' => null, |
32
|
|
|
'product.dateend' => null, |
33
|
|
|
'product.scale' => '', |
34
|
|
|
'product.ctime' => '2011-01-19 17:04:32', |
35
|
|
|
'product.mtime' => '2011-01-19 18:04:32', |
36
|
|
|
'product.editor' => 'unitTestUser', |
37
|
|
|
'product.target' => 'testtarget', |
38
|
|
|
'product.rating' => '4.80', |
39
|
|
|
'product.ratings' => 5, |
40
|
|
|
'product.instock' => 1, |
41
|
|
|
'product.boost' => 1.5, |
42
|
|
|
'additional' => 'value', |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$propItems = array( |
46
|
|
|
2 => new \Aimeos\MShop\Common\Item\Property\Standard( 'product.property.', array( |
47
|
|
|
'product.property.id' => 2, |
48
|
|
|
'product.property.parentid' => 1, |
49
|
|
|
'product.property.type' => 'proptest', |
50
|
|
|
'product.property.languageid' => 'de', |
51
|
|
|
'.languageid' => 'de', |
52
|
|
|
) ), |
53
|
|
|
3 => new \Aimeos\MShop\Common\Item\Property\Standard( 'product.property.', array( |
54
|
|
|
'product.property.id' => 3, |
55
|
|
|
'product.property.parentid' => 1, |
56
|
|
|
'product.property.type' => 'proptype', |
57
|
|
|
'product.property.languageid' => 'de', |
58
|
|
|
'.languageid' => 'fr', |
59
|
|
|
) ), |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$this->object = new \Aimeos\MShop\Product\Item\Standard( 'product.', $this->values + ['.propitems' => $propItems] ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
protected function tearDown() : void |
67
|
|
|
{ |
68
|
|
|
unset( $this->object, $this->values ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function testDynamicMethods() |
73
|
|
|
{ |
74
|
|
|
\Aimeos\MShop\Product\Item\Standard::macro( 'test', function( $name ) { |
75
|
|
|
return $this->bdata[$name]; |
|
|
|
|
76
|
|
|
} ); |
77
|
|
|
|
78
|
|
|
$this->assertInstanceOf( '\Closure', \Aimeos\MShop\Product\Item\Standard::macro( 'test' ) ); |
79
|
|
|
|
80
|
|
|
$object = new \Aimeos\MShop\Product\Item\Standard( 'product.', $this->values ); |
81
|
|
|
$this->assertEquals( 'TEST', $object->test( 'product.code' ) ); |
82
|
|
|
|
83
|
|
|
$this->expectException( \BadMethodCallException::class ); |
84
|
|
|
$object->invalid(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
public function testDynamicBaseMethods() |
89
|
|
|
{ |
90
|
|
|
\Aimeos\MShop\Common\Item\Base::macro( 'tests', function( $name ) { |
91
|
|
|
return $this->bdata[$name]; |
|
|
|
|
92
|
|
|
} ); |
93
|
|
|
|
94
|
|
|
$this->assertInstanceOf( '\Closure', \Aimeos\MShop\Product\Item\Standard::macro( 'tests' ) ); |
95
|
|
|
|
96
|
|
|
$object = new \Aimeos\MShop\Product\Item\Standard( 'product.', $this->values ); |
97
|
|
|
$this->assertEquals( 'TEST', $object->tests( 'product.code' ) ); |
98
|
|
|
|
99
|
|
|
$this->expectException( \BadMethodCallException::class ); |
100
|
|
|
$object->invalid(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
public function testArrayMethods() |
105
|
|
|
{ |
106
|
|
|
$this->assertFalse( isset( $this->object['test'] ) ); |
107
|
|
|
$this->assertEquals( null, $this->object['test'] ); |
108
|
|
|
|
109
|
|
|
$this->object['test'] = 'value'; |
110
|
|
|
|
111
|
|
|
$this->assertTrue( isset( $this->object['test'] ) ); |
112
|
|
|
$this->assertEquals( 'value', $this->object['test'] ); |
113
|
|
|
|
114
|
|
|
$this->expectException( \LogicException::class ); |
115
|
|
|
unset( $this->object['test'] ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testMagicMethods() |
120
|
|
|
{ |
121
|
|
|
$this->assertFalse( isset( $this->object->test ) ); |
122
|
|
|
$this->assertEquals( null, $this->object->test ); |
123
|
|
|
|
124
|
|
|
$this->object->test = 'value'; |
125
|
|
|
|
126
|
|
|
$this->assertTrue( isset( $this->object->test ) ); |
127
|
|
|
$this->assertEquals( 'value', $this->object->test ); |
128
|
|
|
|
129
|
|
|
$this->assertEquals( '1', (string) $this->object ); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
public function testGetSet() |
134
|
|
|
{ |
135
|
|
|
$this->assertEquals( false, $this->object->get( 'test', false ) ); |
136
|
|
|
|
137
|
|
|
$return = $this->object->set( 'test', 'value' ); |
138
|
|
|
|
139
|
|
|
$this->assertEquals( 'value', $this->object->get( 'test', false ) ); |
140
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
public function testJsonSerialize() |
145
|
|
|
{ |
146
|
|
|
$result = json_decode( json_encode( $this->object ), true ); |
147
|
|
|
|
148
|
|
|
$this->assertEquals( 1, $result['product.id'] ); |
149
|
|
|
$this->assertEquals( '1.33.99.', $result['product.siteid'] ); |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
$result = json_decode( json_encode( [1 => $this->object] ), true ); |
153
|
|
|
|
154
|
|
|
$this->assertEquals( 1, $result[1]['product.id'] ); |
155
|
|
|
$this->assertEquals( '1.33.99.', $result[1]['product.siteid'] ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
public function testAssign() |
160
|
|
|
{ |
161
|
|
|
$this->assertEquals( false, $this->object->get( 'test', false ) ); |
162
|
|
|
|
163
|
|
|
$return = $this->object->assign( ['test' => 'value'] ); |
164
|
|
|
|
165
|
|
|
$this->assertEquals( 'value', $this->object->get( 'test', false ) ); |
166
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
public function testGetId() |
171
|
|
|
{ |
172
|
|
|
$this->assertEquals( '1', $this->object->getId() ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
public function testSetId() |
177
|
|
|
{ |
178
|
|
|
$return = $this->object->setId( null ); |
179
|
|
|
|
180
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
181
|
|
|
$this->assertNull( $this->object->getId() ); |
182
|
|
|
$this->assertTrue( $this->object->isModified() ); |
183
|
|
|
|
184
|
|
|
$return = $this->object->setId( 1 ); |
185
|
|
|
|
186
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
187
|
|
|
$this->assertEquals( '1', $this->object->getId() ); |
188
|
|
|
$this->assertFalse( $this->object->isModified() ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
public function testGetSiteId() |
193
|
|
|
{ |
194
|
|
|
$this->assertEquals( '1.33.99.', $this->object->getSiteId() ); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
public function testGetSitePath() |
199
|
|
|
{ |
200
|
|
|
$this->assertEquals( ['1.', '1.33.', '1.33.99.'], $this->object->getSitePath() ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
public function testGetType() |
205
|
|
|
{ |
206
|
|
|
$this->assertEquals( 'test', $this->object->getType() ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
public function testSetType() |
211
|
|
|
{ |
212
|
|
|
$this->assertFalse( $this->object->isModified() ); |
213
|
|
|
|
214
|
|
|
$return = $this->object->setType( 'default' ); |
215
|
|
|
|
216
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
217
|
|
|
$this->assertEquals( 'default', $this->object->getType() ); |
218
|
|
|
$this->assertTrue( $this->object->isModified() ); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
public function testGetCode() |
223
|
|
|
{ |
224
|
|
|
$this->assertEquals( 'TEST', $this->object->getCode() ); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
|
228
|
|
|
public function testSetCode() |
229
|
|
|
{ |
230
|
|
|
$this->assertFalse( $this->object->isModified() ); |
231
|
|
|
|
232
|
|
|
$return = $this->object->setCode( 'NEU' ); |
233
|
|
|
|
234
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
235
|
|
|
$this->assertEquals( 'NEU', $this->object->getCode() ); |
236
|
|
|
$this->assertTrue( $this->object->isModified() ); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
public function testGetDataset() |
241
|
|
|
{ |
242
|
|
|
$this->assertEquals( 'Shirts', $this->object->getDataset() ); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
public function testSetDataset() |
247
|
|
|
{ |
248
|
|
|
$this->assertFalse( $this->object->isModified() ); |
249
|
|
|
|
250
|
|
|
$return = $this->object->setDataset( 'Skirts' ); |
251
|
|
|
|
252
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
253
|
|
|
$this->assertEquals( 'Skirts', $this->object->getDataset() ); |
254
|
|
|
$this->assertTrue( $this->object->isModified() ); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
public function testGetScale() |
259
|
|
|
{ |
260
|
|
|
$this->assertEquals( 1, $this->object->getScale() ); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
|
264
|
|
|
public function testSetScale() |
265
|
|
|
{ |
266
|
|
|
$return = $this->object->setScale( 0.25 ); |
267
|
|
|
|
268
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
269
|
|
|
$this->assertEquals( 0.25, $this->object->getScale() ); |
270
|
|
|
$this->assertTrue( $this->object->isModified() ); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
public function testSetScaleInvalid() |
275
|
|
|
{ |
276
|
|
|
$return = $this->object->setScale( -1 ); |
277
|
|
|
|
278
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
279
|
|
|
$this->assertEquals( 1, $this->object->getScale() ); |
280
|
|
|
$this->assertTrue( $this->object->isModified() ); |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
public function testGetEditor() |
285
|
|
|
{ |
286
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->editor() ); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
|
290
|
|
|
public function testGetStatus() |
291
|
|
|
{ |
292
|
|
|
$this->assertEquals( 1, $this->object->getStatus() ); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
|
296
|
|
|
public function testSetStatus() |
297
|
|
|
{ |
298
|
|
|
$return = $this->object->setStatus( 8 ); |
299
|
|
|
|
300
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
301
|
|
|
$this->assertEquals( 8, $this->object->getStatus() ); |
302
|
|
|
$this->assertTrue( $this->object->isModified() ); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
public function testGetLabel() |
307
|
|
|
{ |
308
|
|
|
$this->assertEquals( 'testproduct', $this->object->getLabel() ); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
|
312
|
|
|
public function testSetLabel() |
313
|
|
|
{ |
314
|
|
|
$return = $this->object->setLabel( 'editproduct' ); |
315
|
|
|
|
316
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
317
|
|
|
$this->assertEquals( 'editproduct', $this->object->getLabel() ); |
318
|
|
|
$this->assertTrue( $this->object->isModified() ); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
|
322
|
|
|
public function testGetUrl() |
323
|
|
|
{ |
324
|
|
|
$this->assertEquals( 'test_product', $this->object->getUrl() ); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
|
328
|
|
|
public function testSetUrl() |
329
|
|
|
{ |
330
|
|
|
$return = $this->object->setUrl( 'edit_product' ); |
331
|
|
|
|
332
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
333
|
|
|
$this->assertEquals( 'edit_product', $this->object->getUrl() ); |
334
|
|
|
$this->assertTrue( $this->object->isModified() ); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
|
338
|
|
|
public function testGetConfig() |
339
|
|
|
{ |
340
|
|
|
$this->assertEquals( array( 'css-class' => 'test' ), $this->object->getConfig() ); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
|
344
|
|
|
public function testGetConfigValue() |
345
|
|
|
{ |
346
|
|
|
$this->assertEquals( 'test', $this->object->getConfigValue( 'css-class' ) ); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
|
350
|
|
|
public function testSetConfig() |
351
|
|
|
{ |
352
|
|
|
$this->assertFalse( $this->object->isModified() ); |
353
|
|
|
|
354
|
|
|
$return = $this->object->setConfig( array( 'key' => 'value' ) ); |
355
|
|
|
|
356
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
357
|
|
|
$this->assertEquals( array( 'key' => 'value' ), $this->object->getConfig() ); |
358
|
|
|
$this->assertTrue( $this->object->isModified() ); |
359
|
|
|
} |
360
|
|
|
|
361
|
|
|
|
362
|
|
|
public function testSetConfigValue() |
363
|
|
|
{ |
364
|
|
|
$result = $this->object->setConfigValue( 'path/to/value', 'test' ); |
365
|
|
|
$expected = ['path' => ['to' => ['value' => 'test']], 'css-class' => 'test']; |
366
|
|
|
|
367
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $result ); |
368
|
|
|
$this->assertEquals( $expected, $this->object->getConfig() ); |
369
|
|
|
|
370
|
|
|
$result = $this->object->setConfigValue( 'path/to/value2', 'test2' ); |
371
|
|
|
$expected = ['path' => ['to' => ['value' => 'test', 'value2' => 'test2']], 'css-class' => 'test']; |
372
|
|
|
|
373
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $result ); |
374
|
|
|
$this->assertEquals( $expected, $this->object->getConfig() ); |
375
|
|
|
} |
376
|
|
|
|
377
|
|
|
|
378
|
|
|
public function testGetTarget() |
379
|
|
|
{ |
380
|
|
|
$this->assertEquals( 'testtarget', $this->object->getTarget() ); |
381
|
|
|
} |
382
|
|
|
|
383
|
|
|
|
384
|
|
|
public function testSetTarget() |
385
|
|
|
{ |
386
|
|
|
$this->assertFalse( $this->object->isModified() ); |
387
|
|
|
|
388
|
|
|
$return = $this->object->setTarget( 'ttarget' ); |
389
|
|
|
|
390
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
391
|
|
|
$this->assertEquals( 'ttarget', $this->object->getTarget() ); |
392
|
|
|
$this->assertTrue( $this->object->isModified() ); |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
|
396
|
|
|
public function testGetDateStart() |
397
|
|
|
{ |
398
|
|
|
$this->assertEquals( null, $this->object->getDateStart() ); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
|
402
|
|
|
public function testSetDateStart() |
403
|
|
|
{ |
404
|
|
|
$return = $this->object->setDateStart( '2010-04-22 06:22:22' ); |
405
|
|
|
|
406
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
407
|
|
|
$this->assertEquals( '2010-04-22 06:22:22', $this->object->getDateStart() ); |
408
|
|
|
$this->assertTrue( $this->object->isModified() ); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
|
412
|
|
|
public function testGetDateEnd() |
413
|
|
|
{ |
414
|
|
|
$this->assertEquals( null, $this->object->getDateEnd() ); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
|
418
|
|
|
public function testSetDateEnd() |
419
|
|
|
{ |
420
|
|
|
$return = $this->object->setDateEnd( '2010-05-22 06:22' ); |
421
|
|
|
|
422
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
423
|
|
|
$this->assertEquals( '2010-05-22 06:22:00', $this->object->getDateEnd() ); |
424
|
|
|
$this->assertTrue( $this->object->isModified() ); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
|
428
|
|
|
public function testGetTimeModified() |
429
|
|
|
{ |
430
|
|
|
$this->assertEquals( '2011-01-19 18:04:32', $this->object->getTimeModified() ); |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
|
434
|
|
|
public function testGetTimeCreated() |
435
|
|
|
{ |
436
|
|
|
$this->assertEquals( '2011-01-19 17:04:32', $this->object->getTimeCreated() ); |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
|
440
|
|
|
public function testSetTimeCreated() |
441
|
|
|
{ |
442
|
|
|
$return = $this->object->setTimeCreated( '2010-05-22 06:22:22' ); |
443
|
|
|
|
444
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
445
|
|
|
$this->assertEquals( '2010-05-22 06:22:22', $this->object->getTimeCreated() ); |
446
|
|
|
$this->assertTrue( $this->object->isModified() ); |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
|
450
|
|
|
public function testGetRating() |
451
|
|
|
{ |
452
|
|
|
$this->assertEquals( '4.80', $this->object->getRating() ); |
453
|
|
|
} |
454
|
|
|
|
455
|
|
|
|
456
|
|
|
public function testGetRatings() |
457
|
|
|
{ |
458
|
|
|
$this->assertEquals( 5, $this->object->getRatings() ); |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
|
462
|
|
|
public function testInStock() |
463
|
|
|
{ |
464
|
|
|
$this->assertEquals( 1, $this->object->inStock() ); |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
|
468
|
|
|
public function testSetInStock() |
469
|
|
|
{ |
470
|
|
|
$return = $this->object->setInStock( 0 ); |
471
|
|
|
|
472
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
473
|
|
|
$this->assertEquals( 0, $this->object->inStock() ); |
474
|
|
|
$this->assertTrue( $this->object->isModified() ); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
|
478
|
|
|
public function testBoost() |
479
|
|
|
{ |
480
|
|
|
$this->assertEquals( 1.5, $this->object->boost() ); |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
|
484
|
|
|
public function testSetBoost() |
485
|
|
|
{ |
486
|
|
|
$return = $this->object->setBoost( 1.25 ); |
487
|
|
|
|
488
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
489
|
|
|
$this->assertEquals( 1.25, $this->object->boost() ); |
490
|
|
|
$this->assertTrue( $this->object->isModified() ); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
|
494
|
|
|
public function testIsAvailable() |
495
|
|
|
{ |
496
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
497
|
|
|
$this->object->setAvailable( false ); |
498
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
|
502
|
|
|
public function testIsAvailableOnStatus() |
503
|
|
|
{ |
504
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
505
|
|
|
$this->object->setStatus( 0 ); |
506
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
507
|
|
|
$this->object->setStatus( -1 ); |
508
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
|
512
|
|
|
public function testIsAvailableOnTime() |
513
|
|
|
{ |
514
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
515
|
|
|
$this->object->setDateStart( date( 'Y-m-d H:i:s', time() + 600 ) ); |
516
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
517
|
|
|
$this->object->setDateEnd( date( 'Y-m-d H:i:s', time() - 600 ) ); |
518
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
|
522
|
|
|
public function testIsAvailableEvent() |
523
|
|
|
{ |
524
|
|
|
$this->object->setType( 'event' ); |
525
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
526
|
|
|
$this->object->setDateStart( date( 'Y-m-d H:i:s', time() + 600 ) ); |
527
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
528
|
|
|
$this->object->setDateEnd( date( 'Y-m-d H:i:s', time() - 600 ) ); |
529
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
|
533
|
|
|
public function testIsModified() |
534
|
|
|
{ |
535
|
|
|
$this->assertFalse( $this->object->isModified() ); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
|
539
|
|
|
public function testIsModifiedTrue() |
540
|
|
|
{ |
541
|
|
|
$this->object->setLabel( 'reeditProduct' ); |
542
|
|
|
$this->assertTrue( $this->object->isModified() ); |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
|
546
|
|
|
public function testGetResourceType() |
547
|
|
|
{ |
548
|
|
|
$this->assertEquals( 'product', $this->object->getResourceType() ); |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
|
552
|
|
|
public function testGetPropertyItems() |
553
|
|
|
{ |
554
|
|
|
$propItems = $this->object->getPropertyItems(); |
555
|
|
|
|
556
|
|
|
$this->assertEquals( 1, count( $propItems ) ); |
557
|
|
|
|
558
|
|
|
foreach( $propItems as $propItem ) { |
559
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $propItem ); |
560
|
|
|
} |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
|
564
|
|
|
public function testGetSiteItem() |
565
|
|
|
{ |
566
|
|
|
$siteItem = \TestHelper::context()->locale()->getSiteItem(); |
567
|
|
|
$object = new \Aimeos\MShop\Product\Item\Standard( 'product.', ['.locale/site' => $siteItem] ); |
568
|
|
|
|
569
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $object->getSiteItem() ); |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
|
573
|
|
|
public function testGetPropertyItemsAll() |
574
|
|
|
{ |
575
|
|
|
$propItems = $this->object->getPropertyItems( null, false ); |
576
|
|
|
|
577
|
|
|
$this->assertEquals( 2, count( $propItems ) ); |
578
|
|
|
|
579
|
|
|
foreach( $propItems as $propItem ) { |
580
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $propItem ); |
581
|
|
|
} |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
|
585
|
|
|
public function testGetPropertyItemsType() |
586
|
|
|
{ |
587
|
|
|
$propItems = $this->object->getPropertyItems( 'proptest' ); |
588
|
|
|
|
589
|
|
|
$this->assertEquals( 1, count( $propItems ) ); |
590
|
|
|
|
591
|
|
|
foreach( $propItems as $propItem ) { |
592
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $propItem ); |
593
|
|
|
} |
594
|
|
|
} |
595
|
|
|
|
596
|
|
|
|
597
|
|
|
public function testFromArray() |
598
|
|
|
{ |
599
|
|
|
$item = new \Aimeos\MShop\Product\Item\Standard( 'product.' ); |
600
|
|
|
|
601
|
|
|
$list = $entries = array( |
602
|
|
|
'product.id' => 1, |
603
|
|
|
'product.type' => 'test', |
604
|
|
|
'product.label' => 'test item', |
605
|
|
|
'product.url' => 'test_item', |
606
|
|
|
'product.code' => 'test', |
607
|
|
|
'product.dataset' => 'Shirts', |
608
|
|
|
'product.datestart' => '2000-01-01 00:00:00', |
609
|
|
|
'product.dateend' => '2001-01-01 00:00:00', |
610
|
|
|
'product.config' => array( 'key' => 'value' ), |
611
|
|
|
'product.status' => 0, |
612
|
|
|
'product.scale' => '0.5', |
613
|
|
|
'product.target' => 'ttarget', |
614
|
|
|
'product.instock' => 1, |
615
|
|
|
'product.boost' => 2.5, |
616
|
|
|
'additional' => 'value', |
617
|
|
|
); |
618
|
|
|
|
619
|
|
|
$item = $item->fromArray( $entries, true ); |
620
|
|
|
|
621
|
|
|
$this->assertEquals( ['additional' => 'value'], $entries ); |
622
|
|
|
$this->assertEquals( $list['product.id'], $item->getId() ); |
623
|
|
|
$this->assertEquals( $list['product.url'], $item->getUrl() ); |
624
|
|
|
$this->assertEquals( $list['product.type'], $item->getType() ); |
625
|
|
|
$this->assertEquals( $list['product.code'], $item->getCode() ); |
626
|
|
|
$this->assertEquals( $list['product.label'], $item->getLabel() ); |
627
|
|
|
$this->assertEquals( $list['product.dataset'], $item->getDataset() ); |
628
|
|
|
$this->assertEquals( $list['product.datestart'], $item->getDateStart() ); |
629
|
|
|
$this->assertEquals( $list['product.dateend'], $item->getDateEnd() ); |
630
|
|
|
$this->assertEquals( $list['product.config'], $item->getConfig() ); |
631
|
|
|
$this->assertEquals( $list['product.status'], $item->getStatus() ); |
632
|
|
|
$this->assertEquals( $list['product.target'], $item->getTarget() ); |
633
|
|
|
$this->assertEquals( $list['product.scale'], $item->getScale() ); |
634
|
|
|
$this->assertEquals( $list['product.instock'], $item->inStock() ); |
635
|
|
|
$this->assertEquals( $list['product.boost'], $item->boost() ); |
636
|
|
|
$this->assertEquals( $list['additional'], $item->additional ); |
|
|
|
|
637
|
|
|
$this->assertEquals( '', $item->getSiteId() ); |
638
|
|
|
} |
639
|
|
|
|
640
|
|
|
|
641
|
|
|
public function testToArray() |
642
|
|
|
{ |
643
|
|
|
$arrayObject = $this->object->toArray( true ); |
644
|
|
|
$this->assertEquals( count( $this->values ), count( $arrayObject ) ); |
645
|
|
|
|
646
|
|
|
$this->assertEquals( $this->object->getId(), $arrayObject['product.id'] ); |
647
|
|
|
$this->assertEquals( $this->object->getSiteId(), $arrayObject['product.siteid'] ); |
648
|
|
|
$this->assertEquals( $this->object->getCode(), $arrayObject['product.code'] ); |
649
|
|
|
$this->assertEquals( $this->object->getType(), $arrayObject['product.type'] ); |
650
|
|
|
$this->assertEquals( $this->object->getDataset(), $arrayObject['product.dataset'] ); |
651
|
|
|
$this->assertEquals( $this->object->getLabel(), $arrayObject['product.label'] ); |
652
|
|
|
$this->assertEquals( $this->object->getUrl(), $arrayObject['product.url'] ); |
653
|
|
|
$this->assertEquals( $this->object->getStatus(), $arrayObject['product.status'] ); |
654
|
|
|
$this->assertEquals( $this->object->getDateStart(), $arrayObject['product.datestart'] ); |
655
|
|
|
$this->assertEquals( $this->object->getDateEnd(), $arrayObject['product.dateend'] ); |
656
|
|
|
$this->assertEquals( $this->object->getConfig(), $arrayObject['product.config'] ); |
657
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['product.ctime'] ); |
658
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $arrayObject['product.mtime'] ); |
659
|
|
|
$this->assertEquals( $this->object->editor(), $arrayObject['product.editor'] ); |
660
|
|
|
$this->assertEquals( $this->object->boost(), $arrayObject['product.boost'] ); |
661
|
|
|
$this->assertEquals( $this->object->getTarget(), $arrayObject['product.target'] ); |
662
|
|
|
$this->assertEquals( $this->object->getScale(), $arrayObject['product.scale'] ); |
663
|
|
|
$this->assertEquals( $this->object->getRating(), $arrayObject['product.rating'] ); |
664
|
|
|
$this->assertEquals( $this->object->getRatings(), $arrayObject['product.ratings'] ); |
665
|
|
|
$this->assertEquals( $this->object->inStock(), $arrayObject['product.instock'] ); |
666
|
|
|
} |
667
|
|
|
} |
668
|
|
|
|