|
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-2022 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Locale\Item\Site; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $object; |
|
15
|
|
|
private $values; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() : void |
|
19
|
|
|
{ |
|
20
|
|
|
$this->values = array( |
|
21
|
|
|
'locale.site.id' => 12, |
|
22
|
|
|
'locale.site.siteid' => 12, |
|
23
|
|
|
'locale.site.code' => 'ExtID', |
|
24
|
|
|
'locale.site.label' => 'My Site', |
|
25
|
|
|
'locale.site.config' => array( 'timezone' => 'Europe/Berlin' ), |
|
26
|
|
|
'locale.site.icon' => 'path/to/site-icon.png', |
|
27
|
|
|
'locale.site.logo' => [1 => 'path/to/site-logo.png'], |
|
28
|
|
|
'locale.site.rating' => '4.80', |
|
29
|
|
|
'locale.site.ratings' => 5, |
|
30
|
|
|
'locale.site.refid' => '1234', |
|
31
|
|
|
'locale.site.theme' => 'elegance', |
|
32
|
|
|
'locale.site.status' => 1, |
|
33
|
|
|
'locale.site.mtime' => '2011-01-01 00:00:02', |
|
34
|
|
|
'locale.site.ctime' => '2011-01-01 00:00:01', |
|
35
|
|
|
'locale.site.editor' => 'unitTestUser' |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
$children = array( new \Aimeos\MShop\Locale\Item\Site\Standard() ); |
|
39
|
|
|
$this->object = new \Aimeos\MShop\Locale\Item\Site\Standard( $this->values, $children ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
protected function tearDown() : void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->object = null; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
public function testIsModified() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->assertFalse( $this->object->isModified() ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function testGetId() |
|
56
|
|
|
{ |
|
57
|
|
|
$this->assertEquals( 12, $this->object->getId() ); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
public function testGetSiteId() |
|
62
|
|
|
{ |
|
63
|
|
|
$this->assertEquals( 12, $this->object->getSiteId() ); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testSetId() |
|
67
|
|
|
{ |
|
68
|
|
|
$return = $this->object->setId( null ); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
71
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
|
72
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
73
|
|
|
|
|
74
|
|
|
$return = $this->object->setId( 12 ); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
77
|
|
|
$this->assertFalse( $this->object->isModified() ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
public function testGetCode() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->assertEquals( 'ExtID', $this->object->getCode() ); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
public function testSetCode() |
|
88
|
|
|
{ |
|
89
|
|
|
$return = $this->object->setCode( 'OtherExtID' ); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
92
|
|
|
$this->assertEquals( 'OtherExtID', $this->object->getCode() ); |
|
93
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
public function testGetLabel() |
|
98
|
|
|
{ |
|
99
|
|
|
$this->assertEquals( 'My Site', $this->object->getLabel() ); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
public function testSetLabel() |
|
104
|
|
|
{ |
|
105
|
|
|
$return = $this->object->setLabel( 'Other Name' ); |
|
106
|
|
|
|
|
107
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
108
|
|
|
$this->assertEquals( 'Other Name', $this->object->getLabel() ); |
|
109
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
|
|
113
|
|
|
public function testGetIcon() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->assertEquals( 'path/to/site-icon.png', $this->object->getIcon() ); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
public function testSetIcon() |
|
120
|
|
|
{ |
|
121
|
|
|
$return = $this->object->setIcon( 'path/site-icon2.png' ); |
|
122
|
|
|
|
|
123
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
124
|
|
|
$this->assertEquals( 'path/site-icon2.png', $this->object->getIcon() ); |
|
125
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
public function testGetLogo() |
|
130
|
|
|
{ |
|
131
|
|
|
$this->assertEquals( 'path/to/site-logo.png', $this->object->getLogo() ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
public function testGetLogos() |
|
136
|
|
|
{ |
|
137
|
|
|
$this->assertEquals( [1 => 'path/to/site-logo.png'], $this->object->getLogos() ); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
public function testSetLogo() |
|
142
|
|
|
{ |
|
143
|
|
|
$return = $this->object->setLogo( '/path/site-logo2.png' ); |
|
144
|
|
|
|
|
145
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
146
|
|
|
$this->assertEquals( '/path/site-logo2.png', $this->object->getLogo() ); |
|
147
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
public function testSetLogos() |
|
152
|
|
|
{ |
|
153
|
|
|
$return = $this->object->setLogos( [1 => '/path/site-logo2.png'] ); |
|
154
|
|
|
|
|
155
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
156
|
|
|
$this->assertEquals( [1 => '/path/site-logo2.png'], $this->object->getLogos() ); |
|
157
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
public function testGetConfig() |
|
162
|
|
|
{ |
|
163
|
|
|
$this->assertEquals( array( 'timezone' => 'Europe/Berlin' ), $this->object->getConfig() ); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
public function testGetConfigValue() |
|
168
|
|
|
{ |
|
169
|
|
|
$this->assertEquals( 'Europe/Berlin', $this->object->getConfigValue( 'timezone' ) ); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
public function testSetConfig() |
|
174
|
|
|
{ |
|
175
|
|
|
$return = $this->object->setConfig( array( 'timezone' => 'Europe/Paris' ) ); |
|
176
|
|
|
|
|
177
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
178
|
|
|
$this->assertEquals( array( 'timezone' => 'Europe/Paris' ), $this->object->getConfig() ); |
|
179
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
|
|
183
|
|
|
public function testGetRating() |
|
184
|
|
|
{ |
|
185
|
|
|
$this->assertEquals( '4.80', $this->object->getRating() ); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
|
|
189
|
|
|
public function testGetRatings() |
|
190
|
|
|
{ |
|
191
|
|
|
$this->assertEquals( 5, $this->object->getRatings() ); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
|
|
195
|
|
|
public function testGetRefId() |
|
196
|
|
|
{ |
|
197
|
|
|
$this->assertEquals( '1234', $this->object->getRefId() ); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
|
|
201
|
|
|
public function testSetRefId() |
|
202
|
|
|
{ |
|
203
|
|
|
$return = $this->object->setRefId( '5678' ); |
|
204
|
|
|
|
|
205
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
206
|
|
|
$this->assertEquals( '5678', $this->object->getRefId() ); |
|
207
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
|
|
211
|
|
|
public function testGetStatus() |
|
212
|
|
|
{ |
|
213
|
|
|
$this->assertEquals( 1, $this->object->getStatus() ); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
|
|
217
|
|
|
public function testSetStatus() |
|
218
|
|
|
{ |
|
219
|
|
|
$return = $this->object->setStatus( 0 ); |
|
220
|
|
|
|
|
221
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
222
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
|
223
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
|
|
227
|
|
|
public function testGetTheme() |
|
228
|
|
|
{ |
|
229
|
|
|
$this->assertEquals( 'elegance', $this->object->getTheme() ); |
|
230
|
|
|
} |
|
231
|
|
|
|
|
232
|
|
|
|
|
233
|
|
|
public function testSetTheme() |
|
234
|
|
|
{ |
|
235
|
|
|
$return = $this->object->setTheme( 'shop' ); |
|
236
|
|
|
|
|
237
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $return ); |
|
238
|
|
|
$this->assertEquals( 'shop', $this->object->getTheme() ); |
|
239
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
|
|
243
|
|
|
public function testGetTimeModified() |
|
244
|
|
|
{ |
|
245
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
|
|
249
|
|
|
public function testGetTimeCreated() |
|
250
|
|
|
{ |
|
251
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
|
|
255
|
|
|
public function testGetEditor() |
|
256
|
|
|
{ |
|
257
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->editor() ); |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
|
|
261
|
|
|
public function testGetResourceType() |
|
262
|
|
|
{ |
|
263
|
|
|
$this->assertEquals( 'locale/site', $this->object->getResourceType() ); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
|
|
267
|
|
|
public function testIsAvailable() |
|
268
|
|
|
{ |
|
269
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
270
|
|
|
$this->object->setAvailable( false ); |
|
271
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
|
|
275
|
|
|
public function testIsAvailableOnStatus() |
|
276
|
|
|
{ |
|
277
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
278
|
|
|
$this->object->setStatus( 0 ); |
|
279
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
280
|
|
|
$this->object->setStatus( -1 ); |
|
281
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
|
|
285
|
|
|
public function testFromArray() |
|
286
|
|
|
{ |
|
287
|
|
|
$item = new \Aimeos\MShop\Locale\Item\Site\Standard(); |
|
288
|
|
|
|
|
289
|
|
|
$list = $entries = array( |
|
290
|
|
|
'locale.site.id' => 2, |
|
291
|
|
|
'locale.site.code' => 'test', |
|
292
|
|
|
'locale.site.label' => 'test item', |
|
293
|
|
|
'locale.site.status' => 1, |
|
294
|
|
|
'locale.site.config' => ['test'], |
|
295
|
|
|
'locale.site.icon' => 'site-icon.jpg', |
|
296
|
|
|
'locale.site.logo' => [1 => 'site-logo.jpg'], |
|
297
|
|
|
'locale.site.refid' => '9876', |
|
298
|
|
|
'locale.site.theme' => 'shop', |
|
299
|
|
|
); |
|
300
|
|
|
|
|
301
|
|
|
$item = $item->fromArray( $entries, true ); |
|
302
|
|
|
|
|
303
|
|
|
$this->assertEquals( [], $entries ); |
|
304
|
|
|
$this->assertEquals( $list['locale.site.id'], $item->getId() ); |
|
305
|
|
|
$this->assertEquals( $list['locale.site.code'], $item->getCode() ); |
|
306
|
|
|
$this->assertEquals( $list['locale.site.label'], $item->getLabel() ); |
|
307
|
|
|
$this->assertEquals( $list['locale.site.status'], $item->getStatus() ); |
|
308
|
|
|
$this->assertEquals( $list['locale.site.config'], $item->getConfig() ); |
|
309
|
|
|
$this->assertEquals( $list['locale.site.refid'], $item->getRefId() ); |
|
310
|
|
|
$this->assertEquals( $list['locale.site.theme'], $item->getTheme() ); |
|
311
|
|
|
$this->assertEquals( $list['locale.site.logo'], $item->getLogos() ); |
|
312
|
|
|
$this->assertEquals( $list['locale.site.icon'], $item->getIcon() ); |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
|
|
316
|
|
|
public function testToArray() |
|
317
|
|
|
{ |
|
318
|
|
|
$arrayObject = $this->object->toArray( true ); |
|
319
|
|
|
|
|
320
|
|
|
$this->assertEquals( count( $this->values ) + 3, count( $arrayObject ) ); |
|
321
|
|
|
|
|
322
|
|
|
$this->assertEquals( $this->object->getId(), $arrayObject['locale.site.id'] ); |
|
323
|
|
|
$this->assertEquals( $this->object->getSiteId(), $arrayObject['locale.site.siteid'] ); |
|
324
|
|
|
$this->assertEquals( $this->object->getCode(), $arrayObject['locale.site.code'] ); |
|
325
|
|
|
$this->assertEquals( $this->object->getLabel(), $arrayObject['locale.site.label'] ); |
|
326
|
|
|
$this->assertEquals( $this->object->getStatus(), $arrayObject['locale.site.status'] ); |
|
327
|
|
|
$this->assertEquals( $this->object->getConfig(), $arrayObject['locale.site.config'] ); |
|
328
|
|
|
$this->assertEquals( $this->object->getLogos(), $arrayObject['locale.site.logo'] ); |
|
329
|
|
|
$this->assertEquals( $this->object->getIcon(), $arrayObject['locale.site.icon'] ); |
|
330
|
|
|
$this->assertEquals( $this->object->getTheme(), $arrayObject['locale.site.theme'] ); |
|
331
|
|
|
$this->assertEquals( $this->object->getRefId(), $arrayObject['locale.site.refid'] ); |
|
332
|
|
|
$this->assertEquals( $this->object->getRating(), $arrayObject['locale.site.rating'] ); |
|
333
|
|
|
$this->assertEquals( $this->object->getRatings(), $arrayObject['locale.site.ratings'] ); |
|
334
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['locale.site.ctime'] ); |
|
335
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $arrayObject['locale.site.mtime'] ); |
|
336
|
|
|
$this->assertEquals( $this->object->editor(), $arrayObject['locale.site.editor'] ); |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
|
|
340
|
|
|
public function testAddChild() |
|
341
|
|
|
{ |
|
342
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Tree\Iface::class, $this->object->addChild( $this->object ) ); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
|
|
346
|
|
|
public function testDeleteChild() |
|
347
|
|
|
{ |
|
348
|
|
|
$result = $this->object->deleteChild( $this->object ); |
|
349
|
|
|
|
|
350
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $result ); |
|
351
|
|
|
$this->assertEquals( 0, count( $this->object->getChildren() ) ); |
|
352
|
|
|
} |
|
353
|
|
|
|
|
354
|
|
|
|
|
355
|
|
|
public function testGetChild() |
|
356
|
|
|
{ |
|
357
|
|
|
$this->expectException( \Aimeos\MShop\Locale\Exception::class ); |
|
358
|
|
|
$this->object->getChild( 0 ); |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
|
|
362
|
|
|
public function testGetChildren() |
|
363
|
|
|
{ |
|
364
|
|
|
$this->assertInstanceOf( \Aimeos\Map::class, $this->object->getChildren() ); |
|
365
|
|
|
$this->assertEquals( [], $this->object->getChildren()->toArray() ); |
|
366
|
|
|
} |
|
367
|
|
|
|
|
368
|
|
|
|
|
369
|
|
|
public function testGetChildrenDeleted() |
|
370
|
|
|
{ |
|
371
|
|
|
$result = $this->object->getChildrenDeleted(); |
|
372
|
|
|
|
|
373
|
|
|
$this->assertInstanceOf( \Aimeos\Map::class, $result ); |
|
374
|
|
|
$this->assertEquals( [], $result->toArray() ); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
|
|
378
|
|
|
public function testToList() |
|
379
|
|
|
{ |
|
380
|
|
|
$list = $this->object->toList(); |
|
381
|
|
|
|
|
382
|
|
|
$this->assertEquals( 1, count( $list ) ); |
|
383
|
|
|
$this->assertInstanceOf( \Aimeos\Map::class, $list ); |
|
384
|
|
|
$this->assertEquals( [$this->object->getId() => $this->object], $list->toArray() ); |
|
385
|
|
|
} |
|
386
|
|
|
|
|
387
|
|
|
|
|
388
|
|
|
public function testHasChildren() |
|
389
|
|
|
{ |
|
390
|
|
|
$this->assertFalse( $this->object->hasChildren() ); |
|
391
|
|
|
} |
|
392
|
|
|
} |
|
393
|
|
|
|