1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
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() |
20
|
|
|
{ |
21
|
|
|
$this->values = array( |
22
|
|
|
'product.id' => 1, |
23
|
|
|
'product.siteid' => 99, |
24
|
|
|
'product.typeid' => 2, |
25
|
|
|
'product.type' => 'test', |
26
|
|
|
'product.typename' => 'Test', |
27
|
|
|
'product.status' => 0, |
28
|
|
|
'product.code' => 'TEST', |
29
|
|
|
'product.label' => 'testproduct', |
30
|
|
|
'product.config' => array( 'css-class' => 'test' ), |
31
|
|
|
'product.datestart' => null, |
32
|
|
|
'product.dateend' => null, |
33
|
|
|
'product.ctime' => '2011-01-19 17:04:32', |
34
|
|
|
'product.mtime' => '2011-01-19 18:04:32', |
35
|
|
|
'product.editor' => 'unitTestUser' |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$propItems = array( |
39
|
|
|
2 => new \Aimeos\MShop\Product\Item\Property\Standard( array( |
40
|
|
|
'product.property.id' => 2, |
41
|
|
|
'product.property.parentid' => 1, |
42
|
|
|
'product.property.type' => 'proptest', |
43
|
|
|
) ), |
44
|
|
|
3 => new \Aimeos\MShop\Product\Item\Property\Standard( array( |
45
|
|
|
'product.property.id' => 3, |
46
|
|
|
'product.property.parentid' => 1, |
47
|
|
|
'product.property.type' => 'proptype', |
48
|
|
|
) ), |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$this->object = new \Aimeos\MShop\Product\Item\Standard( $this->values, array(), array(), $propItems ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
protected function tearDown() |
56
|
|
|
{ |
57
|
|
|
unset( $this->object, $this->textListItems ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testGetId() |
62
|
|
|
{ |
63
|
|
|
$this->assertEquals( '1', $this->object->getId() ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
public function testSetId() |
68
|
|
|
{ |
69
|
|
|
$return = $this->object->setId( null ); |
70
|
|
|
|
71
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return ); |
72
|
|
|
$this->assertNull( $this->object->getId() ); |
73
|
|
|
$this->assertTrue( $this->object->isModified() ); |
74
|
|
|
|
75
|
|
|
$return = $this->object->setId( 1 ); |
76
|
|
|
|
77
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return ); |
78
|
|
|
$this->assertEquals( '1', $this->object->getId() ); |
79
|
|
|
$this->assertFalse( $this->object->isModified() ); |
80
|
|
|
|
81
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
82
|
|
|
$this->object->setId( 2 ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function testGetSiteId() |
87
|
|
|
{ |
88
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function testGetPropertyItems() |
93
|
|
|
{ |
94
|
|
|
$propItems = $this->object->getPropertyItems(); |
95
|
|
|
|
96
|
|
|
$this->assertEquals( 2, count( $propItems ) ); |
97
|
|
|
|
98
|
|
|
foreach( $propItems as $propItem ) { |
99
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Property\Iface', $propItem ); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
public function testGetPropertyItemsType() |
105
|
|
|
{ |
106
|
|
|
$propItems = $this->object->getPropertyItems( 'proptest' ); |
107
|
|
|
|
108
|
|
|
$this->assertEquals( 1, count( $propItems ) ); |
109
|
|
|
|
110
|
|
|
foreach( $propItems as $propItem ) { |
111
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Property\Iface', $propItem ); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
public function testGetTypeId() |
117
|
|
|
{ |
118
|
|
|
$this->assertEquals( 2, $this->object->getTypeId() ); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
|
122
|
|
|
public function testSetTypeId() |
123
|
|
|
{ |
124
|
|
|
$this->assertFalse( $this->object->isModified() ); |
125
|
|
|
|
126
|
|
|
$return = $this->object->setTypeId( 1 ); |
127
|
|
|
|
128
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return ); |
129
|
|
|
$this->assertEquals( 1, $this->object->getTypeId() ); |
130
|
|
|
$this->assertTrue( $this->object->isModified() ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testGetType() |
135
|
|
|
{ |
136
|
|
|
$this->assertEquals( 'test', $this->object->getType() ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
public function testGetTypeName() |
141
|
|
|
{ |
142
|
|
|
$this->assertEquals( 'Test', $this->object->getTypeName() ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
public function testGetCode() |
147
|
|
|
{ |
148
|
|
|
$this->assertEquals( 'TEST', $this->object->getCode() ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
public function testSetCode() |
153
|
|
|
{ |
154
|
|
|
$this->assertFalse( $this->object->isModified() ); |
155
|
|
|
|
156
|
|
|
$return = $this->object->setCode( 'NEU' ); |
157
|
|
|
|
158
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return ); |
159
|
|
|
$this->assertEquals( 'NEU', $this->object->getCode() ); |
160
|
|
|
$this->assertTrue( $this->object->isModified() ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
public function testGetEditor() |
165
|
|
|
{ |
166
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->getEditor() ); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
|
170
|
|
|
public function testGetStatus() |
171
|
|
|
{ |
172
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
public function testSetStatus() |
177
|
|
|
{ |
178
|
|
|
$return = $this->object->setStatus( 8 ); |
179
|
|
|
|
180
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return ); |
181
|
|
|
$this->assertEquals( 8, $this->object->getStatus() ); |
182
|
|
|
$this->assertTrue( $this->object->isModified() ); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
public function testGetLabel() |
187
|
|
|
{ |
188
|
|
|
$this->assertEquals( 'testproduct', $this->object->getLabel() ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
public function testSetLabel() |
193
|
|
|
{ |
194
|
|
|
$return = $this->object->setLabel( 'editproduct' ); |
195
|
|
|
|
196
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return ); |
197
|
|
|
$this->assertEquals( 'editproduct', $this->object->getLabel() ); |
198
|
|
|
$this->assertTrue( $this->object->isModified() ); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
|
202
|
|
|
public function testGetConfig() |
203
|
|
|
{ |
204
|
|
|
$this->assertEquals( array( 'css-class' => 'test' ), $this->object->getConfig() ); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
|
208
|
|
|
public function testSetConfig() |
209
|
|
|
{ |
210
|
|
|
$this->assertFalse( $this->object->isModified() ); |
211
|
|
|
|
212
|
|
|
$return = $this->object->setConfig( array( 'key' => 'value' ) ); |
213
|
|
|
|
214
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return ); |
215
|
|
|
$this->assertEquals( array( 'key' => 'value' ), $this->object->getConfig() ); |
216
|
|
|
$this->assertTrue( $this->object->isModified() ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
public function testGetDateStart() |
221
|
|
|
{ |
222
|
|
|
$this->assertEquals( null, $this->object->getDateStart() ); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
|
226
|
|
|
public function testSetDateStart() |
227
|
|
|
{ |
228
|
|
|
$return = $this->object->setDateStart( '2010-04-22 06:22:22' ); |
229
|
|
|
|
230
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return ); |
231
|
|
|
$this->assertEquals( '2010-04-22 06:22:22', $this->object->getDateStart() ); |
232
|
|
|
$this->assertTrue( $this->object->isModified() ); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
|
236
|
|
|
public function testGetDateEnd() |
237
|
|
|
{ |
238
|
|
|
$this->assertEquals( null, $this->object->getDateEnd() ); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
|
242
|
|
|
public function testSetDateEnd() |
243
|
|
|
{ |
244
|
|
|
$return = $this->object->setDateEnd( '2010-05-22 06:22:22' ); |
245
|
|
|
|
246
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $return ); |
247
|
|
|
$this->assertEquals( '2010-05-22 06:22:22', $this->object->getDateEnd() ); |
248
|
|
|
$this->assertTrue( $this->object->isModified() ); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
public function testGetTimeModified() |
253
|
|
|
{ |
254
|
|
|
$this->assertEquals( '2011-01-19 18:04:32', $this->object->getTimeModified() ); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
public function testGetTimeCreated() |
259
|
|
|
{ |
260
|
|
|
$this->assertEquals( '2011-01-19 17:04:32', $this->object->getTimeCreated() ); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
|
264
|
|
|
public function testIsModified() |
265
|
|
|
{ |
266
|
|
|
$this->assertFalse( $this->object->isModified() ); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
public function testIsModifiedTrue() |
271
|
|
|
{ |
272
|
|
|
$this->object->setLabel( 'reeditProduct' ); |
273
|
|
|
$this->assertTrue( $this->object->isModified() ); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
public function testGetResourceType() |
278
|
|
|
{ |
279
|
|
|
$this->assertEquals( 'product', $this->object->getResourceType() ); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
|
283
|
|
|
public function testFromArray() |
284
|
|
|
{ |
285
|
|
|
$item = new \Aimeos\MShop\Product\Item\Standard(); |
286
|
|
|
|
287
|
|
|
$list = array( |
288
|
|
|
'product.id' => 1, |
289
|
|
|
'product.typeid' => 2, |
290
|
|
|
'product.type' => 'test', |
291
|
|
|
'product.typename' => 'Test', |
292
|
|
|
'product.label' => 'test item', |
293
|
|
|
'product.code' => 'test', |
294
|
|
|
'product.datestart' => '2000-01-01 00:00:00', |
295
|
|
|
'product.dateend' => '2001-01-01 00:00:00', |
296
|
|
|
'product.config' => array( 'key' => 'value' ), |
297
|
|
|
'product.status' => 0, |
298
|
|
|
); |
299
|
|
|
|
300
|
|
|
$unknown = $item->fromArray( $list ); |
301
|
|
|
|
302
|
|
|
$this->assertEquals( array(), $unknown ); |
303
|
|
|
|
304
|
|
|
$this->assertEquals( $list['product.id'], $item->getId() ); |
305
|
|
|
$this->assertEquals( $list['product.code'], $item->getCode() ); |
306
|
|
|
$this->assertEquals( $list['product.label'], $item->getLabel() ); |
307
|
|
|
$this->assertEquals( $list['product.typeid'], $item->getTypeId() ); |
308
|
|
|
$this->assertEquals( $list['product.datestart'], $item->getDateStart() ); |
309
|
|
|
$this->assertEquals( $list['product.dateend'], $item->getDateEnd() ); |
310
|
|
|
$this->assertEquals( $list['product.config'], $item->getConfig() ); |
311
|
|
|
$this->assertEquals( $list['product.status'], $item->getStatus() ); |
312
|
|
|
$this->assertNull( $item->getSiteId() ); |
313
|
|
|
$this->assertNull( $item->getTypeName() ); |
314
|
|
|
$this->assertNull( $item->getType() ); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
|
318
|
|
|
public function testToArray() |
319
|
|
|
{ |
320
|
|
|
$arrayObject = $this->object->toArray(); |
321
|
|
|
$this->assertEquals( count( $this->values ), count( $arrayObject ) ); |
322
|
|
|
|
323
|
|
|
$this->assertEquals( $this->object->getId(), $arrayObject['product.id'] ); |
324
|
|
|
$this->assertEquals( $this->object->getSiteId(), $arrayObject['product.siteid'] ); |
325
|
|
|
$this->assertEquals( $this->object->getCode(), $arrayObject['product.code'] ); |
326
|
|
|
$this->assertEquals( $this->object->getTypeName(), $arrayObject['product.typename'] ); |
327
|
|
|
$this->assertEquals( $this->object->getTypeId(), $arrayObject['product.typeid'] ); |
328
|
|
|
$this->assertEquals( $this->object->getType(), $arrayObject['product.type'] ); |
329
|
|
|
$this->assertEquals( $this->object->getLabel(), $arrayObject['product.label'] ); |
330
|
|
|
$this->assertEquals( $this->object->getStatus(), $arrayObject['product.status'] ); |
331
|
|
|
$this->assertEquals( $this->object->getDateStart(), $arrayObject['product.datestart'] ); |
332
|
|
|
$this->assertEquals( $this->object->getDateEnd(), $arrayObject['product.dateend'] ); |
333
|
|
|
$this->assertEquals( $this->object->getConfig(), $arrayObject['product.config'] ); |
334
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['product.ctime'] ); |
335
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $arrayObject['product.mtime'] ); |
336
|
|
|
$this->assertEquals( $this->object->getEditor(), $arrayObject['product.editor'] ); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
} |
340
|
|
|
|