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-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Customer\Item; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $values; |
17
|
|
|
private $address; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$addressValues = array( |
23
|
|
|
'common.address.parentid' => 'referenceid', |
24
|
|
|
'common.address.position' => 1, |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
$this->address = new \Aimeos\MShop\Common\Item\Address\Standard( 'common.address.', $addressValues ); |
28
|
|
|
|
29
|
|
|
$this->values = array( |
30
|
|
|
'customer.id' => 541, |
31
|
|
|
'customer.siteid' => 123, |
32
|
|
|
'customer.label' => 'unitObject', |
33
|
|
|
'customer.code' => '12345ABCDEF', |
34
|
|
|
'customer.birthday' => '2010-01-01', |
35
|
|
|
'customer.status' => 1, |
36
|
|
|
'customer.groups' => [1, 2], |
37
|
|
|
'customer.password' => '', |
38
|
|
|
'customer.dateverified' => null, |
39
|
|
|
'customer.company' => 'unitCompany', |
40
|
|
|
'customer.vatid' => 'DE999999999', |
41
|
|
|
'customer.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, |
42
|
|
|
'customer.title' => 'Dr.', |
43
|
|
|
'customer.firstname' => 'firstunit', |
44
|
|
|
'customer.lastname' => 'lastunit', |
45
|
|
|
'customer.address1' => 'unit str.', |
46
|
|
|
'customer.address2' => ' 166', |
47
|
|
|
'customer.address3' => '4.OG', |
48
|
|
|
'customer.postal' => '22769', |
49
|
|
|
'customer.city' => 'Hamburg', |
50
|
|
|
'customer.state' => 'Hamburg', |
51
|
|
|
'customer.countryid' => 'de', |
52
|
|
|
'customer.languageid' => 'de', |
53
|
|
|
'customer.telephone' => '05554433221', |
54
|
|
|
'customer.email' => '[email protected]', |
55
|
|
|
'customer.telefax' => '05554433222', |
56
|
|
|
'customer.website' => 'www.example.com', |
57
|
|
|
'customer.longitude' => '10.0', |
58
|
|
|
'customer.latitude' => '50.0', |
59
|
|
|
'customer.mtime'=> '2010-01-05 00:00:05', |
60
|
|
|
'customer.ctime'=> '2010-01-01 00:00:00', |
61
|
|
|
'customer.editor' => 'unitTestUser', |
62
|
|
|
'additional' => 'something', |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$addresses = array( |
66
|
|
|
-1 => new \Aimeos\MShop\Customer\Item\Address\Standard( 'customer.address.', ['customer.address.position' => 1] ), |
67
|
|
|
-2 => new \Aimeos\MShop\Customer\Item\Address\Standard( 'customer.address.', ['customer.address.position' => 0] ), |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$this->object = new \Aimeos\MShop\Customer\Item\Standard( $this->address, $this->values, [], [], 'mshop', null, $addresses ); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
protected function tearDown() |
75
|
|
|
{ |
76
|
|
|
unset( $this->object, $this->address, $this->values ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testGet() |
80
|
|
|
{ |
81
|
|
|
$this->assertEquals( 'something', $this->object->additional ); |
|
|
|
|
82
|
|
|
$this->assertNull( $this->object->missing ); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testIsset() |
86
|
|
|
{ |
87
|
|
|
$this->assertTrue( isset( $this->object->additional ) ); |
88
|
|
|
$this->assertFalse( isset( $this->object->missing ) ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testGetId() |
92
|
|
|
{ |
93
|
|
|
$this->assertEquals( 541, $this->object->getId() ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testSetId() |
97
|
|
|
{ |
98
|
|
|
$return = $this->object->setId( null ); |
99
|
|
|
|
100
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $return ); |
101
|
|
|
$this->assertNull( $this->object->getId() ); |
102
|
|
|
$this->assertTrue( $this->object->isModified() ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testGetSiteId() |
106
|
|
|
{ |
107
|
|
|
$this->assertEquals( 123, $this->object->getSiteId() ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testGetLabel() |
111
|
|
|
{ |
112
|
|
|
$this->assertEquals( 'unitObject', $this->object->getLabel() ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testSetLabel() |
116
|
|
|
{ |
117
|
|
|
$return = $this->object->setLabel( 'newName' ); |
118
|
|
|
|
119
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $return ); |
120
|
|
|
$this->assertEquals( 'newName', $this->object->getLabel() ); |
121
|
|
|
$this->assertTrue( $this->object->isModified() ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function testGetCode() |
125
|
|
|
{ |
126
|
|
|
$this->assertEquals( '12345ABCDEF', $this->object->getCode() ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testSetCode() |
130
|
|
|
{ |
131
|
|
|
$return = $this->object->setCode( '[email protected]' ); |
132
|
|
|
|
133
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $return ); |
134
|
|
|
$this->assertEquals( '[email protected]', $this->object->getCode() ); |
135
|
|
|
$this->assertTrue( $this->object->isModified() ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function testGetStatus() |
139
|
|
|
{ |
140
|
|
|
$this->assertEquals( 1, $this->object->getStatus() ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testSetStatus() |
144
|
|
|
{ |
145
|
|
|
$return = $this->object->setStatus( 0 ); |
146
|
|
|
|
147
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $return ); |
148
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
149
|
|
|
$this->assertTrue( $this->object->isModified() ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function testSetAndGetPassword() |
153
|
|
|
{ |
154
|
|
|
$return = $this->object->setPassword( '08154712' ); |
155
|
|
|
|
156
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $return ); |
157
|
|
|
$this->assertEquals( '08154712', $this->object->getPassword() ); |
158
|
|
|
$this->assertTrue( $this->object->isModified() ); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function testGetTimeCreated() |
162
|
|
|
{ |
163
|
|
|
$this->assertEquals( '2010-01-01 00:00:00', $this->object->getTimeCreated() ); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function testGetTimeModified() |
167
|
|
|
{ |
168
|
|
|
$this->assertEquals( '2010-01-05 00:00:05', $this->object->getTimeModified() ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testGetEditor() |
172
|
|
|
{ |
173
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->getEditor() ); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function testGetBirthday() |
177
|
|
|
{ |
178
|
|
|
$this->assertEquals( '2010-01-01', $this->object->getBirthday() ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function testSetBirthday() |
182
|
|
|
{ |
183
|
|
|
$return = $this->object->setBirthday( '2010-02-01' ); |
184
|
|
|
|
185
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $return ); |
186
|
|
|
$this->assertEquals( '2010-02-01', $this->object->getBirthday() ); |
187
|
|
|
$this->assertTrue( $this->object->isModified() ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
public function testGetDateVerified() |
191
|
|
|
{ |
192
|
|
|
$this->assertEquals( null, $this->object->getDateVerified() ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
public function testSetDateVerified() |
196
|
|
|
{ |
197
|
|
|
$return = $this->object->setDateVerified( '2010-02-01' ); |
198
|
|
|
|
199
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $return ); |
200
|
|
|
$this->assertEquals( '2010-02-01', $this->object->getDateVerified() ); |
201
|
|
|
$this->assertTrue( $this->object->isModified() ); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function testGetGroups() |
205
|
|
|
{ |
206
|
|
|
$listValues = array( 'domain' => 'customer/group', 'type' => 'default', 'refid' => 123 ); |
207
|
|
|
$listItems = array( 'customer/group' => array( new \Aimeos\MShop\Common\Item\Lists\Standard( '', $listValues ) ) ); |
208
|
|
|
$object = new \Aimeos\MShop\Customer\Item\Standard( $this->address, [], $listItems ); |
209
|
|
|
|
210
|
|
|
$this->assertEquals( array( 123 ), $object->getGroups() ); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function testSetGroups() |
214
|
|
|
{ |
215
|
|
|
$this->object->setGroups( array( 1, 2, 3 ) ); |
216
|
|
|
$this->assertEquals( array( 1, 2, 3 ), $this->object->getGroups() ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function testGetPaymentAddress() |
220
|
|
|
{ |
221
|
|
|
$address = $this->object->getPaymentAddress(); |
222
|
|
|
$this->assertEquals( $address->getParentId(), 'referenceid' ); |
223
|
|
|
$this->assertEquals( $address->getCompany(), 'unitCompany' ); |
224
|
|
|
$this->assertEquals( $address->getVatID(), 'DE999999999' ); |
225
|
|
|
$this->assertEquals( $address->getSalutation(), \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR ); |
226
|
|
|
$this->assertEquals( $address->getTitle(), 'Dr.' ); |
227
|
|
|
$this->assertEquals( $address->getFirstname(), 'firstunit' ); |
228
|
|
|
$this->assertEquals( $address->getLastname(), 'lastunit' ); |
229
|
|
|
$this->assertEquals( $address->getAddress1(), 'unit str.' ); |
230
|
|
|
$this->assertEquals( $address->getAddress2(), ' 166' ); |
231
|
|
|
$this->assertEquals( $address->getAddress3(), '4.OG' ); |
232
|
|
|
$this->assertEquals( $address->getPostal(), '22769' ); |
233
|
|
|
$this->assertEquals( $address->getCity(), 'Hamburg' ); |
234
|
|
|
$this->assertEquals( $address->getState(), 'Hamburg' ); |
235
|
|
|
$this->assertEquals( $address->getCountryId(), 'DE' ); |
236
|
|
|
$this->assertEquals( $address->getLanguageId(), 'de' ); |
237
|
|
|
$this->assertEquals( $address->getTelephone(), '05554433221' ); |
238
|
|
|
$this->assertEquals( $address->getEmail(), '[email protected]' ); |
239
|
|
|
$this->assertEquals( $address->getTelefax(), '05554433222' ); |
240
|
|
|
$this->assertEquals( $address->getWebsite(), 'www.example.com' ); |
241
|
|
|
$this->assertEquals( $address->getLongitude(), '10.0' ); |
242
|
|
|
$this->assertEquals( $address->getLatitude(), '50.0' ); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
public function testSetPaymentAddress() |
246
|
|
|
{ |
247
|
|
|
$this->address->setCompany( 'unitCompany0815' ); |
248
|
|
|
$return = $this->object->setPaymentAddress( $this->address ); |
249
|
|
|
|
250
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $return ); |
251
|
|
|
$this->assertEquals( $this->address, $this->object->getPaymentAddress() ); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
|
255
|
|
|
public function testGetAddressItems() |
256
|
|
|
{ |
257
|
|
|
$i = 0; |
258
|
|
|
$list = $this->object->getAddressItems(); |
259
|
|
|
$this->assertEquals( 2, count( $list ) ); |
260
|
|
|
|
261
|
|
|
foreach( $list as $item ) |
262
|
|
|
{ |
263
|
|
|
$this->assertEquals( $i++, $item->getPosition() ); |
264
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $item ); |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
|
269
|
|
|
public function testGetResourceType() |
270
|
|
|
{ |
271
|
|
|
$this->assertEquals( 'customer', $this->object->getResourceType() ); |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
|
275
|
|
|
public function testFromArray() |
276
|
|
|
{ |
277
|
|
|
$address = new \Aimeos\MShop\Common\Item\Address\Standard( 'common.address.' ); |
278
|
|
|
$item = new \Aimeos\MShop\Customer\Item\Standard( $address ); |
279
|
|
|
|
280
|
|
|
$list = array( |
281
|
|
|
'customer.id' => 1, |
282
|
|
|
'customer.code' => '12345ABCDEF', |
283
|
|
|
'customer.label' => 'unitObject', |
284
|
|
|
'customer.birthday' => '2010-01-01', |
285
|
|
|
'customer.status' => 1, |
286
|
|
|
'customer.password' => '', |
287
|
|
|
'customer.dateverified' => null, |
288
|
|
|
'customer.company' => 'unitCompany', |
289
|
|
|
'customer.vatid' => 'DE999999999', |
290
|
|
|
'customer.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, |
291
|
|
|
'customer.title' => 'Dr.', |
292
|
|
|
'customer.firstname' => 'firstunit', |
293
|
|
|
'customer.lastname' => 'lastunit', |
294
|
|
|
'customer.address1' => 'unit str.', |
295
|
|
|
'customer.address2' => ' 166', |
296
|
|
|
'customer.address3' => '4.OG', |
297
|
|
|
'customer.postal' => '22769', |
298
|
|
|
'customer.city' => 'Hamburg', |
299
|
|
|
'customer.state' => 'Hamburg', |
300
|
|
|
'customer.countryid' => 'DE', |
301
|
|
|
'customer.languageid' => 'de', |
302
|
|
|
'customer.telephone' => '05554433221', |
303
|
|
|
'customer.email' => '[email protected]', |
304
|
|
|
'customer.telefax' => '05554433222', |
305
|
|
|
'customer.website' => 'www.example.com', |
306
|
|
|
'customer.longitude' => '10.0', |
307
|
|
|
'customer.latitude' => '53.5', |
308
|
|
|
'customer.groups' => [1, 2], |
309
|
|
|
); |
310
|
|
|
|
311
|
|
|
$unknown = $item->fromArray( $list ); |
312
|
|
|
|
313
|
|
|
$this->assertEquals( [], $unknown ); |
314
|
|
|
|
315
|
|
|
$this->assertEquals( $list['customer.id'], $item->getId() ); |
316
|
|
|
$this->assertEquals( $list['customer.code'], $item->getCode() ); |
317
|
|
|
$this->assertEquals( $list['customer.label'], $item->getLabel() ); |
318
|
|
|
$this->assertEquals( $list['customer.birthday'], $item->getBirthday() ); |
319
|
|
|
$this->assertEquals( $list['customer.status'], $item->getStatus() ); |
320
|
|
|
$this->assertEquals( $list['customer.groups'], $item->getGroups() ); |
321
|
|
|
$this->assertEquals( $list['customer.password'], $item->getPassword() ); |
322
|
|
|
$this->assertEquals( $list['customer.dateverified'], $item->getDateVerified() ); |
323
|
|
|
|
324
|
|
|
$address = $item->getPaymentAddress(); |
325
|
|
|
$this->assertEquals( $list['customer.company'], $address->getCompany() ); |
326
|
|
|
$this->assertEquals( $list['customer.vatid'], $address->getVatID() ); |
327
|
|
|
$this->assertEquals( $list['customer.salutation'], $address->getSalutation() ); |
328
|
|
|
$this->assertEquals( $list['customer.title'], $address->getTitle() ); |
329
|
|
|
$this->assertEquals( $list['customer.firstname'], $address->getFirstname() ); |
330
|
|
|
$this->assertEquals( $list['customer.lastname'], $address->getLastname() ); |
331
|
|
|
$this->assertEquals( $list['customer.address1'], $address->getAddress1() ); |
332
|
|
|
$this->assertEquals( $list['customer.address2'], $address->getAddress2() ); |
333
|
|
|
$this->assertEquals( $list['customer.address3'], $address->getAddress3() ); |
334
|
|
|
$this->assertEquals( $list['customer.postal'], $address->getPostal() ); |
335
|
|
|
$this->assertEquals( $list['customer.city'], $address->getCity() ); |
336
|
|
|
$this->assertEquals( $list['customer.state'], $address->getState() ); |
337
|
|
|
$this->assertEquals( $list['customer.countryid'], $address->getCountryId() ); |
338
|
|
|
$this->assertEquals( $list['customer.languageid'], $address->getLanguageId() ); |
339
|
|
|
$this->assertEquals( $list['customer.telephone'], $address->getTelephone() ); |
340
|
|
|
$this->assertEquals( $list['customer.email'], $address->getEmail() ); |
341
|
|
|
$this->assertEquals( $list['customer.telefax'], $address->getTelefax() ); |
342
|
|
|
$this->assertEquals( $list['customer.website'], $address->getWebsite() ); |
343
|
|
|
$this->assertEquals( $list['customer.longitude'], $address->getLongitude() ); |
344
|
|
|
$this->assertEquals( $list['customer.latitude'], $address->getLatitude() ); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
|
348
|
|
|
public function testToArray() |
349
|
|
|
{ |
350
|
|
|
$arrayObject = $this->object->toArray( true ); |
351
|
|
|
|
352
|
|
|
$this->assertEquals( count( $this->values ) - 1, count( $arrayObject ) ); |
353
|
|
|
|
354
|
|
|
$this->assertEquals( $this->object->getId(), $arrayObject['customer.id'] ); |
355
|
|
|
$this->assertEquals( $this->object->getLabel(), $arrayObject['customer.label'] ); |
356
|
|
|
$this->assertEquals( $this->object->getCode(), $arrayObject['customer.code'] ); |
357
|
|
|
$this->assertEquals( $this->object->getStatus(), $arrayObject['customer.status'] ); |
358
|
|
|
$this->assertEquals( $this->object->getGroups(), $arrayObject['customer.groups'] ); |
359
|
|
|
$this->assertEquals( $this->object->getPassword(), $arrayObject['customer.password'] ); |
360
|
|
|
$this->assertEquals( $this->object->getBirthday(), $arrayObject['customer.birthday'] ); |
361
|
|
|
$this->assertEquals( $this->object->getDateVerified(), $arrayObject['customer.dateverified'] ); |
362
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['customer.ctime'] ); |
363
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $arrayObject['customer.mtime'] ); |
364
|
|
|
$this->assertEquals( $this->object->getEditor(), $arrayObject['customer.editor'] ); |
365
|
|
|
|
366
|
|
|
$address = $this->object->getPaymentAddress(); |
367
|
|
|
$this->assertEquals( $address->getCompany(), $arrayObject['customer.company'] ); |
368
|
|
|
$this->assertEquals( $address->getVatID(), $arrayObject['customer.vatid'] ); |
369
|
|
|
$this->assertEquals( $address->getSalutation(), $arrayObject['customer.salutation'] ); |
370
|
|
|
$this->assertEquals( $address->getTitle(), $arrayObject['customer.title'] ); |
371
|
|
|
$this->assertEquals( $address->getFirstname(), $arrayObject['customer.firstname'] ); |
372
|
|
|
$this->assertEquals( $address->getLastname(), $arrayObject['customer.lastname'] ); |
373
|
|
|
$this->assertEquals( $address->getAddress1(), $arrayObject['customer.address1'] ); |
374
|
|
|
$this->assertEquals( $address->getAddress2(), $arrayObject['customer.address2'] ); |
375
|
|
|
$this->assertEquals( $address->getAddress3(), $arrayObject['customer.address3'] ); |
376
|
|
|
$this->assertEquals( $address->getPostal(), $arrayObject['customer.postal'] ); |
377
|
|
|
$this->assertEquals( $address->getCity(), $arrayObject['customer.city'] ); |
378
|
|
|
$this->assertEquals( $address->getState(), $arrayObject['customer.state'] ); |
379
|
|
|
$this->assertEquals( $address->getCountryId(), $arrayObject['customer.countryid'] ); |
380
|
|
|
$this->assertEquals( $address->getLanguageId(), $arrayObject['customer.languageid'] ); |
381
|
|
|
$this->assertEquals( $address->getTelephone(), $arrayObject['customer.telephone'] ); |
382
|
|
|
$this->assertEquals( $address->getEmail(), $arrayObject['customer.email'] ); |
383
|
|
|
$this->assertEquals( $address->getTelefax(), $arrayObject['customer.telefax'] ); |
384
|
|
|
$this->assertEquals( $address->getWebsite(), $arrayObject['customer.website'] ); |
385
|
|
|
$this->assertEquals( $address->getLongitude(), $arrayObject['customer.longitude'] ); |
386
|
|
|
$this->assertEquals( $address->getLatitude(), $arrayObject['customer.latitude'] ); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
public function testIsModified() |
390
|
|
|
{ |
391
|
|
|
$this->assertFalse( $this->object->isModified() ); |
392
|
|
|
|
393
|
|
|
$this->object->getPaymentAddress()->setState( 'HH' ); |
394
|
|
|
$this->assertTrue( $this->object->isModified() ); |
395
|
|
|
} |
396
|
|
|
} |
397
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.