Passed
Push — master ( 92591d...b586f0 )
by Aimeos
15:24
created

StandardTest::testSetMobile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2023
6
 */
7
8
9
namespace Aimeos\MShop\Customer\Item\Address;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $values;
16
17
18
	protected function setUp() : void
19
	{
20
		$this->values = array(
21
			'customer.address.id' => 23,
22
			'customer.address.siteid' => 12,
23
			'customer.address.parentid' => 'referenceid',
24
			'customer.address.company' => 'unitCompany',
25
			'customer.address.vatid' => 'DE999999999',
26
			'customer.address.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR,
27
			'customer.address.title' => 'Herr',
28
			'customer.address.firstname' => 'firstunit',
29
			'customer.address.lastname' => 'lastunit',
30
			'customer.address.address1' => 'unit str.',
31
			'customer.address.address2' => '166',
32
			'customer.address.address3' => '4.OG',
33
			'customer.address.postal' => '22769',
34
			'customer.address.city' => 'Hamburg',
35
			'customer.address.state' => 'Hamburg',
36
			'customer.address.countryid' => 'DE',
37
			'customer.address.languageid' => 'de',
38
			'customer.address.telephone' => '05554433221',
39
			'customer.address.telefax' => '05554433222',
40
			'customer.address.mobile' => '05554433223',
41
			'customer.address.email' => '[email protected]',
42
			'customer.address.website' => 'www.example.com',
43
			'customer.address.longitude' => '10.0',
44
			'customer.address.latitude' => '50.0',
45
			'customer.address.position' => 1,
46
			'customer.address.birthday' => '2000-01-01',
47
			'customer.address.mtime' => '2011-01-01 00:00:02',
48
			'customer.address.ctime' => '2011-01-01 00:00:01',
49
			'customer.address.editor' => 'unitTestUser',
50
		);
51
52
		$this->object = new \Aimeos\MShop\Customer\Item\Address\Standard( 'customer.address.', $this->values );
53
	}
54
55
56
	protected function tearDown() : void
57
	{
58
		$this->object = null;
59
	}
60
61
62
	public function testGetId()
63
	{
64
		$this->assertEquals( 23, $this->object->getId() );
65
	}
66
67
68
	public function testSetId()
69
	{
70
		$return = $this->object->setId( null );
71
72
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
73
		$this->assertTrue( $this->object->isModified() );
74
		$this->assertNull( $this->object->getId() );
75
	}
76
77
78
	public function testGetParentId()
79
	{
80
		$this->assertEquals( 'referenceid', $this->object->getParentId() );
81
	}
82
83
84
	public function testSetParentId()
85
	{
86
		$return = $this->object->setParentId( 'unitreference' );
87
88
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
89
		$this->assertEquals( 'unitreference', $this->object->getParentId() );
90
		$this->assertTrue( $this->object->isModified() );
91
	}
92
93
94
	public function testGetCompany()
95
	{
96
		$this->assertEquals( 'unitCompany', $this->object->getCompany() );
97
	}
98
99
100
	public function testSetCompany()
101
	{
102
		$return = $this->object->setCompany( 'company' );
103
104
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
105
		$this->assertEquals( 'company', $this->object->getCompany() );
106
		$this->assertTrue( $this->object->isModified() );
107
	}
108
109
110
	public function testGetVatID()
111
	{
112
		$this->assertEquals( 'DE999999999', $this->object->getVatID() );
113
	}
114
115
116
	public function testSetVatID()
117
	{
118
		$return = $this->object->setVatID( 'vatid' );
119
120
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
121
		$this->assertEquals( 'vatid', $this->object->getVatID() );
122
		$this->assertTrue( $this->object->isModified() );
123
	}
124
125
126
	public function testGetSalutation()
127
	{
128
		$this->assertEquals( \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, $this->object->getSalutation() );
129
	}
130
131
132
	public function testSetSalutation()
133
	{
134
		$return = $this->object->setSalutation( \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY );
135
136
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
137
		$this->assertEquals( \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY, $this->object->getSalutation() );
138
		$this->assertTrue( $this->object->isModified() );
139
	}
140
141
142
	public function testGetTitle()
143
	{
144
		$this->assertEquals( 'Herr', $this->object->getTitle() );
145
	}
