Completed
Push — master ( 24a86a...771b97 )
by Aimeos
10:31
created

StandardTest::testGetSetPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
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 );
0 ignored issues
show
Documentation introduced by
The property additional does not exist on object<Aimeos\MShop\Customer\Item\Standard>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
82
		$this->assertNull( $this->object->missing );
0 ignored issues
show
Documentation introduced by
The property missing does not exist on object<Aimeos\MShop\Customer\Item\Standard>. Since you implemented __get, maybe consider adding a @property annotation.

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.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

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.

Loading history...
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 testGetSetPassword()
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 testAddAddressItem()
270
	{
271
		$this->object->addAddressItem( $this->address );
272
273
		$this->assertEquals( 3, count( $this->object->getAddressItems() ) );
274
	}
275
276
277
	public function testDeleteAddressItem()
278
	{
279
		$this->object->addAddressItem( $this->address );
280
		$this->object->deleteAddressItem( $this->address );
281
282
		$this->assertEquals( 2, count( $this->object->getAddressItems() ) );
283
		$this->assertEquals( 1, count( $this->object->getAddressItemsDeleted() ) );
284
	}
285
286
287
	public function testDeleteAddressItems()
288
	{
289
		$this->object->addAddressItem( $this->address );
290
		$this->object->deleteAddressItems( [$this->address] );
291
292
		$this->assertEquals( 2, count( $this->object->getAddressItems() ) );
293
		$this->assertEquals( 1, count( $this->object->getAddressItemsDeleted() ) );
294
	}
295
296
297
	public function testGetResourceType()
298
	{
299
		$this->assertEquals( 'customer', $this->object->getResourceType() );
300
	}
301
302
303
	public function testFromArray()
304
	{
305
		$address = new \Aimeos\MShop\Common\Item\Address\Standard( 'common.address.' );
306
		$item = new \Aimeos\MShop\Customer\Item\Standard( $address );
307
308
		$list = array(
309
			'customer.id' => 1,
310
			'customer.code' => '12345ABCDEF',
311
			'customer.label' => 'unitObject',
312
			'customer.birthday' => '2010-01-01',
313
			'customer.status' => 1,
314
			'customer.password' => '',
315
			'customer.dateverified' => null,
316
			'customer.company' => 'unitCompany',
317
			'customer.vatid' => 'DE999999999',
318
			'customer.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR,
319
			'customer.title' => 'Dr.',
320
			'customer.firstname' => 'firstunit',
321
			'customer.lastname' => 'lastunit',
322
			'customer.address1' => 'unit str.',
323
			'customer.address2' => ' 166',
324
			'customer.address3' => '4.OG',
325
			'customer.postal' => '22769',
326
			'customer.city' => 'Hamburg',
327
			'customer.state' => 'Hamburg',
328
			'customer.countryid' => 'DE',
329
			'customer.languageid' => 'de',
330
			'customer.telephone' => '05554433221',
331
			'customer.email' => '[email protected]',
332
			'customer.telefax' => '05554433222',
333
			'customer.website' => 'www.example.com',
334
			'customer.longitude' => '10.0',
335
			'customer.latitude' => '53.5',
336
			'customer.groups' => [1, 2],
337
		);
338
339
		$unknown = $item->fromArray( $list );
340
341
		$this->assertEquals( [], $unknown );
342
343
		$this->assertEquals( $list['customer.id'], $item->getId() );
344
		$this->assertEquals( $list['customer.code'], $item->getCode() );
345
		$this->assertEquals( $list['customer.label'], $item->getLabel() );
346
		$this->assertEquals( $list['customer.birthday'], $item->getBirthday() );
347
		$this->assertEquals( $list['customer.status'], $item->getStatus() );
348
		$this->assertEquals( $list['customer.groups'], $item->getGroups() );
349
		$this->assertEquals( $list['customer.password'], $item->getPassword() );
350
		$this->assertEquals( $list['customer.dateverified'], $item->getDateVerified() );
351
352
		$address = $item->getPaymentAddress();
353
		$this->assertEquals( $list['customer.company'], $address->getCompany() );
354
		$this->assertEquals( $list['customer.vatid'], $address->getVatID() );
355
		$this->assertEquals( $list['customer.salutation'], $address->getSalutation() );
356
		$this->assertEquals( $list['customer.title'], $address->getTitle() );
357
		$this->assertEquals( $list['customer.firstname'], $address->getFirstname() );
358
		$this->assertEquals( $list['customer.lastname'], $address->getLastname() );
359
		$this->assertEquals( $list['customer.address1'], $address->getAddress1() );
360
		$this->assertEquals( $list['customer.address2'], $address->getAddress2() );
361
		$this->assertEquals( $list['customer.address3'], $address->getAddress3() );
362
		$this->assertEquals( $list['customer.postal'], $address->getPostal() );
363
		$this->assertEquals( $list['customer.city'], $address->getCity() );
364
		$this->assertEquals( $list['customer.state'], $address->getState() );
365
		$this->assertEquals( $list['customer.countryid'], $address->getCountryId() );
366
		$this->assertEquals( $list['customer.languageid'], $address->getLanguageId() );
367
		$this->assertEquals( $list['customer.telephone'], $address->getTelephone() );
368
		$this->assertEquals( $list['customer.email'], $address->getEmail() );
369
		$this->assertEquals( $list['customer.telefax'], $address->getTelefax() );
370
		$this->assertEquals( $list['customer.website'], $address->getWebsite() );
371
		$this->assertEquals( $list['customer.longitude'], $address->getLongitude() );
372
		$this->assertEquals( $list['customer.latitude'], $address->getLatitude() );
373
	}
