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\Item; |
11
|
|
|
|
12
|
|
|
use \Aimeos\MShop\Locale\Manager\Base as Locale; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Test class for \Aimeos\MShop\Locale\Item\Standard. |
17
|
|
|
*/ |
18
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
19
|
|
|
{ |
20
|
|
|
private $object; |
21
|
|
|
private $siteItem; |
22
|
|
|
private $values; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
protected function setUp() : void |
26
|
|
|
{ |
27
|
|
|
$this->siteItem = \Aimeos\MShop::create( \TestHelper::context(), 'locale/site' )->create(); |
28
|
|
|
|
29
|
|
|
$this->values = array( |
30
|
|
|
'locale.id' => 1, |
31
|
|
|
'locale.siteid' => 1, |
32
|
|
|
'locale.languageid' => 'de', |
33
|
|
|
'locale.currencyid' => 'EUR', |
34
|
|
|
'locale.position' => 1, |
35
|
|
|
'locale.status' => 1, |
36
|
|
|
'locale.mtime' => '2011-01-01 00:00:02', |
37
|
|
|
'locale.ctime' => '2011-01-01 00:00:01', |
38
|
|
|
'locale.editor' => 'unitTestUser', |
39
|
|
|
'locale.sitecode' => 'unittest', |
40
|
|
|
); |
41
|
|
|
|
42
|
|
|
$this->object = new \Aimeos\MShop\Locale\Item\Standard( $this->values, $this->siteItem, |
43
|
|
|
[Locale::SITE_ONE => '/1/2/', Locale::SITE_PATH => ['/1/', '/1/2'], Locale::SITE_SUBTREE => '/1/2/'] |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
protected function tearDown() : void |
49
|
|
|
{ |
50
|
|
|
unset( $this->object, $this->values ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testGetSiteItem() |
55
|
|
|
{ |
56
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Site\Iface::class, $this->object->getSiteItem() ); |
57
|
|
|
|
58
|
|
|
$wrongobject = new \Aimeos\MShop\Locale\Item\Standard(); |
59
|
|
|
$this->expectException( \Aimeos\MShop\Locale\Exception::class ); |
60
|
|
|
$wrongobject->getSiteItem(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testGetSites() |
65
|
|
|
{ |
66
|
|
|
$expected = [Locale::SITE_ONE => '/1/2/', Locale::SITE_PATH => ['/1/', '/1/2'], Locale::SITE_SUBTREE => '/1/2/']; |
67
|
|
|
|
68
|
|
|
$this->assertEquals( $expected, $this->object->getSites() ); |
69
|
|
|
$this->assertEquals( '/1/2/', $this->object->getSites( Locale::SITE_ONE ) ); |
70
|
|
|
$this->assertEquals( ['/1/', '/1/2'], $this->object->getSites( Locale::SITE_PATH ) ); |
71
|
|
|
$this->assertEquals( '/1/2/', $this->object->getSites( Locale::SITE_SUBTREE ) ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testGetSiteCode() |
76
|
|
|
{ |
77
|
|
|
$this->assertEquals( 'unittest', $this->object->getSiteCode() ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
public function testGetSiteId() |
82
|
|
|
{ |
83
|
|
|
$this->assertEquals( '1', $this->object->getSiteId() ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
public function testSetSiteId() |
88
|
|
|
{ |
89
|
|
|
$return = $this->object->setSiteId( '/5/' ); |
90
|
|
|
|
91
|
|
|
$this->assertTrue( $this->object->isModified() ); |
92
|
|
|
$this->assertEquals( '/5/', $this->object->getSiteId() ); |
93
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Iface::class, $return ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
public function testGetLanguageId() |
98
|
|
|
{ |
99
|
|
|
$this->assertEquals( 'de', $this->object->getLanguageId() ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
public function testSetLanguageId() |
104
|
|
|
{ |
105
|
|
|
$return = $this->object->setLanguageId( 'en' ); |
106
|
|
|
|
107
|
|
|
$this->assertTrue( $this->object->isModified() ); |
108
|
|
|
$this->assertEquals( 'en', $this->object->getLanguageId() ); |
109
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Iface::class, $return ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
public function testSetLanguageIdNull() |
114
|
|
|
{ |
115
|
|
|
$return = $this->object->setLanguageId( null ); |
116
|
|
|
|
117
|
|
|
$this->assertTrue( $this->object->isModified() ); |
118
|
|
|
$this->assertEquals( null, $this->object->getLanguageId() ); |
119
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Iface::class, $return ); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
public function testSetLanguageIdCountry() |
124
|
|
|
{ |
125
|
|
|
$return = $this->object->setLanguageId( 'en_GB' ); |
126
|
|
|
|
127
|
|
|
$this->assertEquals( 'en_GB', $this->object->getLanguageId() ); |
128
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Iface::class, $return ); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
public function testSetLanguageIdInvalid() |
133
|
|
|
{ |
134
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
135
|
|
|
$this->object->setLanguageId( 'test' ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
public function testSetLanguageIdCountryInvalid() |
140
|
|
|
{ |
141
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
142
|
|
|
$this->object->setLanguageId( 'en-GB' ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
public function testGetCurrencyId() |
147
|
|
|
{ |
148
|
|
|
$this->assertEquals( 'EUR', $this->object->getCurrencyId() ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
public function testSetCurrencyId() |
153
|
|
|
{ |
154
|
|
|
$return = $this->object->setCurrencyId( 'AWG' ); |
155
|
|
|
|
156
|
|
|
$this->assertTrue( $this->object->isModified() ); |
157
|
|
|
$this->assertEquals( 'AWG', $this->object->getCurrencyId() ); |
158
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Iface::class, $return ); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
public function testSetCurrencyIdNull() |
163
|
|
|
{ |
164
|
|
|
$return = $this->object->setCurrencyId( null ); |
165
|
|
|
|
166
|
|
|
$this->assertTrue( $this->object->isModified() ); |
167
|
|
|
$this->assertEquals( null, $this->object->getCurrencyId() ); |
168
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Iface::class, $return ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
public function testSetCurrencyIdInvalid() |
173
|
|
|
{ |
174
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
175
|
|
|
$this->object->setCurrencyId( 'TEST' ); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
|
179
|
|
|
public function testGetPosition() |
180
|
|
|
{ |
181
|
|
|
$this->assertEquals( 1, $this->object->getPosition() ); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
public function testSetPosition() |
186
|
|
|
{ |
187
|
|
|
$return = $this->object->setPosition( 2 ); |
188
|
|
|
|
189
|
|
|
$this->assertTrue( $this->object->isModified() ); |
190
|
|
|
$this->assertEquals( 2, $this->object->getPosition() ); |
191
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Locale\Item\Iface::class, $return ); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
195
|
|
|
public function testGetTimeModified() |
196
|
|
|
{ |
197
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
public function testGetTimeCreated() |
202
|
|
|
{ |
203
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
public function testGetEditor() |
208
|
|
|
{ |
209
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->editor() ); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
public function testGetResourceType() |
214
|
|
|
{ |
215
|
|
|
$this->assertEquals( 'locale', $this->object->getResourceType() ); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
public function testFromArray() |
220
|
|
|
{ |
221
|
|
|
$item = new \Aimeos\MShop\Locale\Item\Standard(); |
222
|
|
|
|
223
|
|
|
$list = $entries = array( |
224
|
|
|
'locale.id' => 1, |
225
|
|
|
'locale.siteid' => 2, |
226
|
|
|
'locale.languageid' => 'de', |
227
|
|
|
'locale.currencyid' => 'EUR', |
228
|
|
|
'locale.position' => 10, |
229
|
|
|
'locale.status' => 0, |
230
|
|
|
); |
231
|
|
|
|
232
|
|
|
$item = $item->fromArray( $entries, true ); |
233
|
|
|
|
234
|
|
|
$this->assertEquals( [], $entries ); |
235
|
|
|
$this->assertEquals( $list['locale.id'], $item->getId() ); |
236
|
|
|
$this->assertEquals( $list['locale.siteid'], $item->getSiteId() ); |
237
|
|
|
$this->assertEquals( $list['locale.languageid'], $item->getLanguageId() ); |
238
|
|
|
$this->assertEquals( $list['locale.currencyid'], $item->getCurrencyId() ); |
239
|
|
|
$this->assertEquals( $list['locale.position'], $item->getPosition() ); |
240
|
|
|
$this->assertEquals( $list['locale.status'], $item->getStatus() ); |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
|
244
|
|
|
public function testToArray() |
245
|
|
|
{ |
246
|
|
|
$arrayObject = $this->object->toArray( true ); |
247
|
|
|
$this->assertEquals( count( $this->values ), count( $arrayObject ) ); |
248
|
|
|
|
249
|
|
|
$this->assertEquals( $this->object->getId(), $arrayObject['locale.id'] ); |
250
|
|
|
$this->assertEquals( $this->object->getSiteId(), $arrayObject['locale.siteid'] ); |
251
|
|
|
$this->assertEquals( $this->object->getLanguageId(), $arrayObject['locale.languageid'] ); |
252
|
|
|
$this->assertEquals( $this->object->getCurrencyId(), $arrayObject['locale.currencyid'] ); |
253
|
|
|
$this->assertEquals( $this->object->getPosition(), $arrayObject['locale.position'] ); |
254
|
|
|
$this->assertEquals( $this->object->getStatus(), $arrayObject['locale.status'] ); |
255
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['locale.ctime'] ); |
256
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $arrayObject['locale.mtime'] ); |
257
|
|
|
$this->assertEquals( $this->object->editor(), $arrayObject['locale.editor'] ); |
258
|
|
|
$this->assertEquals( $this->object->getSiteCode(), $arrayObject['locale.sitecode'] ); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
|
262
|
|
|
public function testIsAvailable() |
263
|
|
|
{ |
264
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
265
|
|
|
$this->object->setAvailable( false ); |
266
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
public function testIsAvailableOnStatus() |
271
|
|
|
{ |
272
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
273
|
|
|
$this->object->setStatus( 0 ); |
274
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
275
|
|
|
$this->object->setStatus( -1 ); |
276
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
} |
280
|
|
|
|