|
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 testSetConfigFlat() |
|
379
|
|
|
{ |
|
380
|
|
|
$result = $this->object->setConfigFlat( ['css-class' => 'test'] ); |
|
381
|
|
|
|
|
382
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $result ); |
|
383
|
|
|
$this->assertEquals( ['css-class' => 'test'], $this->object->getConfig() ); |
|
384
|
|
|
$this->assertFalse( $this->object->isModified() ); |
|
385
|
|
|
|
|
386
|
|
|
$result = $this->object->setConfigFlat( ['path/to/value' => 'test'] ); |
|
387
|
|
|
$expected = ['path' => ['to' => ['value' => 'test']]]; |
|
388
|
|
|
|
|
389
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $result ); |
|
390
|
|
|
$this->assertEquals( $expected, $this->object->getConfig() ); |
|
391
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
|
|
395
|
|
|
public function testGetTarget() |
|
396
|
|
|
{ |
|
397
|
|
|
$this->assertEquals( 'testtarget', $this->object->getTarget() ); |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
|
|
401
|
|
|
public function testSetTarget() |
|
402
|
|
|
{ |
|
403
|
|
|
$this->assertFalse( $this->object->isModified() ); |
|
404
|
|
|
|
|
405
|
|
|
$return = $this->object->setTarget( 'ttarget' ); |
|
406
|
|
|
|
|
407
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
|
408
|
|
|
$this->assertEquals( 'ttarget', $this->object->getTarget() ); |
|
409
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
410
|
|
|
} |
|
411
|
|
|
|
|
412
|
|
|
|
|
413
|
|
|
public function testGetDateStart() |
|
414
|
|
|
{ |
|
415
|
|
|
$this->assertEquals( null, $this->object->getDateStart() ); |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
|
|
419
|
|
|
public function testSetDateStart() |
|
420
|
|
|
{ |
|
421
|
|
|
$return = $this->object->setDateStart( '2010-04-22 06:22:22' ); |
|
422
|
|
|
|
|
423
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
|
424
|
|
|
$this->assertEquals( '2010-04-22 06:22:22', $this->object->getDateStart() ); |
|
425
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
|
|
429
|
|
|
public function testGetDateEnd() |
|
430
|
|
|
{ |
|
431
|
|
|
$this->assertEquals( null, $this->object->getDateEnd() ); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
|
|
435
|
|
|
public function testSetDateEnd() |
|
436
|
|
|
{ |
|
437
|
|
|
$return = $this->object->setDateEnd( '2010-05-22 06:22' ); |
|
438
|
|
|
|
|
439
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
|
440
|
|
|
$this->assertEquals( '2010-05-22 06:22:00', $this->object->getDateEnd() ); |
|
441
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
442
|
|
|
} |
|
443
|
|
|
|
|
444
|
|
|
|
|
445
|
|
|
public function testGetTimeModified() |
|
446
|
|
|
{ |
|
447
|
|
|
$this->assertEquals( '2011-01-19 18:04:32', $this->object->getTimeModified() ); |
|
448
|
|
|
} |
|
449
|
|
|
|
|
450
|
|
|
|
|
451
|
|
|
public function testGetTimeCreated() |
|
452
|
|
|
{ |
|
453
|
|
|
$this->assertEquals( '2011-01-19 17:04:32', $this->object->getTimeCreated() ); |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
|
|
457
|
|
|
public function testSetTimeCreated() |
|
458
|
|
|
{ |
|
459
|
|
|
$return = $this->object->setTimeCreated( '2010-05-22 06:22:22' ); |
|
460
|
|
|
|
|
461
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
|
462
|
|
|
$this->assertEquals( '2010-05-22 06:22:22', $this->object->getTimeCreated() ); |
|
463
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
464
|
|
|
} |
|
465
|
|
|
|
|
466
|
|
|
|
|
467
|
|
|
public function testGetRating() |
|
468
|
|
|
{ |
|
469
|
|
|
$this->assertEquals( '4.80', $this->object->getRating() ); |
|
470
|
|
|
} |
|
471
|
|
|
|
|
472
|
|
|
|
|
473
|
|
|
public function testGetRatings() |
|
474
|
|
|
{ |
|
475
|
|
|
$this->assertEquals( 5, $this->object->getRatings() ); |
|
476
|
|
|
} |
|
477
|
|
|
|
|
478
|
|
|
|
|
479
|
|
|
public function testInStock() |
|
480
|
|
|
{ |
|
481
|
|
|
$this->assertEquals( 1, $this->object->inStock() ); |
|
482
|
|
|
} |
|
483
|
|
|
|
|
484
|
|
|
|
|
485
|
|
|
public function testSetInStock() |
|
486
|
|
|
{ |
|
487
|
|
|
$return = $this->object->setInStock( 0 ); |
|
488
|
|
|
|
|
489
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
|
490
|
|
|
$this->assertEquals( 0, $this->object->inStock() ); |
|
491
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
492
|
|
|
} |
|
493
|
|
|
|
|
494
|
|
|
|
|
495
|
|
|
public function testBoost() |
|
496
|
|
|
{ |
|
497
|
|
|
$this->assertEquals( 1.5, $this->object->boost() ); |
|
498
|
|
|
} |
|
499
|
|
|
|
|
500
|
|
|
|
|
501
|
|
|
public function testSetBoost() |
|
502
|
|
|
{ |
|
503
|
|
|
$return = $this->object->setBoost( 1.25 ); |
|
504
|
|
|
|
|
505
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $return ); |
|
506
|
|
|
$this->assertEquals( 1.25, $this->object->boost() ); |
|
507
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
508
|
|
|
} |
|
509
|
|
|
|
|
510
|
|
|
|
|
511
|
|
|
public function testIsAvailable() |
|
512
|
|
|
{ |
|
513
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
514
|
|
|
$this->object->setAvailable( false ); |
|
515
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
516
|
|
|
} |
|
517
|
|
|
|
|
518
|
|
|
|
|
519
|
|
|
public function testIsAvailableOnStatus() |
|
520
|
|
|
{ |
|
521
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
522
|
|
|
$this->object->setStatus( 0 ); |
|
523
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
524
|
|
|
$this->object->setStatus( -1 ); |
|
525
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
|
|
529
|
|
|
public function testIsAvailableOnTime() |
|
530
|
|
|
{ |
|
531
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
532
|
|
|
$this->object->setDateStart( date( 'Y-m-d H:i:s', time() + 600 ) ); |
|
533
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
534
|
|
|
$this->object->setDateEnd( date( 'Y-m-d H:i:s', time() - 600 ) ); |
|
535
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
536
|
|
|
} |
|
537
|
|
|
|
|
538
|
|
|
|
|
539
|
|
|
public function testIsAvailableEvent() |
|
540
|
|
|
{ |
|
541
|
|
|
$this->object->setType( 'event' ); |
|
542
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
543
|
|
|
$this->object->setDateStart( date( 'Y-m-d H:i:s', time() + 600 ) ); |
|
544
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
545
|
|
|
$this->object->setDateEnd( date( 'Y-m-d H:i:s', time() - 600 ) ); |
|
546
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
547
|
|
|
} |
|
548
|
|
|
|
|
549
|
|
|
|
|
550
|
|
|
public function testIsModified() |
|
551
|
|
|
{ |
|
552
|
|
|
$this->assertFalse( $this->object->isModified() ); |
|
553
|
|
|
} |
|
554
|
|
|
|
|
555
|
|
|
|
|
556
|
|
|
public function testIsModifiedTrue() |
|
557
|
|
|
{ |
|
558
|
|
|
$this->object->setLabel( 'reeditProduct' ); |
|
559
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
560
|
|
|
} |
|
561
|
|
|
|
|
562
|
|
|
|
|
563
|
|
|
public function testGetResourceType() |
|
564
|
|
|
{ |
|
565
|
|
|
$this->assertEquals( 'product', $this->object->getResourceType() ); |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
|
|
569
|
|
|
public function testGetPropertyItems() |
|
570
|
|
|
{ |
|
571
|
|
|
$propItems = $this->object->getPropertyItems(); |
|
572
|
|
|
|
|
573
|
|
|
$this->assertEquals( 1, count( $propItems ) ); |
|
574
|
|
|
|
|
575
|
|
|
foreach( $propItems as $propItem ) { |
|
576
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $propItem ); |
|
577
|
|
|
} |
|
578
|
|
|
} |
|
579
|
|
|
|
|
580
|
|
|
|
|
581
|
|
|
public function testGetSiteItem() |
|
582
|
|
|
{ |
|
583
|
|
|
$siteItem = \TestHelper::context()->locale()->getSiteItem(); |
|
584
|
|
|
$object = new \Aimeos\MShop\Product\Item\Standard( 'product.', ['.locale/site' => $siteItem] ); |
|
585
|
|
|
|
|
586
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $object->getSiteItem() ); |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
|
|
590
|
|
|
public function testGetPropertyItemsAll() |
|
591
|
|
|
{ |
|
592
|
|
|
$propItems = $this->object->getPropertyItems( null, false ); |
|
593
|
|
|
|
|
594
|
|
|
$this->assertEquals( 2, count( $propItems ) ); |
|
595
|
|
|
|
|
596
|
|
|
foreach( $propItems as $propItem ) { |
|
597
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $propItem ); |
|
598
|
|
|
} |
|
599
|
|
|
} |
|
600
|
|
|
|
|
601
|
|
|
|
|
602
|
|
|
public function testGetPropertyItemsType() |
|
603
|
|
|
{ |
|
604
|
|
|
$propItems = $this->object->getPropertyItems( 'proptest' ); |
|
605
|
|
|
|
|
606
|
|
|
$this->assertEquals( 1, count( $propItems ) ); |
|
607
|
|
|
|
|
608
|
|
|
foreach( $propItems as $propItem ) { |
|
609
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $propItem ); |
|
610
|
|
|
} |
|
611
|
|
|
} |
|
612
|
|
|
|
|
613
|
|
|
|
|
614
|
|
|
public function testFromArray() |
|
615
|
|
|
{ |
|
616
|
|
|
$item = new \Aimeos\MShop\Product\Item\Standard( 'product.' ); |
|
617
|
|
|
|
|
618
|
|
|
$list = $entries = array( |
|
619
|
|
|
'product.id' => 1, |
|
620
|
|
|
'product.type' => 'test', |
|
621
|
|
|
'product.label' => 'test item', |
|
622
|
|
|
'product.url' => 'test_item', |
|
623
|
|
|
'product.code' => 'test', |
|
624
|
|
|
'product.dataset' => 'Shirts', |
|
625
|
|
|
'product.datestart' => '2000-01-01 00:00:00', |
|
626
|
|
|
'product.dateend' => '2001-01-01 00:00:00', |
|
627
|
|
|
'product.config' => array( 'key' => 'value' ), |
|
628
|
|
|
'product.status' => 0, |
|
629
|
|
|
'product.scale' => '0.5', |
|
630
|
|
|
'product.target' => 'ttarget', |
|
631
|
|
|
'product.instock' => 1, |
|
632
|
|
|
'product.boost' => 2.5, |
|
633
|
|
|
'additional' => 'value', |
|
634
|
|
|
); |
|
635
|
|
|
|
|
636
|
|
|
$item = $item->fromArray( $entries, true ); |
|
637
|
|
|
|
|
638
|
|
|
$this->assertEquals( ['additional' => 'value'], $entries ); |
|
639
|
|
|
$this->assertEquals( $list['product.id'], $item->getId() ); |
|
640
|
|
|
$this->assertEquals( $list['product.url'], $item->getUrl() ); |
|
641
|
|
|
$this->assertEquals( $list['product.type'], $item->getType() ); |
|
642
|
|
|
$this->assertEquals( $list['product.code'], $item->getCode() ); |
|
643
|
|
|
$this->assertEquals( $list['product.label'], $item->getLabel() ); |
|
644
|
|
|
$this->assertEquals( $list['product.dataset'], $item->getDataset() ); |
|
645
|
|
|
$this->assertEquals( $list['product.datestart'], $item->getDateStart() ); |
|
646
|
|
|
$this->assertEquals( $list['product.dateend'], $item->getDateEnd() ); |
|
647
|
|
|
$this->assertEquals( $list['product.config'], $item->getConfig() ); |
|
648
|
|
|
$this->assertEquals( $list['product.status'], $item->getStatus() ); |
|
649
|
|
|
$this->assertEquals( $list['product.target'], $item->getTarget() ); |
|
650
|
|
|
$this->assertEquals( $list['product.scale'], $item->getScale() ); |
|
651
|
|
|
$this->assertEquals( $list['product.instock'], $item->inStock() ); |
|
652
|
|
|
$this->assertEquals( $list['product.boost'], $item->boost() ); |
|
653
|
|
|
$this->assertEquals( $list['additional'], $item->additional ); |
|
|
|
|
|
|
654
|
|
|
$this->assertEquals( '', $item->getSiteId() ); |
|
655
|
|
|
} |
|
656
|
|
|
|
|
657
|
|
|
|
|
658
|
|
|
public function testToArray() |
|
659
|
|
|
{ |
|
660
|
|
|
$arrayObject = $this->object->toArray( true ); |
|
661
|
|
|
$this->assertEquals( count( $this->values ), count( $arrayObject ) ); |
|
662
|
|
|
|
|
663
|
|
|
$this->assertEquals( $this->object->getId(), $arrayObject['product.id'] ); |
|
664
|
|
|
$this->assertEquals( $this->object->getSiteId(), $arrayObject['product.siteid'] ); |
|
665
|
|
|
$this->assertEquals( $this->object->getCode(), $arrayObject['product.code'] ); |
|
666
|
|
|
$this->assertEquals( $this->object->getType(), $arrayObject['product.type'] ); |
|
667
|
|
|
$this->assertEquals( $this->object->getDataset(), $arrayObject['product.dataset'] ); |
|
668
|
|
|
$this->assertEquals( $this->object->getLabel(), $arrayObject['product.label'] ); |
|
669
|
|
|
$this->assertEquals( $this->object->getUrl(), $arrayObject['product.url'] ); |
|
670
|
|
|
$this->assertEquals( $this->object->getStatus(), $arrayObject['product.status'] ); |
|
671
|
|
|
$this->assertEquals( $this->object->getDateStart(), $arrayObject['product.datestart'] ); |
|
672
|
|
|
$this->assertEquals( $this->object->getDateEnd(), $arrayObject['product.dateend'] ); |
|
673
|
|
|
$this->assertEquals( $this->object->getConfig(), $arrayObject['product.config'] ); |
|
674
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['product.ctime'] ); |
|
675
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $arrayObject['product.mtime'] ); |
|
676
|
|
|
$this->assertEquals( $this->object->editor(), $arrayObject['product.editor'] ); |
|
677
|
|
|
$this->assertEquals( $this->object->boost(), $arrayObject['product.boost'] ); |
|
678
|
|
|
$this->assertEquals( $this->object->getTarget(), $arrayObject['product.target'] ); |
|
679
|
|
|
$this->assertEquals( $this->object->getScale(), $arrayObject['product.scale'] ); |
|
680
|
|
|
$this->assertEquals( $this->object->getRating(), $arrayObject['product.rating'] ); |
|
681
|
|
|
$this->assertEquals( $this->object->getRatings(), $arrayObject['product.ratings'] ); |
|
682
|
|
|
$this->assertEquals( $this->object->inStock(), $arrayObject['product.instock'] ); |
|
683
|
|
|
} |
|
684
|
|
|
} |
|
685
|
|
|
|