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-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Catalog\Item; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $node; |
15
|
|
|
private $object; |
16
|
|
|
private $values; |
17
|
|
|
private $listItems; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$listValues = array( 'id' => 1, 'type' => 'default', 'domain' => 'text' ); |
23
|
|
|
$this->listItems = array( 1 => new \Aimeos\MShop\Common\Item\Lists\Standard( 'catalog.lists.', $listValues ) ); |
24
|
|
|
|
25
|
|
|
$this->values = array( |
26
|
|
|
'id' => 2, |
27
|
|
|
'parentid' => 3, |
28
|
|
|
'level' => 1, |
29
|
|
|
'code' => 'unit-test', |
30
|
|
|
'label' => 'unittest', |
31
|
|
|
'config' => array( 'testcategory' => '10' ), |
32
|
|
|
'status' => 1, |
33
|
|
|
'siteid' => '99', |
34
|
|
|
'mtime' => '2011-01-01 00:00:02', |
35
|
|
|
'ctime' => '2011-01-01 00:00:01', |
36
|
|
|
'editor' => 'unitTestUser', |
37
|
|
|
'target' => 'testtarget', |
38
|
|
|
'hasChildren' => true |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
$this->node = new \Aimeos\MW\Tree\Node\Standard( $this->values ); |
42
|
|
|
$child = new \Aimeos\MShop\Catalog\Item\Standard( $this->node ); |
43
|
|
|
|
44
|
|
|
$this->object = new \Aimeos\MShop\Catalog\Item\Standard( $this->node, array( $child ), $this->listItems ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
protected function tearDown() |
49
|
|
|
{ |
50
|
|
|
unset( $this->object ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testGetId() |
55
|
|
|
{ |
56
|
|
|
$this->assertEquals( 2, $this->object->getId() ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
public function testSetId() |
61
|
|
|
{ |
62
|
|
|
$return = $this->object->setId( 5 ); |
63
|
|
|
|
64
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $return ); |
65
|
|
|
$this->assertEquals( 5, $this->object->getId() ); |
66
|
|
|
$this->assertFalse( $this->object->isModified() ); |
67
|
|
|
|
68
|
|
|
$return = $this->object->setId( null ); |
69
|
|
|
|
70
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $return ); |
71
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
72
|
|
|
$this->assertTrue( $this->object->isModified() ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testGetParentId() |
77
|
|
|
{ |
78
|
|
|
$this->assertEquals( 3, $this->object->getParentId() ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testGetCode() |
83
|
|
|
{ |
84
|
|
|
$this->assertEquals( 'unit-test', $this->object->getCode() ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
public function testSetCode() |
89
|
|
|
{ |
90
|
|
|
$return = $this->object->setCode( 'unit test' ); |
91
|
|
|
|
92
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $return ); |
93
|
|
|
$this->assertEquals( 'unit test', $this->object->getCode() ); |
94
|
|
|
$this->assertTrue( $this->object->isModified() ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
public function testGetLevel() |
99
|
|
|
{ |
100
|
|
|
$this->assertEquals( 1, $this->object->getLevel() ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
public function testGetLabel() |
105
|
|
|
{ |
106
|
|
|
$this->assertEquals( 'unittest', $this->object->getLabel() ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
public function testSetLabel() |
111
|
|
|
{ |
112
|
|
|
$return = $this->object->setLabel( 'unit test' ); |
113
|
|
|
|
114
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $return ); |
115
|
|
|
$this->assertEquals( 'unit test', $this->object->getLabel() ); |
116
|
|
|
$this->assertTrue( $this->object->isModified() ); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
|
120
|
|
|
public function testGetConfig() |
121
|
|
|
{ |
122
|
|
|
$this->assertEquals( array( 'testcategory' => '10' ), $this->object->getConfig() ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
public function testSetConfig() |
127
|
|
|
{ |
128
|
|
|
$return = $this->object->setConfig( array( 'unitcategory' => '12' ) ); |
129
|
|
|
|
130
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $return ); |
131
|
|
|
$this->assertEquals( array( 'unitcategory' => '12' ), $this->object->getConfig() ); |
132
|
|
|
$this->assertTrue( $this->object->isModified() ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
public function testGetStatus() |
137
|
|
|
{ |
138
|
|
|
$this->assertEquals( 1, $this->object->getStatus() ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
public function testSetStatus() |
143
|
|
|
{ |
144
|
|
|
$return = $this->object->setStatus( 0 ); |
145
|
|
|
|
146
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $return ); |
147
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
148
|
|
|
$this->assertTrue( $this->object->isModified() ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
public function testGetTarget() |
153
|
|
|
{ |
154
|
|
|
$this->assertEquals( 'testtarget', $this->object->getTarget() ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testSetTarget() |
159
|
|
|
{ |
160
|
|
|
$return = $this->object->setTarget( 'ttarget' ); |
161
|
|
|
|
162
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $return ); |
163
|
|
|
$this->assertEquals( 'ttarget', $this->object->getTarget() ); |
164
|
|
|
$this->assertTrue( $this->object->isModified() ); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
public function testGetSiteid() |
169
|
|
|
{ |
170
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
public function testGetTimeModified() |
175
|
|
|
{ |
176
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
public function testGetTimeCreated() |
181
|
|
|
{ |
182
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
public function testGetEditor() |
187
|
|
|
{ |
188
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->getEditor() ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
public function testIsModified() |
193
|
|
|
{ |
194
|
|
|
$this->assertFalse( $this->object->isModified() ); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
public function testGetResourceType() |
199
|
|
|
{ |
200
|
|
|
$this->assertEquals( 'catalog', $this->object->getResourceType() ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
public function testFromArray() |
205
|
|
|
{ |
206
|
|
|
$item = new \Aimeos\MShop\Catalog\Item\Standard( new \Aimeos\MW\Tree\Node\Standard() ); |
207
|
|
|
|
208
|
|
|
$list = array( |
209
|
|
|
'catalog.id' => 1, |
210
|
|
|
'catalog.code' => 'test', |
211
|
|
|
'catalog.config' => array( 'test' ), |
212
|
|
|
'catalog.label' => 'test item', |
213
|
|
|
'catalog.status' => '0', |
214
|
|
|
'catalog.target' => 'ttarget', |
215
|
|
|
); |
216
|
|
|
|
217
|
|
|
$unknown = $item->fromArray( $list ); |
218
|
|
|
|
219
|
|
|
$this->assertEquals( [], $unknown ); |
220
|
|
|
|
221
|
|
|
$this->assertEquals( $list['catalog.id'], $item->getId() ); |
222
|
|
|
$this->assertEquals( $list['catalog.code'], $item->getCode() ); |
223
|
|
|
$this->assertEquals( $list['catalog.config'], $item->getConfig() ); |
224
|
|
|
$this->assertEquals( $list['catalog.status'], $item->getStatus() ); |
225
|
|
|
$this->assertEquals( $list['catalog.label'], $item->getLabel() ); |
226
|
|
|
$this->assertEquals( $list['catalog.target'], $item->getTarget() ); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
public function testToArray() |
231
|
|
|
{ |
232
|
|
|
$values = $this->object->toArray( true ); |
233
|
|
|
|
234
|
|
|
$this->assertEquals( count( $this->values ), count( $values ) ); |
235
|
|
|
|
236
|
|
|
$this->assertEquals( $this->values['id'], $values['catalog.id'] ); |
237
|
|
|
$this->assertEquals( $this->values['level'], $values['catalog.level'] ); |
238
|
|
|
$this->assertEquals( $this->values['parentid'], $values['catalog.parentid'] ); |
239
|
|
|
$this->assertEquals( $this->values['label'], $values['catalog.label'] ); |
240
|
|
|
$this->assertEquals( $this->values['config'], $values['catalog.config'] ); |
241
|
|
|
$this->assertEquals( $this->values['status'], $values['catalog.status'] ); |
242
|
|
|
$this->assertEquals( $this->values['siteid'], $values['catalog.siteid'] ); |
243
|
|
|
$this->assertEquals( $this->values['code'], $values['catalog.code'] ); |
244
|
|
|
$this->assertEquals( $this->values['ctime'], $values['catalog.ctime'] ); |
245
|
|
|
$this->assertEquals( $this->values['mtime'], $values['catalog.mtime'] ); |
246
|
|
|
$this->assertEquals( $this->values['editor'], $values['catalog.editor'] ); |
247
|
|
|
$this->assertEquals( $this->values['target'], $values['catalog.target'] ); |
248
|
|
|
$this->assertEquals( $this->values['hasChildren'], $values['catalog.hasChildren'] ); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
public function testHasChildren() |
253
|
|
|
{ |
254
|
|
|
$this->assertTrue( $this->object->hasChildren() ); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
public function testGetChildren() |
259
|
|
|
{ |
260
|
|
|
$children = $this->object->getChildren(); |
261
|
|
|
$this->assertEquals( 1, count( $children ) ); |
262
|
|
|
|
263
|
|
|
foreach( $children as $child ) { |
264
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Catalog\\Item\\Iface', $child ); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
|
269
|
|
|
public function testAddChild() |
270
|
|
|
{ |
271
|
|
|
$return = $this->object->addChild( $this->object ); |
272
|
|
|
|
273
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Catalog\Item\Iface', $return ); |
274
|
|
|
$this->assertEquals( 2, count( $this->object->getChildren() ) ); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
|
278
|
|
|
public function testGetChild() |
279
|
|
|
{ |
280
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Catalog\\Item\\Iface', $this->object->getChild( 0 ) ); |
281
|
|
|
|
282
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Catalog\\Exception' ); |
283
|
|
|
$this->object->getChild( 1 ); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
|
287
|
|
|
public function testGetNode() |
288
|
|
|
{ |
289
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Tree\\Node\\Iface', $this->object->getNode() ); |
290
|
|
|
} |
291
|
|
|
} |
292
|
|
|
|