Passed
Push — master ( 3311dc...3c99d6 )
by Aimeos
05:26
created

tests/MShop/Common/Item/Address/StandardTest.php (2 issues)

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-2018
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()
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.email' => '[email protected]',
41
			'common.address.telefax' => '05554433222',
42
			'common.address.website' => 'www.example.com',
43
			'common.address.longitude' => '10.0',
44
			'common.address.latitude' => '50.0',
45
			'common.address.position' => 1,
46
			'common.address.mtime' => '2011-01-01 00:00:02',
47
			'common.address.ctime' => '2011-01-01 00:00:01',
48
			'common.address.editor' => 'unitTestUser',
49
		);
50
51
		$this->object = new \Aimeos\MShop\Common\Item\Address\Standard( 'common.address.', $this->values );
52
	}
53
54
55
	protected function tearDown()
56
	{
57
		$this->object = null;
58
	}
59
60
61
	public function testGetId()
62
	{
63
		$this->assertEquals( 23, $this->object->getId() );
64
	}
65
66
67
	public function testSetId()
68
	{
69
		$return = $this->object->setId( null );
70
71
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
72
		$this->assertTrue( $this->object->isModified() );
73
		$this->assertNull( $this->object->getId() );
74
	}
75
76
77
	public function testGetParentfId()
78
	{
79
		$this->assertEquals( 'referenceid', $this->object->getParentId() );
80
	}
81
82
83
	public function testSetParentId()
84
	{
85
		$return = $this->object->setParentId( 'unitreference' );
86
87
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
88
		$this->assertTrue( $this->object->isModified() );
89
		$this->assertEquals( 'unitreference', $this->object->getParentId() );
90
	}
91
92
93
	public function testGetCompany()
94
	{
95
		$this->assertEquals( 'unitCompany', $this->object->getCompany() );
96
	}
97
98
99
	public function testSetCompany()
100
	{
101
		$return = $this->object->setCompany( 'company' );
102
103
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
104
		$this->assertEquals( 'company', $this->object->getCompany() );
105
		$this->assertTrue( $this->object->isModified() );
106
	}
107
108
109
	public function testGetVatID()
0 ignored issues
show
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
110
	{
111
		$this->assertEquals( 'DE999999999', $this->object->getVatID() );
112
	}
113
114
115
	public function testSetVatID()
0 ignored issues
show
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
116
	{
117
		$return = $this->object->setVatID( 'vatid' );
118
119
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
120
		$this->assertEquals( 'vatid', $this->object->getVatID() );
121
		$this->assertTrue( $this->object->isModified() );
122
	}
123
124
125
	public function testGetSalutation()
126
	{
127
		$this->assertEquals( \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, $this->object->getSalutation() );
128
	}
129
130
131
	public function testSetSalutation()
132
	{
133
		$return = $this->object->setSalutation( \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY );
134
135
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
136
		$this->assertEquals( \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_COMPANY, $this->object->getSalutation() );
137
		$this->assertTrue( $this->object->isModified() );
138
	}
139
140
141
	public function testGetTitle()
142
	{
143
		$this->assertEquals( 'Herr', $this->object->getTitle() );
144
	}
145
146
147
	public function testSetTitle()
148
	{
149
		$return = $this->object->setTitle( 'Dr.' );
150
151
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
152
		$this->assertEquals( 'Dr.', $this->object->getTitle() );
153
		$this->assertTrue( $this->object->isModified() );
154
	}
155
156
157
	public function testGetFirstname()
158
	{
159
		$this->assertEquals( 'firstunit', $this->object->getFirstname() );
160
	}
161
162
163
	public function testSetFirstname()
164
	{
165
		$return = $this->object->setFirstname( 'hans' );
166
167
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
168
		$this->assertEquals( 'hans', $this->object->getFirstname() );
169
		$this->assertTrue( $this->object->isModified() );
170
	}
171
172
173
	public function testGetLastname()
174
	{
175
		$this->assertEquals( 'lastunit', $this->object->getLastname() );
176
	}
177
178
179
	public function testSetLastname()
180
	{
181
		$return = $this->object->setLastname( 'im Glueck' );
182
183
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
184
		$this->assertEquals( 'im Glueck', $this->object->getLastname() );
185
		$this->assertTrue( $this->object->isModified() );
186
	}
187
188
189
	public function testGetAddress1()
190
	{
191
		$this->assertEquals( 'unit str.', $this->object->getAddress1() );
192
	}
193
194
195
	public function testSetAddress1()
