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