Passed
Push — master ( be8b0f...6b51fc )
by Aimeos
05:27
created

StandardTest::testSetPositionInvalid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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