196
	{
197
		$return = $this->object->setAddress1( 'unitallee' );
198
199
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
200
		$this->assertEquals( 'unitallee', $this->object->getAddress1() );
201
		$this->assertTrue( $this->object->isModified() );
202
	}
203
204
205
	public function testGetAddress2()
206
	{
207
		$this->assertEquals( '166', $this->object->getAddress2() );
208
	}
209
210
211
	public function testSetAddress2()
212
	{
213
		$return = $this->object->setAddress2( '12' );
214
215
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
216
		$this->assertEquals( '12', $this->object->getAddress2() );
217
		$this->assertTrue( $this->object->isModified() );
218
	}
219
220
221
	public function testGetAddress3()
222
	{
223
		$this->assertEquals( '4.OG', $this->object->getAddress3() );
224
	}
225
226
227
	public function testSetAddress3()
228
	{
229
		$return = $this->object->setAddress3( 'EG' );
230
231
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
232
		$this->assertEquals( 'EG', $this->object->getAddress3() );
233
		$this->assertTrue( $this->object->isModified() );
234
	}
235
236
237
	public function testGetPostal()
238
	{
239
		$this->assertEquals( '22769', $this->object->getPostal() );
240
	}
241
242
243
	public function testSetPostal()
244
	{
245
		$return = $this->object->setPostal( '11111' );
246
247
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
248
		$this->assertEquals( '11111', $this->object->getPostal() );
249
		$this->assertTrue( $this->object->isModified() );
250
	}
251
252
253
	public function testGetCity()
254
	{
255
		$this->assertEquals( 'Hamburg', $this->object->getCity() );
256
	}
257
258
259
	public function testSetCity()
260
	{
261
		$return = $this->object->setCity( 'unitCity' );
262
263
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
264
		$this->assertEquals( 'unitCity', $this->object->getCity() );
265
		$this->assertTrue( $this->object->isModified() );
266
	}
267
268
269
	public function testGetState()
270
	{
271
		$this->assertEquals( 'Hamburg', $this->object->getState() );
272
	}
273
274
275
	public function testSetState()
276
	{
277
		$return = $this->object->setState( 'unitState' );
278
279
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
280
		$this->assertEquals( 'unitState', $this->object->getState() );
281
		$this->assertTrue( $this->object->isModified() );
282
	}
283
284
285
	public function testGetCountryId()
286
	{
287
		$this->assertEquals( 'DE', $this->object->getCountryId() );
288
	}
289
290
291
	public function testSetCountryId()
292
	{
293
		$return = $this->object->setCountryId( 'uk' );
294
295
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
296
		$this->assertEquals( 'UK', $this->object->getCountryId() );
297
		$this->assertTrue( $this->object->isModified() );
298
	}
299
300
301
	public function testGetLanguageId()
302
	{
303
		$this->assertEquals( 'de', $this->object->getLanguageId() );
304
	}
305
306
307
	public function testSetLanguageId()
308
	{
309
		$return = $this->object->setLanguageId( 'en' );
310
311
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
312
		$this->assertEquals( 'en', $this->object->getLanguageId() );
313
		$this->assertTrue( $this->object->isModified() );
314
	}
315
316
317
	public function testGetTelephone()
318
	{
319
		$this->assertEquals( '05554433221', $this->object->getTelephone() );
320
	}
321
322
323
	public function testSetTelephone()
324
	{
325
		$return = $this->object->setTelephone( '55512345' );
326
327
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
328
		$this->assertEquals( '55512345', $this->object->getTelephone() );
329
		$this->assertTrue( $this->object->isModified() );
330
	}
331
332
333
	public function testGetEmail()
334
	{
335
		$this->assertEquals( '[email protected]', $this->object->getEmail() );
336
	}
337
338
339
	public function testSetEmail()
340
	{
341
		$return = $this->object->setEmail( '[email protected]' );
342
343
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
344
		$this->assertEquals( '[email protected]', $this->object->getEmail() );
345
		$this->assertTrue( $this->object->isModified() );
346
347
		$this->setExpectedException( \Aimeos\MShop\Exception::class );
348
		$this->object->setEmail( 'unittest.de' );
349
	}
350
351
352
	public function testGetTelefax()
353
	{
354
		$this->assertEquals( '05554433222', $this->object->getTelefax() );
355
	}
356
357
358
	public function testSetTelefax()
359
	{
360
		$return = $this->object->setTelefax( '55512345' );
361
362
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
363
		$this->assertEquals( '55512345', $this->object->getTelefax() );
364
		$this->assertTrue( $this->object->isModified() );
365
	}
366
367
368
	public function testGetWebsite()
369
	{
370
		$this->assertEquals( 'www.example.com', $this->object->getWebsite() );
371
	}
