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