146
147
148
	public function testSetTitle()
149
	{
150
		$return = $this->object->setTitle( 'Dr.' );
151
152
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
153
		$this->assertEquals( 'Dr.', $this->object->getTitle() );
154
		$this->assertTrue( $this->object->isModified() );
155
	}
156
157
158
	public function testGetFirstname()
159
	{
160
		$this->assertEquals( 'firstunit', $this->object->getFirstname() );
161
	}
162
163
164
	public function testSetFirstname()
165
	{
166
		$return = $this->object->setFirstname( 'hans' );
167
168
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
169
		$this->assertEquals( 'hans', $this->object->getFirstname() );
170
		$this->assertTrue( $this->object->isModified() );
171
	}
172
173
174
	public function testGetLastname()
175
	{
176
		$this->assertEquals( 'lastunit', $this->object->getLastname() );
177
	}
178
179
180
	public function testSetLastname()
181
	{
182
		$return = $this->object->setLastname( 'im Glueck' );
183
184
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
185
		$this->assertEquals( 'im Glueck', $this->object->getLastname() );
186
		$this->assertTrue( $this->object->isModified() );
187
	}
188
189
190
	public function testGetAddress1()
191
	{
192
		$this->assertEquals( 'unit str.', $this->object->getAddress1() );
193
	}
194
195
196
	public function testSetAddress1()
197
	{
198
		$return = $this->object->setAddress1( 'unitallee' );
199
200
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
201
		$this->assertEquals( 'unitallee', $this->object->getAddress1() );
202
		$this->assertTrue( $this->object->isModified() );
203
	}
204
205
206
	public function testGetAddress2()
207
	{
208
		$this->assertEquals( '166', $this->object->getAddress2() );
209
	}
210
211
212
	public function testSetAddress2()
213
	{
214
		$return = $this->object->setAddress2( '12' );
215
216
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
217
		$this->assertEquals( '12', $this->object->getAddress2() );
218
		$this->assertTrue( $this->object->isModified() );
219
	}
220
221
222
	public function testGetAddress3()
223
	{
224
		$this->assertEquals( '4.OG', $this->object->getAddress3() );
225
	}
226
227
228
	public function testSetAddress3()
229
	{
230
		$return = $this->object->setAddress3( 'EG' );
231
232
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
233
		$this->assertEquals( 'EG', $this->object->getAddress3() );
234
		$this->assertTrue( $this->object->isModified() );
235
	}
236
237
238
	public function testGetPostal()
239
	{
240
		$this->assertEquals( '22769', $this->object->getPostal() );
241
	}
242
243
244
	public function testSetPostal()
245
	{
246
		$return = $this->object->setPostal( '11111' );
247
248
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
249
		$this->assertEquals( '11111', $this->object->getPostal() );
250
		$this->assertTrue( $this->object->isModified() );
251
	}
252
253
254
	public function testGetCity()
255
	{
256
		$this->assertEquals( 'Hamburg', $this->object->getCity() );
257
	}
258
259
260
	public function testSetCity()
261
	{
262
		$return = $this->object->setCity( 'unitCity' );
263
264
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
265
		$this->assertEquals( 'unitCity', $this->object->getCity() );
266
		$this->assertTrue( $this->object->isModified() );
267
	}
268
269
270
	public function testGetState()
271
	{
272
		$this->assertEquals( 'Hamburg', $this->object->getState() );
273
	}
274
275
276
	public function testSetState()
277
	{
278
		$return = $this->object->setState( 'unitState' );
279
280
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
281
		$this->assertEquals( 'unitState', $this->object->getState() );
282
		$this->assertTrue( $this->object->isModified() );
283
	}
284
285
286
	public function testGetCountryId()
287
	{
288
		$this->assertEquals( 'DE', $this->object->getCountryId() );
289
	}
290
291
292
	public function testSetCountryId()
293
	{
294
		$return = $this->object->setCountryId( 'uk' );
295
296
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
297
		$this->assertEquals( 'UK', $this->object->getCountryId() );
298
		$this->assertTrue( $this->object->isModified() );
299
	}
300
301
302
	public function testGetLanguageId()
303
	{
304
		$this->assertEquals( 'de', $this->object->getLanguageId() );
305
	}
