|
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
|
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Locale\Manager\Site; |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
private $context; |
|
16
|
|
|
private $object; |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
protected function setUp() : void |
|
20
|
|
|
{ |
|
21
|
|
|
$this->context = \TestHelper::context(); |
|
22
|
|
|
$this->object = new \Aimeos\MShop\Locale\Manager\Site\Standard( $this->context ); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
protected function tearDown() : void |
|
27
|
|
|
{ |
|
28
|
|
|
$this->object = null; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
public function testClear() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function testDeleteItems() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->delete( [-1] ) ); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
public function testCreateItem() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $this->object->create() ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
public function testSaveIdException() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->expectException( \Aimeos\MShop\Locale\Exception::class ); |
|
53
|
|
|
$this->object->save( $this->object->create() ); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
public function testSaveUpdateDeleteItem() |
|
58
|
|
|
{ |
|
59
|
|
|
$item = $this->object->create(); |
|
60
|
|
|
$item->setLabel( 'new name' ); |
|
61
|
|
|
$item->setStatus( 1 ); |
|
62
|
|
|
$item->setCode( 'xx' ); |
|
63
|
|
|
$resultSaved = $this->object->insert( $item ); |
|
64
|
|
|
$itemSaved = $this->object->get( $item->getId() ); |
|
65
|
|
|
|
|
66
|
|
|
$itemExp = clone $itemSaved; |
|
67
|
|
|
$itemExp->setLabel( 'new new name' ); |
|
68
|
|
|
$resultUpd = $this->object->save( $itemExp ); |
|
69
|
|
|
$itemUpd = $this->object->get( $itemExp->getId() ); |
|
70
|
|
|
|
|
71
|
|
|
$this->object->delete( $item->getId() ); |
|
72
|
|
|
|
|
73
|
|
|
$context = \TestHelper::context(); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertTrue( $item->getId() !== null ); |
|
76
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
|
77
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
|
78
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
|
79
|
|
|
$this->assertEquals( $item->getCode(), $itemSaved->getCode() ); |
|
80
|
|
|
$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() ); |
|
81
|
|
|
$this->assertEquals( $item->getConfig(), $itemSaved->getConfig() ); |
|
82
|
|
|
$this->assertEquals( $item->getChildren(), $itemSaved->getChildren() ); |
|
83
|
|
|
$this->assertEquals( $item->getRefId(), $itemSaved->getRefId() ); |
|
84
|
|
|
$this->assertEquals( $item->getTheme(), $itemSaved->getTheme() ); |
|
85
|
|
|
$this->assertEquals( $item->getLogos(), $itemSaved->getLogos() ); |
|
86
|
|
|
$this->assertEquals( $item->getLogo(), $itemSaved->getLogo() ); |
|
87
|
|
|
$this->assertEquals( $item->getIcon(), $itemSaved->getIcon() ); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertEquals( $context->editor(), $itemSaved->editor() ); |
|
90
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
|
91
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
|
92
|
|
|
|
|
93
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
|
94
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
|
95
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
|
96
|
|
|
$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() ); |
|
97
|
|
|
$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() ); |
|
98
|
|
|
$this->assertEquals( $itemExp->getConfig(), $itemUpd->getConfig() ); |
|
99
|
|
|
$this->assertEquals( $itemExp->getChildren(), $itemUpd->getChildren() ); |
|
100
|
|
|
$this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() ); |
|
101
|
|
|
$this->assertEquals( $itemExp->getTheme(), $itemUpd->getTheme() ); |
|
102
|
|
|
$this->assertEquals( $itemExp->getLogos(), $itemUpd->getLogos() ); |
|
103
|
|
|
$this->assertEquals( $itemExp->getLogo(), $itemUpd->getLogo() ); |
|
104
|
|
|
$this->assertEquals( $itemExp->getIcon(), $itemUpd->getIcon() ); |
|
105
|
|
|
|
|
106
|
|
|
$this->assertEquals( $context->editor(), $itemUpd->editor() ); |
|
107
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
|
108
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
|
111
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
|
112
|
|
|
|
|
113
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
|
114
|
|
|
$this->object->get( $item->getId() ); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
public function testFindItem() |
|
119
|
|
|
{ |
|
120
|
|
|
$item = $this->object->find( 'unittest' ); |
|
121
|
|
|
|
|
122
|
|
|
$this->assertEquals( 'unittest', $item->getCode() ); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
public function testGetItem() |
|
127
|
|
|
{ |
|
128
|
|
|
$search = $this->object->filter()->slice( 0, 1 ); |
|
129
|
|
|
$search->setConditions( $search->compare( '==', 'locale.site.code', 'unittest' ) ); |
|
130
|
|
|
|
|
131
|
|
|
$a = $this->object->search( $search )->toArray(); |
|
132
|
|
|
if( ( $expected = reset( $a ) ) === false ) { |
|
133
|
|
|
throw new \RuntimeException( 'Site item not found' ); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
$actual = $this->object->get( $expected->getId() ); |
|
137
|
|
|
|
|
138
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $actual ); |
|
139
|
|
|
$this->assertEquals( $expected, $actual ); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
|
|
143
|
|
|
public function testRate() |
|
144
|
|
|
{ |
|
145
|
|
|
$item = $this->object->find( 'unittest' ); |
|
146
|
|
|
$result = $this->object->rate( $item->getId(), '4.00', 5 ); |
|
147
|
|
|
$item2 = $this->object->find( 'unittest' ); |
|
148
|
|
|
|
|
149
|
|
|
$this->object->rate( $item->getId(), $item->getRating(), $item->getRatings() ); |
|
150
|
|
|
|
|
151
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $result ); |
|
152
|
|
|
$this->assertEquals( '4.00', $item2->getRating() ); |
|
153
|
|
|
$this->assertEquals( 5, $item2->getRatings() ); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
|
|
157
|
|
|
public function testSearchItems() |
|
158
|
|
|
{ |
|
159
|
|
|
$siteid = $this->context->locale()->getSiteId(); |
|
160
|
|
|
|
|
161
|
|
|
$search = $this->object->filter(); |
|
162
|
|
|
|
|
163
|
|
|
$expr = []; |
|
164
|
|
|
$expr[] = $search->compare( '!=', 'locale.site.id', null ); |
|
165
|
|
|
$expr[] = $search->compare( '==', 'locale.site.siteid', $siteid ); |
|
166
|
|
|
$expr[] = $search->compare( '==', 'locale.site.code', 'unittest' ); |
|
167
|
|
|
$expr[] = $search->compare( '==', 'locale.site.label', 'Unit test site' ); |
|
168
|
|
|
$expr[] = $search->compare( '=~', 'locale.site.config', '{' ); |
|
169
|
|
|
$expr[] = $search->compare( '==', 'locale.site.icon', 'path/to/site-icon.png' ); |
|
170
|
|
|
$expr[] = $search->compare( '=~', 'locale.site.logo', '{' ); |
|
171
|
|
|
$expr[] = $search->compare( '==', 'locale.site.rating', '0.00' ); |
|
172
|
|
|
$expr[] = $search->compare( '==', 'locale.site.ratings', 0 ); |
|
173
|
|
|
$expr[] = $search->compare( '==', 'locale.site.refid', '1234' ); |
|
174
|
|
|
$expr[] = $search->compare( '==', 'locale.site.theme', 'shop' ); |
|
175
|
|
|
$expr[] = $search->compare( '==', 'locale.site.status', 1 ); |
|
176
|
|
|
$expr[] = $search->compare( '>=', 'locale.site.mtime', '1970-01-01 00:00:00' ); |
|
177
|
|
|
$expr[] = $search->compare( '>=', 'locale.site.ctime', '1970-01-01 00:00:00' ); |
|
178
|
|
|
$expr[] = $search->compare( '>=', 'locale.site.editor', '' ); |
|
179
|
|
|
|
|
180
|
|
|
$total = 0; |
|
181
|
|
|
$search->setConditions( $search->and( $expr ) ); |
|
182
|
|
|
$results = $this->object->search( $search, [], $total )->toArray(); |
|
183
|
|
|
|
|
184
|
|
|
$this->assertEquals( 1, count( $results ) ); |
|
185
|
|
|
$this->assertEquals( 1, $total ); |
|
186
|
|
|
|
|
187
|
|
|
//search with base criteria and total |
|
188
|
|
|
$search = $this->object->filter( true ); |
|
189
|
|
|
$search->setConditions( $search->compare( '==', 'locale.site.code', array( 'unittest' ) ) ); |
|
190
|
|
|
$search->slice( 0, 1 ); |
|
191
|
|
|
|
|
192
|
|
|
$results = $this->object->search( $search, [], $total )->toArray(); |
|
193
|
|
|
$this->assertEquals( 1, count( $results ) ); |
|
194
|
|
|
$this->assertGreaterThanOrEqual( 1, $total ); |
|
195
|
|
|
|
|
196
|
|
|
foreach( $results as $itemId => $item ) { |
|
197
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
|
|
202
|
|
|
public function testGetResourceType() |
|
203
|
|
|
{ |
|
204
|
|
|
$result = $this->object->getResourceType(); |
|
205
|
|
|
|
|
206
|
|
|
$this->assertContains( 'locale/site', $result ); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
public function testGetSearchAttributes() |
|
211
|
|
|
{ |
|
212
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
|
213
|
|
|
$this->assertInstanceOf( \Aimeos\Base\Criteria\Attribute\Iface::class, $attribute ); |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
|
|
218
|
|
|
public function testGetSubManager() |
|
219
|
|
|
{ |
|
220
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
|
221
|
|
|
$this->object->getSubManager( 'unknown' ); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
|
|
225
|
|
|
public function testGetPath() |
|
226
|
|
|
{ |
|
227
|
|
|
$search = $this->object->filter(); |
|
228
|
|
|
$search->setConditions( $search->compare( '==', 'locale.site.code', 'unittest' ) ); |
|
229
|
|
|
|
|
230
|
|
|
$results = $this->object->search( $search )->toArray(); |
|
231
|
|
|
|
|
232
|
|
|
if( ( $expected = reset( $results ) ) === false ) { |
|
233
|
|
|
throw new \RuntimeException( 'No item found' ); |
|
234
|
|
|
} |
|
235
|
|
|
|
|
236
|
|
|
$list = $this->object->getPath( $expected->getId() )->toArray(); |
|
237
|
|
|
$this->assertArrayHasKey( $expected->getId(), $list ); |
|
238
|
|
|
$this->assertEquals( $expected, $list[$expected->getId()] ); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
|
|
242
|
|
|
public function testGetTree() |
|
243
|
|
|
{ |
|
244
|
|
|
$search = $this->object->filter(); |
|
245
|
|
|
$search->setConditions( $search->compare( '==', 'locale.site.code', 'unittest' ) ); |
|
246
|
|
|
|
|
247
|
|
|
$expected = $this->object->search( $search )->first(); |
|
248
|
|
|
|
|
249
|
|
|
$item = $this->object->getTree( $expected->getId() ); |
|
250
|
|
|
$this->assertEquals( $expected, $item ); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
|
|
254
|
|
|
public function testGetTreeNoId() |
|
255
|
|
|
{ |
|
256
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Locale\Manager\Site\Standard::class ) |
|
257
|
|
|
->setConstructorArgs( array( $this->context ) ) |
|
258
|
|
|
->setMethods( array( 'search' ) ) |
|
259
|
|
|
->getMock(); |
|
260
|
|
|
|
|
261
|
|
|
$object->expects( $this->once() )->method( 'search' ) |
|
262
|
|
|
->will( $this->returnValue( map( [$object->create()] ) ) ); |
|
263
|
|
|
|
|
264
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $object->getTree() ); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
|
|
268
|
|
|
public function testGetTreeNoItem() |
|
269
|
|
|
{ |
|
270
|
|
|
$object = $this->getMockBuilder( \Aimeos\MShop\Locale\Manager\Site\Standard::class ) |
|
271
|
|
|
->setConstructorArgs( array( $this->context ) ) |
|
272
|
|
|
->setMethods( array( 'search' ) ) |
|
273
|
|
|
->getMock(); |
|
274
|
|
|
|
|
275
|
|
|
$object->expects( $this->once() )->method( 'search' ) |
|
276
|
|
|
->will( $this->returnValue( map() ) ); |
|
277
|
|
|
|
|
278
|
|
|
$this->expectException( \Aimeos\MShop\Locale\Exception::class ); |
|
279
|
|
|
$object->getTree(); |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
|
|
283
|
|
|
public function testGetTreeCache() |
|
284
|
|
|
{ |
|
285
|
|
|
$search = $this->object->filter(); |
|
286
|
|
|
$search->setConditions( $search->compare( '==', 'locale.site.code', 'unittest' ) ); |
|
287
|
|
|
|
|
288
|
|
|
$results = $this->object->search( $search )->toArray(); |
|
289
|
|
|
|
|
290
|
|
|
if( ( $expected = reset( $results ) ) === false ) { |
|
291
|
|
|
throw new \RuntimeException( 'No item found' ); |
|
292
|
|
|
} |
|
293
|
|
|
|
|
294
|
|
|
$item = $this->object->getTree( $expected->getId() ); |
|
295
|
|
|
$item2 = $this->object->getTree( $expected->getId() ); |
|
296
|
|
|
|
|
297
|
|
|
$this->assertSame( $item, $item2 ); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
|
|
301
|
|
|
public function testGetTreeDefault() |
|
302
|
|
|
{ |
|
303
|
|
|
$search = $this->object->filter(); |
|
304
|
|
|
$search->setConditions( $search->compare( '==', 'locale.site.code', 'default' ) ); |
|
305
|
|
|
$results = $this->object->search( $search )->toArray(); |
|
306
|
|
|
|
|
307
|
|
|
$this->assertIsArray( $results ); |
|
308
|
|
|
|
|
309
|
|
|
if( ( $expected = reset( $results ) ) !== false ) |
|
310
|
|
|
{ |
|
311
|
|
|
$item = $this->object->getTree(); |
|
312
|
|
|
$this->assertEquals( $expected, $item ); |
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
|
|
317
|
|
|
public function testMoveItem() |
|
318
|
|
|
{ |
|
319
|
|
|
$this->expectException( \Aimeos\MShop\Locale\Exception::class ); |
|
320
|
|
|
$this->object->move( '', '', '' ); |
|
321
|
|
|
} |
|
322
|
|
|
} |
|
323
|
|
|
|