372
373
374
	public function testSetWebsite()
375
	{
376
		$return = $this->object->setWebsite( 'www.test.de' );
377
378
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
379
		$this->assertEquals( 'www.test.de', $this->object->getWebsite() );
380
		$this->assertTrue( $this->object->isModified() );
381
382
		$this->object->setWebsite( 'http://xn--ses-5ka8l.de' );
383
		$this->object->setWebsite( 'http://www.test.de:443' );
384
		$this->object->setWebsite( 'https://www.test.de:8080/abc?123' );
385
386
		$this->setExpectedException( \Aimeos\MShop\Exception::class );
387
		$this->object->setWebsite( '_test:de' );
388
	}
389
390
391
	public function testSetWebsiteHostException()
392
	{
393
		$this->setExpectedException( \Aimeos\MShop\Exception::class );
394
		$this->object->setWebsite( 'localhost' );
395
	}
396
397
398
	public function testGetLongitude()
399
	{
400
		$this->assertEquals( '10.0', $this->object->getLongitude() );
401
	}
402
403
404
	public function testSetLongitude()
405
	{
406
		$return = $this->object->setLongitude( '10.5' );
407
408
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
409
		$this->assertEquals( '10.5', $this->object->getLongitude() );
410
		$this->assertTrue( $this->object->isModified() );
411
	}
412
413
414
	public function testGetLatitude()
415
	{
416
		$this->assertEquals( '50.0', $this->object->getLatitude() );
417
	}
418
419
420
	public function testSetLatitude()
421
	{
422
		$return = $this->object->setLatitude( '53.5' );
423
424
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
425
		$this->assertEquals( '53.5', $this->object->getLatitude() );
426
		$this->assertTrue( $this->object->isModified() );
427
	}
428
429
430
	public function testGetPosition()
431
	{
432
		$this->assertEquals( 1, $this->object->getPosition() );
433
	}
434
435
436
	public function testSetPosition()
437
	{
438
		$return = $this->object->setPosition( 555 );
439
440
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
441
		$this->assertEquals( 555, $this->object->getPosition() );
442
		$this->assertTrue( $this->object->isModified() );
443
	}
444
445
446
	public function testGetTimeModified()
447
	{
448
		$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() );
449
	}
450
451
452
	public function testGetTimeCreated()
453
	{
454
		$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() );
455
	}
456
457
458
	public function testGetEditor()
459
	{
460
		$this->assertEquals( 'unitTestUser', $this->object->getEditor() );
461
	}
462
463
464
	public function testGetResourceType()
465
	{
466
		$this->assertEquals( 'common/address', $this->object->getResourceType() );
467
	}
468
469
470
	public function testCopyFrom()
471
	{
472
		$address = new \Aimeos\MShop\Order\Item\Base\Address\Standard();
473
		$return = $this->object->copyFrom( $address );
474
475
		$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $return );
476
	}
477
478
	public function testFromArray()
479
	{
480
		$list = $entries = array(
481
			'common.address.id' => 1,
482
			'common.address.parentid' => 2,
483
			'common.address.salutation' => 'mr',
484
			'common.address.company' => 'mw',
485
			'common.address.vatid' => 'vatnumber',
486
			'common.address.title' => 'dr',
487
			'common.address.firstname' => 'first',
488
			'common.address.lastname' => 'last',
489
			'common.address.address1' => 'street',
490
			'common.address.address2' => 'no',
491
			'common.address.address3' => 'flat',
492
			'common.address.postal' => '12345',
493
			'common.address.city' => 'city',
494
			'common.address.state' => 'state',
495
			'common.address.countryid' => 'DE',
496
			'common.address.languageid' => 'de',
497
			'common.address.telephone' => '01234',
498
			'common.address.telefax' => '02345',
499
			'common.address.email' => 'a@b',
500
			'common.address.website' => 'example.com',
501
			'common.address.longitude' => '10.0',
502
			'common.address.latitude' => '53.5',
503
			'common.address.position' => 4,
504
		);
505
506
		$object = new \Aimeos\MShop\Common\Item\Address\Standard( 'common.address.' );
507
		$object = $object->fromArray( $entries, true );
508
509
		$this->assertEquals( [], $entries );
510
		$this->assertEquals( $list['common.address.id'], $object->getId() );
511
		$this->assertEquals( $list['common.address.parentid'], $object->getParentId() );
512
		$this->assertEquals( $list['common.address.salutation'], $object->getSalutation() );
513
		$this->assertEquals( $list['common.address.company'], $object->getCompany() );
514
		$this->assertEquals( $list['common.address.vatid'], $object->getVatID() );
515
		$this->assertEquals( $list['common.address.title'], $object->getTitle() );
516
		$this->assertEquals( $list['common.address.firstname'], $object->getFirstname() );
517
		$this->assertEquals( $list['common.address.lastname'], $object->getLastname() );
518
		$this->assertEquals( $list['common.address.address1'], $object->getAddress1() );
519
		$this->assertEquals( $list['common.address.address2'], $object->getAddress2() );
520
		$this->assertEquals( $list['common.address.address3'], $object->getAddress3() );
521
		$this->assertEquals( $list['common.address.postal'], $object->getPostal() );
522
		$this->assertEquals( $list['common.address.city'], $object->getCity() );
523
		$this->assertEquals( $list['common.address.state'], $object->getState() );
524
		$this->assertEquals( $list['common.address.countryid'], $object->getCountryId() );
525
		$this->assertEquals( $list['common.address.languageid'], $object->getLanguageId() );
526
		$this->assertEquals( $list['common.address.telephone'], $object->getTelephone() );
527
		$this->assertEquals( $list['common.address.telefax'], $object->getTelefax() );
528
		$this->assertEquals( $list['common.address.email'], $object->getEmail() );
529
		$this->assertEquals( $list['common.address.website'], $object->getWebsite() );
530
		$this->assertEquals( $list['common.address.longitude'], $object->getLongitude() );
531
		$this->assertEquals( $list['common.address.latitude'], $object->getLatitude() );
532
		$this->assertEquals( $list['common.address.position'], $object->getPosition() );
533
	}