306
307
308
	public function testSetLanguageId()
309
	{
310
		$return = $this->object->setLanguageId( 'en' );
311
312
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
313
		$this->assertEquals( 'en', $this->object->getLanguageId() );
314
		$this->assertTrue( $this->object->isModified() );
315
	}
316
317
318
	public function testGetTelephone()
319
	{
320
		$this->assertEquals( '05554433221', $this->object->getTelephone() );
321
	}
322
323
324
	public function testSetTelephone()
325
	{
326
		$return = $this->object->setTelephone( '55512345' );
327
328
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
329
		$this->assertEquals( '55512345', $this->object->getTelephone() );
330
		$this->assertTrue( $this->object->isModified() );
331
	}
332
333
334
	public function testGetTelefax()
335
	{
336
		$this->assertEquals( '05554433222', $this->object->getTelefax() );
337
	}
338
339
340
	public function testSetTelefax()
341
	{
342
		$return = $this->object->setTelefax( '55512345' );
343
344
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
345
		$this->assertEquals( '55512345', $this->object->getTelefax() );
346
		$this->assertTrue( $this->object->isModified() );
347
	}
348
349
350
	public function testGetMobile()
351
	{
352
		$this->assertEquals( '05554433223', $this->object->getMobile() );
353
	}
354
355
356
	public function testSetMobile()
357
	{
358
		$return = $this->object->setMobile( '555123456' );
359
360
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
361
		$this->assertEquals( '555123456', $this->object->getMobile() );
362
		$this->assertTrue( $this->object->isModified() );
363
	}
364
365
366
	public function testGetEmail()
367
	{
368
		$this->assertEquals( '[email protected]', $this->object->getEmail() );
369
	}
370
371
372
	public function testSetEmail()
373
	{
374
		$return = $this->object->setEmail( '[email protected]' );
375
376
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
377
		$this->assertEquals( '[email protected]', $this->object->getEmail() );
378
		$this->assertTrue( $this->object->isModified() );
379
380
		$this->expectException( \Aimeos\MShop\Exception::class );
381
		$this->object->setEmail( 'unittest.de' );
382
	}
383
384
385
	public function testGetWebsite()
386
	{
387
		$this->assertEquals( 'www.example.com', $this->object->getWebsite() );
388
	}
389
390
391
	public function testSetWebsite()
392
	{
393
		$return = $this->object->setWebsite( 'www.test.de' );
394
395
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
396
		$this->assertEquals( 'www.test.de', $this->object->getWebsite() );
397
		$this->assertTrue( $this->object->isModified() );
398
399
		$this->object->setWebsite( 'http://xn--ses-5ka8l.de' );
400
		$this->object->setWebsite( 'http://www.test.de:443' );
401
		$this->object->setWebsite( 'https://www.test.de:8080/abc?123' );
402
403
		$this->expectException( \Aimeos\MShop\Exception::class );
404
		$this->object->setWebsite( '_test:de' );
405
	}
406
407
408
	public function testSetWebsiteHostException()
409
	{
410
		$this->expectException( \Aimeos\MShop\Exception::class );
411
		$this->object->setWebsite( 'localhost' );
412
	}
413
414
415
	public function testGetLongitude()
416
	{
417
		$this->assertEquals( '10.0', $this->object->getLongitude() );
418
	}
419
420
421
	public function testSetLongitude()
422
	{
423
		$return = $this->object->setLongitude( '10.5' );
424
425
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
426
		$this->assertEquals( '10.5', $this->object->getLongitude() );
427
		$this->assertTrue( $this->object->isModified() );
428
	}
429
430
431
	public function testGetLatitude()
432
	{
433
		$this->assertEquals( '50.0', $this->object->getLatitude() );
434
	}
435
436
437
	public function testSetLatitude()
438
	{
439
		$return = $this->object->setLatitude( '53.5' );
440
441
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
442
		$this->assertEquals( '53.5', $this->object->getLatitude() );
443
		$this->assertTrue( $this->object->isModified() );
444
	}
445
446
447
	public function testGetPosition()
448
	{
449
		$this->assertEquals( 1, $this->object->getPosition() );
450
	}
451
452
453
	public function testSetPosition()
