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-2018 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Common\Item\Lists; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$values = array( |
21
|
|
|
'common.lists.id' => 8, |
22
|
|
|
'common.lists.siteid' => 99, |
23
|
|
|
'common.lists.parentid' => 2, |
24
|
|
|
'common.lists.domain' => 'testDomain', |
25
|
|
|
'common.lists.refid' => 'unitId', |
26
|
|
|
'common.lists.datestart' => '2005-01-01 00:00:00', |
27
|
|
|
'common.lists.dateend' => '2010-12-31 00:00:00', |
28
|
|
|
'common.lists.config' => array( 'cnt' => '40' ), |
29
|
|
|
'common.lists.position' => 7, |
30
|
|
|
'common.lists.status' => 1, |
31
|
|
|
'common.lists.type' => 'test', |
32
|
|
|
'common.lists.mtime' => '2011-01-01 00:00:02', |
33
|
|
|
'common.lists.ctime' => '2011-01-01 00:00:01', |
34
|
|
|
'common.lists.editor' => 'unitTestUser', |
35
|
|
|
'date' => date( 'Y-m-d H:i:s' ), |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$this->object = new \Aimeos\MShop\Common\Item\Lists\Standard( 'common.lists.', $values ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
protected function tearDown() |
43
|
|
|
{ |
44
|
|
|
unset( $this->object ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function testGetId() |
49
|
|
|
{ |
50
|
|
|
$this->assertEquals( 8, $this->object->getId() ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testSetId() |
55
|
|
|
{ |
56
|
|
|
$return = $this->object->setId( null ); |
57
|
|
|
|
58
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
59
|
|
|
$this->assertTrue( $this->object->isModified() ); |
60
|
|
|
$this->assertNull( $this->object->getId() ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testGetParentId() |
65
|
|
|
{ |
66
|
|
|
$this->assertEquals( 2, $this->object->getParentId() ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testSetParentId() |
71
|
|
|
{ |
72
|
|
|
$return = $this->object->setParentId( 5 ); |
73
|
|
|
|
74
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
75
|
|
|
$this->assertEquals( 5, $this->object->getParentId() ); |
76
|
|
|
$this->assertTrue( $this->object->isModified() ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
public function testGetKey() |
81
|
|
|
{ |
82
|
|
|
$this->assertEquals( 'testDomain|test|unitId', $this->object->getKey() ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function testGetDomain() |
87
|
|
|
{ |
88
|
|
|
$this->assertEquals( 'testDomain', $this->object->getDomain() ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function testSetDomain() |
93
|
|
|
{ |
94
|
|
|
$return = $this->object->setDomain( 'newDom' ); |
95
|
|
|
|
96
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
97
|
|
|
$this->assertEquals( 'newDom', $this->object->getDomain() ); |
98
|
|
|
$this->assertTrue( $this->object->isModified() ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
public function testGetRefId() |
103
|
|
|
{ |
104
|
|
|
$this->assertEquals( 'unitId', $this->object->getRefId() ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testSetRefId() |
109
|
|
|
{ |
110
|
|
|
$return = $this->object->setRefId( 'unitReference' ); |
111
|
|
|
|
112
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
113
|
|
|
$this->assertEquals( 'unitReference', $this->object->getRefId() ); |
114
|
|
|
$this->assertTrue( $this->object->isModified() ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testGetDateStart() |
119
|
|
|
{ |
120
|
|
|
$this->assertEquals( '2005-01-01 00:00:00', $this->object->getDateStart() ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
public function testSetDateStart() |
125
|
|
|
{ |
126
|
|
|
$return = $this->object->setDateStart( '2002-01-01 00:00:00' ); |
127
|
|
|
|
128
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
129
|
|
|
$this->assertEquals( '2002-01-01 00:00:00', $this->object->getDateStart() ); |
130
|
|
|
$this->assertTrue( $this->object->isModified() ); |
131
|
|
|
|
132
|
|
|
$this->setExpectedException( \Aimeos\MShop\Exception::class ); |
133
|
|
|
$this->object->setDateStart( '2008-34-12' ); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testGetDateEnd() |
138
|
|
|
{ |
139
|
|
|
$this->assertEquals( '2010-12-31 00:00:00', $this->object->getDateEnd() ); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
public function testSetDateEnd() |
144
|
|
|
{ |
145
|
|
|
$return = $this->object->setDateEnd( '4400-12-31 00:00:00' ); |
146
|
|
|
|
147
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
148
|
|
|
$this->assertEquals( '4400-12-31 00:00:00', $this->object->getDateEnd() ); |
149
|
|
|
$this->assertTrue( $this->object->isModified() ); |
150
|
|
|
|
151
|
|
|
$this->setExpectedException( \Aimeos\MShop\Exception::class ); |
152
|
|
|
$this->object->setDateEnd( '2008-34-12' ); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
|
156
|
|
|
public function testSetPosition() |
157
|
|
|
{ |
158
|
|
|
$return = $this->object->setPosition( 1234 ); |
159
|
|
|
|
160
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
161
|
|
|
$this->assertEquals( 1234, $this->object->getPosition() ); |
162
|
|
|
$this->assertTrue( $this->object->isModified() ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
public function testGetPosition() |
167
|
|
|
{ |
168
|
|
|
$this->assertEquals( 7, $this->object->getPosition() ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
public function testSetStatus() |
173
|
|
|
{ |
174
|
|
|
$return = $this->object->setStatus( 0 ); |
175
|
|
|
|
176
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
177
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
178
|
|
|
$this->assertTrue( $this->object->isModified() ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
public function testGetStatus() |
183
|
|
|
{ |
184
|
|
|
$this->assertEquals( 1, $this->object->getStatus() ); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
public function testGetType() |
189
|
|
|
{ |
190
|
|
|
$this->assertEquals( 'test', $this->object->getType() ); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
public function testSetType() |
195
|
|
|
{ |
196
|
|
|
$return = $this->object->setType( 'test2' ); |
197
|
|
|
|
198
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
199
|
|
|
$this->assertEquals( 'test2', $this->object->getType() ); |
200
|
|
|
$this->assertTrue( $this->object->isModified() ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
public function testGetSiteId() |
205
|
|
|
{ |
206
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
public function testGetTimeModified() |
211
|
|
|
{ |
212
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
|
216
|
|
|
public function testGetTimeCreated() |
217
|
|
|
{ |
218
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
public function testGetEditor() |
223
|
|
|
{ |
224
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->getEditor() ); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
|
228
|
|
|
public function testGetConfig() |
229
|
|
|
{ |
230
|
|
|
$this->assertEquals( array( 'cnt'=>'40' ), $this->object->getConfig() ); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
|
234
|
|
|
public function testGetConfigValue() |
235
|
|
|
{ |
236
|
|
|
$this->assertEquals( '40', $this->object->getConfigValue( 'cnt' ) ); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
public function testSetConfig() |
241
|
|
|
{ |
242
|
|
|
$return = $this->object->setConfig( array( 'new value'=>'20.00' ) ); |
243
|
|
|
|
244
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
245
|
|
|
$this->assertEquals( array( 'new value'=>'20.00' ), $this->object->getConfig() ); |
246
|
|
|
$this->assertEquals( true, $this->object->isModified() ); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
public function testIsAvailable() |
251
|
|
|
{ |
252
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
public function testIsModified() |
257
|
|
|
{ |
258
|
|
|
$this->assertFalse( $this->object->isModified() ); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
public function testGetRefItem() |
263
|
|
|
{ |
264
|
|
|
$this->assertEquals( null, $this->object->getRefItem() ); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
|
268
|
|
|
public function testSetRefItem() |
269
|
|
|
{ |
270
|
|
|
$obj = new \Aimeos\MShop\Common\Item\Lists\Standard( 'reftest', [] ); |
271
|
|
|
|
272
|
|
|
$return = $this->object->setRefItem( $obj ); |
273
|
|
|
|
274
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $return ); |
275
|
|
|
$this->assertSame( $obj, $this->object->getRefItem() ); |
276
|
|
|
$this->assertFalse( $this->object->isModified() ); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
|
280
|
|
|
public function testGetResourceType() |
281
|
|
|
{ |
282
|
|
|
$this->assertEquals( 'common/lists', $this->object->getResourceType() ); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
|
286
|
|
|
public function testFromArray() |
287
|
|
|
{ |
288
|
|
|
$item = new \Aimeos\MShop\Common\Item\Lists\Standard( 'common.lists.' ); |
289
|
|
|
|
290
|
|
|
$list = $entries = array( |
291
|
|
|
'common.lists.id' => 8, |
292
|
|
|
'common.lists.parentid' => 2, |
293
|
|
|
'common.lists.type' => 'default', |
294
|
|
|
'common.lists.domain' => 'testDomain', |
295
|
|
|
'common.lists.refid' => 'unitId', |
296
|
|
|
'common.lists.config' => array( 'cnt' => '40' ), |
297
|
|
|
'common.lists.position' => 7, |
298
|
|
|
'common.lists.status' => 1, |
299
|
|
|
); |
300
|
|
|
|
301
|
|
|
$item = $item->fromArray( $entries, true ); |
302
|
|
|
|
303
|
|
|
$this->assertEquals( [], $entries ); |
304
|
|
|
|
305
|
|
|
$this->assertEquals( $list['common.lists.id'], $item->getId() ); |
306
|
|
|
$this->assertEquals( $list['common.lists.parentid'], $item->getParentId() ); |
307
|
|
|
$this->assertEquals( $list['common.lists.type'], $item->getType() ); |
308
|
|
|
$this->assertEquals( $list['common.lists.domain'], $item->getDomain() ); |
309
|
|
|
$this->assertEquals( $list['common.lists.refid'], $item->getRefId() ); |
310
|
|
|
$this->assertEquals( $list['common.lists.config'], $item->getConfig() ); |
311
|
|
|
$this->assertEquals( $list['common.lists.position'], $item->getPosition() ); |
312
|
|
|
$this->assertEquals( $list['common.lists.status'], $item->getStatus() ); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
|
316
|
|
|
public function testToArray() |
317
|
|
|
{ |
318
|
|
|
$expected = array( |
319
|
|
|
'common.lists.id' => '8', |
320
|
|
|
'common.lists.siteid' => 99, |
321
|
|
|
'common.lists.parentid' => 2, |
322
|
|
|
'common.lists.key' => 'testDomain|test|unitId', |
323
|
|
|
'common.lists.domain' => 'testDomain', |
324
|
|
|
'common.lists.refid' => 'unitId', |
325
|
|
|
'common.lists.datestart' => '2005-01-01 00:00:00', |
326
|
|
|
'common.lists.dateend' => '2010-12-31 00:00:00', |
327
|
|
|
'common.lists.config' => array( 'cnt' => '40' ), |
328
|
|
|
'common.lists.position' => 7, |
329
|
|
|
'common.lists.status' => 1, |
330
|
|
|
'common.lists.ctime' => '2011-01-01 00:00:01', |
331
|
|
|
'common.lists.mtime' => '2011-01-01 00:00:02', |
332
|
|
|
'common.lists.editor' => 'unitTestUser', |
333
|
|
|
'common.lists.type' => 'test', |
334
|
|
|
); |
335
|
|
|
|
336
|
|
|
$this->assertEquals( $expected, $this->object->toArray( true ) ); |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|