1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Common\Item\ListRef; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class Test extends \Aimeos\MShop\Common\Item\ListRef\Base |
14
|
|
|
{ |
15
|
|
|
public function getLabel() |
16
|
|
|
{ |
17
|
|
|
return 'test label'; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function getResourceType() |
21
|
|
|
{ |
22
|
|
|
return ''; |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
private $object; |
31
|
|
|
private $textItem1; |
32
|
|
|
private $textItem2; |
33
|
|
|
private $listItem1; |
34
|
|
|
private $listItem2; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
protected function setUp() |
38
|
|
|
{ |
39
|
|
|
$values = ['languageid' => null, 'text.status' => 1]; |
40
|
|
|
|
41
|
|
|
$this->textItem1 = new \Aimeos\MShop\Text\Item\Standard( array( 'text.type' => 'name' ) + $values ); |
42
|
|
|
$this->textItem1->setContent( 'test name' ); |
43
|
|
|
$this->textItem1->setStatus( 1 ); |
44
|
|
|
$this->textItem1->setId( 1 ); |
45
|
|
|
|
46
|
|
|
$this->textItem2 = new \Aimeos\MShop\Text\Item\Standard( array( 'text.type' => 'short' ) + $values ); |
47
|
|
|
$this->textItem2->setContent( 'default name' ); |
48
|
|
|
$this->textItem2->setStatus( 1 ); |
49
|
|
|
$this->textItem2->setId( 2 ); |
50
|
|
|
|
51
|
|
|
$this->listItem1 = new \Aimeos\MShop\Common\Item\Lists\Standard( 'text.lists.', array( 'text.lists.type' => 'test' ) + $values ); |
52
|
|
|
$this->listItem1->setRefId( $this->textItem1->getId() ); |
53
|
|
|
$this->listItem1->setDomain( 'text' ); |
54
|
|
|
$this->listItem1->setPosition( 1 ); |
55
|
|
|
$this->listItem1->setStatus( 1 ); |
56
|
|
|
$this->listItem1->setId( 11 ); |
57
|
|
|
|
58
|
|
|
$this->listItem2 = new \Aimeos\MShop\Common\Item\Lists\Standard( 'text.lists.', array( 'text.lists.type' => 'default' ) + $values ); |
59
|
|
|
$this->listItem2->setRefId( $this->textItem2->getId() ); |
60
|
|
|
$this->listItem2->setDomain( 'text' ); |
61
|
|
|
$this->listItem2->setPosition( 0 ); |
62
|
|
|
$this->listItem2->setStatus( 1 ); |
63
|
|
|
$this->listItem2->setId( 10 ); |
64
|
|
|
|
65
|
|
|
$listItems = array( 'text' => array( |
66
|
|
|
$this->listItem1->getId() => $this->listItem1, |
67
|
|
|
$this->listItem2->getId() => $this->listItem2, |
68
|
|
|
) ); |
69
|
|
|
|
70
|
|
|
$refItems = array( 'text' => array( |
71
|
|
|
$this->textItem1->getId() => $this->textItem1, |
72
|
|
|
$this->textItem2->getId() => $this->textItem2, |
73
|
|
|
) ); |
74
|
|
|
|
75
|
|
|
$this->object = new \Aimeos\MShop\Common\Item\ListRef\Test( 'text.', [], $listItems, $refItems ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
protected function tearDown() |
80
|
|
|
{ |
81
|
|
|
unset( $this->object ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testAddListItem() |
86
|
|
|
{ |
87
|
|
|
$this->object->addListItem( 'test', $this->listItem1, $this->textItem1 ); |
88
|
|
|
|
89
|
|
|
$this->assertEquals( [11 => $this->listItem1], $this->object->getListItems( 'test' ) ); |
90
|
|
|
$this->assertEquals( [1 => $this->textItem1], $this->object->getRefItems( 'test' ) ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
public function testAddListItemNew() |
95
|
|
|
{ |
96
|
|
|
$this->object->addListItem( 'test', $this->listItem1->setId( null ), $this->textItem1->setId( null ) ); |
97
|
|
|
|
98
|
|
|
$this->assertEquals( ['tmp-0' => $this->listItem1], $this->object->getListItems( 'test' ) ); |
99
|
|
|
$this->assertEquals( ['tmp-1' => $this->textItem1], $this->object->getRefItems( 'test' ) ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
public function testDeleteListItem() |
104
|
|
|
{ |
105
|
|
|
$this->object->deleteListItem( 'text', $this->listItem1, $this->textItem1 ); |
106
|
|
|
|
107
|
|
|
$this->assertEquals( [$this->listItem1], $this->object->getListItemsDeleted() ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function testDeleteListItems() |
112
|
|
|
{ |
113
|
|
|
$this->object->deleteListItems( [$this->listItem1, $this->listItem2] ); |
114
|
|
|
|
115
|
|
|
$this->assertEquals( [$this->listItem1, $this->listItem2], $this->object->getListItemsDeleted() ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testDeleteListItemException() |
120
|
|
|
{ |
121
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Exception' ); |
122
|
|
|
$this->object->deleteListItem( 'test', $this->listItem1 ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
|
126
|
|
|
public function testGetListItemsDeleted() |
127
|
|
|
{ |
128
|
|
|
$this->assertEquals( [], $this->object->getListItemsDeleted() ); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
public function testGetName() |
133
|
|
|
{ |
134
|
|
|
$object = new \Aimeos\MShop\Common\Item\ListRef\Test( '' ); |
135
|
|
|
|
136
|
|
|
$this->assertEquals( 'test label', $object->getName() ); |
137
|
|
|
$this->assertEquals( 'test name', $this->object->getName() ); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
public function testGetListItem() |
142
|
|
|
{ |
143
|
|
|
$result = $this->object->getListItem( 'text', 'default', 2 ); |
144
|
|
|
|
145
|
|
|
$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $result ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
public function testGetListItems() |
150
|
|
|
{ |
151
|
|
|
$result = $this->object->getListItems(); |
152
|
|
|
$expected = array( |
153
|
|
|
$this->listItem2->getId() => $this->listItem2, |
154
|
|
|
$this->listItem1->getId() => $this->listItem1, |
155
|
|
|
); |
156
|
|
|
|
157
|
|
|
$this->assertEquals( $expected, $result ); |
158
|
|
|
|
159
|
|
|
foreach( $result as $listItem ) { |
160
|
|
|
$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem ); |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
public function testGetListItemsWithDomain() |
166
|
|
|
{ |
167
|
|
|
$result = $this->object->getListItems( 'text' ); |
168
|
|
|
$expected = array( |
169
|
|
|
$this->listItem2->getId() => $this->listItem2, |
170
|
|
|
$this->listItem1->getId() => $this->listItem1, |
171
|
|
|
); |
172
|
|
|
|
173
|
|
|
$this->assertEquals( $expected, $result ); |
174
|
|
|
|
175
|
|
|
foreach( $result as $listItem ) { |
176
|
|
|
$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $listItem ); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$this->assertEquals( [], $this->object->getListItems( 'undefined' ) ); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
public function testGetListItemsWithListtype() |
184
|
|
|
{ |
185
|
|
|
$result = $this->object->getListItems( 'text', 'test' ); |
186
|
|
|
$expected = array( $this->listItem1->getId() => $this->listItem1 ); |
187
|
|
|
|
188
|
|
|
$this->assertEquals( $expected, $result ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
public function testGetListItemsWithListtypes() |
193
|
|
|
{ |
194
|
|
|
$result = $this->object->getListItems( 'text', array( 'test' ) ); |
195
|
|
|
$expected = array( $this->listItem1->getId() => $this->listItem1 ); |
196
|
|
|
|
197
|
|
|
$this->assertEquals( $expected, $result ); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
public function testGetListItemsWithType() |
202
|
|
|
{ |
203
|
|
|
$result = $this->object->getListItems( 'text', null, 'name' ); |
204
|
|
|
$expected = array( $this->listItem1->getId() => $this->listItem1 ); |
205
|
|
|
|
206
|
|
|
$this->assertEquals( $expected, $result ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
public function testGetListItemsWithTypes() |
211
|
|
|
{ |
212
|
|
|
$result = $this->object->getListItems( 'text', null, array( 'name', 'short' ) ); |
213
|
|
|
$expected = array( |
214
|
|
|
$this->listItem1->getId() => $this->listItem1, |
215
|
|
|
$this->listItem2->getId() => $this->listItem2, |
216
|
|
|
); |
217
|
|
|
|
218
|
|
|
$this->assertEquals( $expected, $result ); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
|
222
|
|
|
public function testGetListItemsWithRefItems() |
223
|
|
|
{ |
224
|
|
|
$result = $this->object->getListItems( 'text' ); |
225
|
|
|
$expected = array( |
226
|
|
|
$this->textItem2->getId() => $this->textItem2, |
227
|
|
|
$this->textItem1->getId() => $this->textItem1, |
228
|
|
|
); |
229
|
|
|
|
230
|
|
|
foreach( $result as $listItem ) |
231
|
|
|
{ |
232
|
|
|
$this->assertInstanceof( '\\Aimeos\\MShop\\Text\\Item\\Iface', $listItem->getRefItem() ); |
233
|
|
|
$this->assertSame( $expected[$listItem->getRefId()], $listItem->getRefItem() ); |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
public function testGetRefItems() |
239
|
|
|
{ |
240
|
|
|
$result = $this->object->getRefItems(); |
241
|
|
|
$expected = array( |
242
|
|
|
'text' => array( |
243
|
|
|
$this->textItem2->getId() => $this->textItem2, |
244
|
|
|
$this->textItem1->getId() => $this->textItem1, |
245
|
|
|
) |
246
|
|
|
); |
247
|
|
|
|
248
|
|
|
$this->assertEquals( $expected, $result ); |
249
|
|
|
|
250
|
|
|
foreach( $result as $domain => $list ) |
251
|
|
|
{ |
252
|
|
|
foreach( $list as $item ) { |
253
|
|
|
$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Iface', $item ); |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
public function testGetRefItemsWithDomain() |
260
|
|
|
{ |
261
|
|
|
$result = $this->object->getRefItems( 'text' ); |
262
|
|
|
$expected = array( |
263
|
|
|
$this->textItem2->getId() => $this->textItem2, |
264
|
|
|
$this->textItem1->getId() => $this->textItem1, |
265
|
|
|
); |
266
|
|
|
|
267
|
|
|
$this->assertEquals( $expected, $result ); |
268
|
|
|
|
269
|
|
|
foreach( $result as $item ) { |
270
|
|
|
$this->assertInstanceof( '\\Aimeos\\MShop\\Common\\Item\\Iface', $item ); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
$this->assertEquals( [], $this->object->getRefItems( 'undefined' ) ); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
public function testGetRefItemsWithType() |
278
|
|
|
{ |
279
|
|
|
$result = $this->object->getRefItems( 'text', 'name' ); |
280
|
|
|
$expected = array( $this->textItem1->getId() => $this->textItem1 ); |
281
|
|
|
|
282
|
|
|
$this->assertEquals( $expected, $result ); |
283
|
|
|
$this->assertEquals( [], $this->object->getRefItems( 'text', 'undefined' ) ); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
|
287
|
|
|
public function testGetRefItemsWithTypes() |
288
|
|
|
{ |
289
|
|
|
$result = $this->object->getRefItems( 'text', array( 'short', 'name' ) ); |
290
|
|
|
$expected = array( |
291
|
|
|
$this->textItem2->getId() => $this->textItem2, |
292
|
|
|
$this->textItem1->getId() => $this->textItem1, |
293
|
|
|
); |
294
|
|
|
|
295
|
|
|
$this->assertEquals( $expected, $result ); |
296
|
|
|
$this->assertEquals( [], $this->object->getRefItems( 'text', 'undefined' ) ); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
|
300
|
|
|
public function testGetRefItemsWithTypeAndListtype() |
301
|
|
|
{ |
302
|
|
|
$result = $this->object->getRefItems( 'text', 'name', 'test' ); |
303
|
|
|
$expected = array( $this->textItem1->getId() => $this->textItem1 ); |
304
|
|
|
|
305
|
|
|
$this->assertEquals( $expected, $result ); |
306
|
|
|
$this->assertEquals( [], $this->object->getRefItems( 'text', 'name', 'undefined' ) ); |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.