454
	{
455
		$return = $this->object->setPosition( 555 );
456
457
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
458
		$this->assertEquals( 555, $this->object->getPosition() );
459
		$this->assertTrue( $this->object->isModified() );
460
	}
461
462
463
	public function testGetBirthday()
464
	{
465
		$this->assertEquals( '2000-01-01', $this->object->getBirthday() );
466
	}
467
468
469
	public function testSetBirthday()
470
	{
471
		$return = $this->object->setBirthday( '1990-01-01' );
472
473
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
474
		$this->assertEquals( '1990-01-01', $this->object->getBirthday() );
475
		$this->assertTrue( $this->object->isModified() );
476
	}
477
478
479
	public function testGetTimeModified()
480
	{
481
		$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() );
482
	}
483
484
485
	public function testGetTimeCreated()
486
	{
487
		$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() );
488
	}
489
490
491
	public function testGetEditor()
492
	{
493
		$this->assertEquals( 'unitTestUser', $this->object->editor() );
494
	}
495
496
497
	public function testGetResourceType()
498
	{
499
		$this->assertEquals( 'customer/address', $this->object->getResourceType() );
500
	}
501
502
503
	public function testCopyFrom()
504
	{
505
		$address = new \Aimeos\MShop\Order\Item\Address\Standard();
506
		$return = $this->object->copyFrom( $address );
507
508
		$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Address\Iface::class, $return );
509
	}
510
511
512
	public function testFromArray()
513
	{
514
		$list = $entries = array(
515
			'customer.address.id' => 1,
516
			'customer.address.parentid' => 2,
517
			'customer.address.salutation' => 'mr',
518
			'customer.address.company' => 'mw',
519
			'customer.address.vatid' => 'vatnumber',
520
			'customer.address.title' => 'dr',
521
			'customer.address.firstname' => 'first',
522
			'customer.address.lastname' => 'last',
523
			'customer.address.address1' => 'street',
524
			'customer.address.address2' => 'no',
525
			'customer.address.address3' => 'flat',
526
			'customer.address.postal' => '12345',
527
			'customer.address.city' => 'city',
528
			'customer.address.state' => 'state',
529
			'customer.address.countryid' => 'DE',
530
			'customer.address.languageid' => 'de',
531
			'customer.address.telephone' => '01234',
532
			'customer.address.telefax' => '02345',
533
			'customer.address.mobile' => '03456',
534
			'customer.address.email' => '[email protected]',
535
			'customer.address.website' => 'example.com',
536
			'customer.address.birthday' => '1990-01-01',
537
			'customer.address.longitude' => '10.0',
538
			'customer.address.latitude' => '53.5',
539
			'customer.address.position' => 4,
540
		);
541
542
		$object = new \Aimeos\MShop\Common\Item\Address\Standard( 'customer.address.' );
543
		$object = $object->fromArray( $entries, true );
544
545
		$this->assertEquals( [], $entries );
546
547
		$this->assertEquals( $list['customer.address.id'], $object->getId() );
548
		$this->assertEquals( $list['customer.address.parentid'], $object->getParentId() );
549
		$this->assertEquals( $list['customer.address.salutation'], $object->getSalutation() );
550
		$this->assertEquals( $list['customer.address.company'], $object->getCompany() );
551
		$this->assertEquals( $list['customer.address.vatid'], $object->getVatID() );
552
		$this->assertEquals( $list['customer.address.title'], $object->getTitle() );
553
		$this->assertEquals( $list['customer.address.firstname'], $object->getFirstname() );
554
		$this->assertEquals( $list['customer.address.lastname'], $object->getLastname() );
555
		$this->assertEquals( $list['customer.address.address1'], $object->getAddress1() );
556
		$this->assertEquals( $list['customer.address.address2'], $object->getAddress2() );
557
		$this->assertEquals( $list['customer.address.address3'], $object->getAddress3() );
558
		$this->assertEquals( $list['customer.address.postal'], $object->getPostal() );
559
		$this->assertEquals( $list['customer.address.city'], $object->getCity() );
560
		$this->assertEquals( $list['customer.address.state'], $object->getState() );
561
		$this->assertEquals( $list['customer.address.countryid'], $object->getCountryId() );
562
		$this->assertEquals( $list['customer.address.languageid'], $object->getLanguageId() );
563
		$this->assertEquals( $list['customer.address.telephone'], $object->getTelephone() );
564
		$this->assertEquals( $list['customer.address.telefax'], $object->getTelefax() );
565
		$this->assertEquals( $list['customer.address.mobile'], $object->getMobile() );
566
		$this->assertEquals( $list['customer.address.email'], $object->getEmail() );
567
		$this->assertEquals( $list['customer.address.website'], $object->getWebsite() );
568
		$this->assertEquals( $list['customer.address.longitude'], $object->getLongitude() );
569
		$this->assertEquals( $list['customer.address.latitude'], $object->getLatitude() );
570
		$this->assertEquals( $list['customer.address.position'], $object->getPosition() );
571
		$this->assertEquals( $list['customer.address.birthday'], $object->getBirthday() );
572
	}