374
375
376
	public function testToArray()
377
	{
378
		$arrayObject = $this->object->toArray( true );
379
380
		$this->assertEquals( count( $this->values ) - 1, count( $arrayObject ) );
381
382
		$this->assertEquals( $this->object->getId(), $arrayObject['customer.id'] );
383
		$this->assertEquals( $this->object->getLabel(), $arrayObject['customer.label'] );
384
		$this->assertEquals( $this->object->getCode(), $arrayObject['customer.code'] );
385
		$this->assertEquals( $this->object->getStatus(), $arrayObject['customer.status'] );
386
		$this->assertEquals( $this->object->getGroups(), $arrayObject['customer.groups'] );
387
		$this->assertEquals( $this->object->getPassword(), $arrayObject['customer.password'] );
388
		$this->assertEquals( $this->object->getBirthday(), $arrayObject['customer.birthday'] );
389
		$this->assertEquals( $this->object->getDateVerified(), $arrayObject['customer.dateverified'] );
390
		$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['customer.ctime'] );
391
		$this->assertEquals( $this->object->getTimeModified(), $arrayObject['customer.mtime'] );
392
		$this->assertEquals( $this->object->getEditor(), $arrayObject['customer.editor'] );
393
394
		$address = $this->object->getPaymentAddress();
395
		$this->assertEquals( $address->getCompany(), $arrayObject['customer.company'] );
396
		$this->assertEquals( $address->getVatID(), $arrayObject['customer.vatid'] );
397
		$this->assertEquals( $address->getSalutation(), $arrayObject['customer.salutation'] );
398
		$this->assertEquals( $address->getTitle(), $arrayObject['customer.title'] );
399
		$this->assertEquals( $address->getFirstname(), $arrayObject['customer.firstname'] );
400
		$this->assertEquals( $address->getLastname(), $arrayObject['customer.lastname'] );
401
		$this->assertEquals( $address->getAddress1(), $arrayObject['customer.address1'] );
402
		$this->assertEquals( $address->getAddress2(), $arrayObject['customer.address2'] );
403
		$this->assertEquals( $address->getAddress3(), $arrayObject['customer.address3'] );
404
		$this->assertEquals( $address->getPostal(), $arrayObject['customer.postal'] );
405
		$this->assertEquals( $address->getCity(), $arrayObject['customer.city'] );
406
		$this->assertEquals( $address->getState(), $arrayObject['customer.state'] );
407
		$this->assertEquals( $address->getCountryId(), $arrayObject['customer.countryid'] );
408
		$this->assertEquals( $address->getLanguageId(), $arrayObject['customer.languageid'] );
409
		$this->assertEquals( $address->getTelephone(), $arrayObject['customer.telephone'] );
410
		$this->assertEquals( $address->getEmail(), $arrayObject['customer.email'] );
411
		$this->assertEquals( $address->getTelefax(), $arrayObject['customer.telefax'] );
412
		$this->assertEquals( $address->getWebsite(), $arrayObject['customer.website'] );
413
		$this->assertEquals( $address->getLongitude(), $arrayObject['customer.longitude'] );
414
		$this->assertEquals( $address->getLatitude(), $arrayObject['customer.latitude'] );
415
	}
416
417
418
	public function testIsAvailable()
419
	{
420
		$this->assertTrue( $this->object->isAvailable() );
421
	}
422
423
424
	public function testIsModified()
425
	{
426
		$this->assertFalse( $this->object->isModified() );
427
428
		$this->object->getPaymentAddress()->setState( 'HH' );
429
		$this->assertTrue( $this->object->isModified() );
430
	}
431
}
432