534
535
	public function testToArray()
536
	{
537
		$arrayObject = $this->object->toArray( true );
538
539
		$this->assertEquals( count( $this->values ), count( $arrayObject ) );
540
541
		$this->assertEquals( $this->object->getId(), $arrayObject['common.address.id'] );
542
		$this->assertEquals( $this->object->getSiteId(), $arrayObject['common.address.siteid'] );
543
		$this->assertEquals( $this->object->getParentId(), $arrayObject['common.address.parentid'] );
544
		$this->assertEquals( $this->object->getPosition(), $arrayObject['common.address.position'] );
545
		$this->assertEquals( $this->object->getCompany(), $arrayObject['common.address.company'] );
546
		$this->assertEquals( $this->object->getVatID(), $arrayObject['common.address.vatid'] );
547
		$this->assertEquals( $this->object->getSalutation(), $arrayObject['common.address.salutation'] );
548
		$this->assertEquals( $this->object->getTitle(), $arrayObject['common.address.title'] );
549
		$this->assertEquals( $this->object->getFirstname(), $arrayObject['common.address.firstname'] );
550
		$this->assertEquals( $this->object->getLastname(), $arrayObject['common.address.lastname'] );
551
		$this->assertEquals( $this->object->getAddress1(), $arrayObject['common.address.address1'] );
552
		$this->assertEquals( $this->object->getAddress2(), $arrayObject['common.address.address2'] );
553
		$this->assertEquals( $this->object->getAddress3(), $arrayObject['common.address.address3'] );
554
		$this->assertEquals( $this->object->getPostal(), $arrayObject['common.address.postal'] );
555
		$this->assertEquals( $this->object->getCity(), $arrayObject['common.address.city'] );
556
		$this->assertEquals( $this->object->getState(), $arrayObject['common.address.state'] );
557
		$this->assertEquals( $this->object->getCountryId(), $arrayObject['common.address.countryid'] );
558
		$this->assertEquals( $this->object->getLanguageId(), $arrayObject['common.address.languageid'] );
559
		$this->assertEquals( $this->object->getTelephone(), $arrayObject['common.address.telephone'] );
560
		$this->assertEquals( $this->object->getEmail(), $arrayObject['common.address.email'] );
561
		$this->assertEquals( $this->object->getTelefax(), $arrayObject['common.address.telefax'] );
562
		$this->assertEquals( $this->object->getWebsite(), $arrayObject['common.address.website'] );
563
		$this->assertEquals( $this->object->getLongitude(), $arrayObject['common.address.longitude'] );
564
		$this->assertEquals( $this->object->getLatitude(), $arrayObject['common.address.latitude'] );
565
		$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['common.address.ctime'] );
566
		$this->assertEquals( $this->object->getTimeModified(), $arrayObject['common.address.mtime'] );
567
		$this->assertEquals( $this->object->getEditor(), $arrayObject['common.address.editor'] );
568
	}
569
570
	public function testIsModified()
571
	{
572
		$this->assertFalse( $this->object->isModified() );
573
	}
574
}
575