573
574
	public function testToArray()
575
	{
576
		$arrayObject = $this->object->toArray( true );
577
578
		$this->assertEquals( count( $this->values ), count( $arrayObject ) );
579
580
		$this->assertEquals( $this->object->getId(), $arrayObject['customer.address.id'] );
581
		$this->assertEquals( $this->object->getSiteId(), $arrayObject['customer.address.siteid'] );
582
		$this->assertEquals( $this->object->getParentId(), $arrayObject['customer.address.parentid'] );
583
		$this->assertEquals( $this->object->getPosition(), $arrayObject['customer.address.position'] );
584
		$this->assertEquals( $this->object->getCompany(), $arrayObject['customer.address.company'] );
585
		$this->assertEquals( $this->object->getVatID(), $arrayObject['customer.address.vatid'] );
586
		$this->assertEquals( $this->object->getSalutation(), $arrayObject['customer.address.salutation'] );
587
		$this->assertEquals( $this->object->getTitle(), $arrayObject['customer.address.title'] );
588
		$this->assertEquals( $this->object->getFirstname(), $arrayObject['customer.address.firstname'] );
589
		$this->assertEquals( $this->object->getLastname(), $arrayObject['customer.address.lastname'] );
590
		$this->assertEquals( $this->object->getAddress1(), $arrayObject['customer.address.address1'] );
591
		$this->assertEquals( $this->object->getAddress2(), $arrayObject['customer.address.address2'] );
592
		$this->assertEquals( $this->object->getAddress3(), $arrayObject['customer.address.address3'] );
593
		$this->assertEquals( $this->object->getPostal(), $arrayObject['customer.address.postal'] );
594
		$this->assertEquals( $this->object->getCity(), $arrayObject['customer.address.city'] );
595
		$this->assertEquals( $this->object->getState(), $arrayObject['customer.address.state'] );
596
		$this->assertEquals( $this->object->getCountryId(), $arrayObject['customer.address.countryid'] );
597
		$this->assertEquals( $this->object->getLanguageId(), $arrayObject['customer.address.languageid'] );
598
		$this->assertEquals( $this->object->getTelephone(), $arrayObject['customer.address.telephone'] );
599
		$this->assertEquals( $this->object->getMobile(), $arrayObject['customer.address.mobile'] );
600
		$this->assertEquals( $this->object->getEmail(), $arrayObject['customer.address.email'] );
601
		$this->assertEquals( $this->object->getTelefax(), $arrayObject['customer.address.telefax'] );
602
		$this->assertEquals( $this->object->getWebsite(), $arrayObject['customer.address.website'] );
603
		$this->assertEquals( $this->object->getLongitude(), $arrayObject['customer.address.longitude'] );
604
		$this->assertEquals( $this->object->getLatitude(), $arrayObject['customer.address.latitude'] );
605
		$this->assertEquals( $this->object->getBirthday(), $arrayObject['customer.address.birthday'] );
606
		$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['customer.address.ctime'] );
607
		$this->assertEquals( $this->object->getTimeModified(), $arrayObject['customer.address.mtime'] );
608
		$this->assertEquals( $this->object->editor(), $arrayObject['customer.address.editor'] );
609
	}
610
611
	public function testIsModified()
612
	{
613
		$this->assertFalse( $this->object->isModified() );
614
	}
615
}
616