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