Completed
Push — master ( 94b58b...843436 )
by Aimeos
02:17
created

LaravelTest::testGetSaveAddressItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2017
6
 */
7
8
9
namespace Aimeos\MShop\Customer\Manager;
10
11
12
class LaravelTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $fixture;
16
	private $address;
17
	private $editor = '';
18
19
20
	protected function setUp()
21
	{
22
		$context = \TestHelper::getContext();
23
		$this->editor = $context->getEditor();
24
		$this->object = new \Aimeos\MShop\Customer\Manager\Laravel( $context );
25
26
		$this->fixture = array(
27
			'label' => 'unitTest',
28
			'status' => 2,
29
		);
30
31
		$this->address = new \Aimeos\MShop\Common\Item\Address\Standard( 'common.address.' );
32
	}
33
34
35
	protected function tearDown()
36
	{
37
		unset( $this->object, $this->fixture, $this->address );
38
	}
39
40
41
	public function testCleanup()
42
	{
43
		$this->object->cleanup( array( -1 ) );
44
	}
45
46
47
	public function testGetSearchAttributes()
48
	{
49
		foreach( $this->object->getSearchAttributes() as $attribute )
50
		{
51
			$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute );
52
		}
53
	}
54
55
56
	public function testCreateItem()
57
	{
58
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $this->object->createItem() );
59
	}
60
61
62
	public function testGetItem()
63
	{
64
		$search = $this->object->createSearch();
65
		$conditions = array(
66
			$search->compare( '==', 'customer.code', 'UTC003' ),
67
			$search->compare( '==', 'customer.editor', $this->editor )
68
		);
69
		$search->setConditions( $search->combine( '&&', $conditions ) );
70
		$items = $this->object->searchItems( $search, array( 'text' ) );
71
72
		if( ( $expected = reset( $items ) ) === false ) {
73
			throw new \RuntimeException( 'No customer item with code "UTC003" found' );
74
		}
75
76
		$actual = $this->object->getItem( $expected->getId(), array( 'text' ) );
77
78
		$this->assertEquals( $expected, $actual );
79
		$this->assertEquals( 3, count( $actual->getListItems( 'text' ) ) );
80
		$this->assertEquals( 3, count( $actual->getRefItems( 'text' ) ) );
81
	}
82
83
84
	public function testSaveUpdateDeleteItem()
85
	{
86
		$item = $this->object->createItem();
87
88
		$item->setCode( 'unitTest' );
89
		$item->setLabel( 'unitTest' );
90
		$resultSaved = $this->object->saveItem( $item );
91
		$itemSaved = $this->object->getItem( $item->getId() );
92
93
		$itemExp = clone $itemSaved;
94
		$itemExp->setCode( 'unitTest2' );
95
		$itemExp->setLabel( 'unitTest2' );
96
		$resultUpd = $this->object->saveItem( $itemExp );
97
		$itemUpd = $this->object->getItem( $itemExp->getId() );
98
99
		$this->object->deleteItem( $item->getId() );
100
101
		$this->assertTrue( $item->getId() !== null );
102
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
103
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
104
		$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() );
105
		$this->assertEquals( $item->getCode(), $itemSaved->getCode() );
106
		$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() );
107
		$this->assertEquals( $item->getPaymentAddress(), $itemSaved->getPaymentAddress() );
108
		$this->assertEquals( $item->getBirthday(), $itemSaved->getBirthday() );
109
		$this->assertEquals( $item->getPassword(), $itemSaved->getPassword() );
110
111
		$this->assertEquals( $this->editor, $itemSaved->getEditor() );
112
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
113
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
114
115
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
116
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
117
		$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() );
118
		$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() );
119
		$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() );
120
		$this->assertEquals( $itemExp->getPaymentAddress(), $itemUpd->getPaymentAddress() );
121
		$this->assertEquals( $itemExp->getBirthday(), $itemUpd->getBirthday() );
122
		$this->assertEquals( $itemExp->getPassword(), $itemUpd->getPassword() );
123
124
		$this->assertEquals( $this->editor, $itemUpd->getEditor() );
125
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
126
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
127
128
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved );
129
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd );
130
131
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
132
		$this->object->getItem( $item->getId() );
133
	}
134
135
136 View Code Duplication
	public function testGetSaveAddressItems()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
	{
138
		$item = $this->object->findItem( 'UTC001', ['customer/address'] );
139
140
		$item->setId( null )->setCode( 'xyz' );
141
		$item->getPaymentAddress()->setEmail( '[email protected]' );
142
		$item->addAddressItem( new \Aimeos\MShop\Common\Item\Address\Standard( 'customer.address.' ) );
0 ignored issues
show
Bug introduced by
The method addAddressItem() does not seem to exist on object<Aimeos\MShop\Common\Item\Iface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
143
		$this->object->saveItem( $item );
144
145
		$item2 = $this->object->findItem( 'xyz', ['customer/address'] );
146
147
		$this->object->deleteItem( $item->getId() );
148
149
		$this->assertEquals( 2, count( $item->getAddressItems() ) );
150
		$this->assertEquals( 2, count( $item2->getAddressItems() ) );
151
	}
152
153
154 View Code Duplication
	public function testGetSavePropertyItems()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155
	{
156
		$item = $this->object->findItem( 'UTC001', ['customer/property'] );
157
158
		$item->setId( null )->setCode( 'xyz' );
159
		$item->getPaymentAddress()->setEmail( '[email protected]' );
160
		$this->object->saveItem( $item );
161
162
		$item2 = $this->object->findItem( 'xyz', ['customer/property'] );
163
164
		$this->object->deleteItem( $item->getId() );
165
166
		$this->assertEquals( 1, count( $item->getPropertyItems() ) );
167
		$this->assertEquals( 1, count( $item2->getPropertyItems() ) );
168
	}
169
170
171
	public function testCreateSearch()
172
	{
173
		$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() );
174
	}
175
176
177
	public function testSearchItems()
178
	{
179
		$total = 0;
180
		$search = $this->object->createSearch();
181
182
		$expr = [];
183
		$expr[] = $search->compare( '!=', 'customer.id', null );
184
		$expr[] = $search->compare( '==', 'customer.label', 'unitCustomer2' );
185
		$expr[] = $search->compare( '==', 'customer.code', 'UTC002' );
186
187
		$expr[] = $search->compare( '>=', 'customer.salutation', '' );
188
		$expr[] = $search->compare( '>=', 'customer.company', '' );
189
		$expr[] = $search->compare( '>=', 'customer.vatid', '' );
190
		$expr[] = $search->compare( '>=', 'customer.title', '' );
191
		$expr[] = $search->compare( '>=', 'customer.firstname', '' );
192
		$expr[] = $search->compare( '>=', 'customer.lastname', '' );
193
		$expr[] = $search->compare( '>=', 'customer.address1', '' );
194
		$expr[] = $search->compare( '>=', 'customer.address2', '' );
195
		$expr[] = $search->compare( '>=', 'customer.address3', '' );
196
		$expr[] = $search->compare( '>=', 'customer.postal', '' );
197
		$expr[] = $search->compare( '>=', 'customer.city', '' );
198
		$expr[] = $search->compare( '>=', 'customer.state', '' );
199
		$expr[] = $search->compare( '!=', 'customer.languageid', null );
200
		$expr[] = $search->compare( '>=', 'customer.countryid', '' );
201
		$expr[] = $search->compare( '>=', 'customer.telephone', '' );
202
		$expr[] = $search->compare( '>=', 'customer.email', '' );
203
		$expr[] = $search->compare( '>=', 'customer.telefax', '' );
204
		$expr[] = $search->compare( '>=', 'customer.website', '' );
205
		$expr[] = $search->compare( '>=', 'customer.longitude', '10.0' );
206
		$expr[] = $search->compare( '>=', 'customer.latitude', '50.0' );
207
208
		$expr[] = $search->compare( '==', 'customer.birthday', '1970-01-01' );
209
		$expr[] = $search->compare( '>=', 'customer.password', '' );
210
		$expr[] = $search->compare( '==', 'customer.status', 0 );
211
		$expr[] = $search->compare( '!=', 'customer.mtime', '1970-01-01 00:00:00' );
212
		$expr[] = $search->compare( '!=', 'customer.ctime', '1970-01-01 00:00:00' );
213
		$expr[] = $search->compare( '==', 'customer.editor', $this->editor );
214
215
		$expr[] = $search->compare( '!=', 'customer.address.id', null );
216
		$expr[] = $search->compare( '!=', 'customer.address.parentid', null );
217
		$expr[] = $search->compare( '==', 'customer.address.company', 'ABC GmbH' );
218
		$expr[] = $search->compare( '==', 'customer.address.vatid', 'DE999999999' );
219
		$expr[] = $search->compare( '==', 'customer.address.salutation', 'mr' );
220
		$expr[] = $search->compare( '==', 'customer.address.title', 'Dr.' );
221
		$expr[] = $search->compare( '==', 'customer.address.firstname', 'Good' );
222
		$expr[] = $search->compare( '==', 'customer.address.lastname', 'Unittest' );
223
		$expr[] = $search->compare( '==', 'customer.address.address1', 'Pickhuben' );
224
		$expr[] = $search->compare( '==', 'customer.address.address2', '2-4' );
225
		$expr[] = $search->compare( '==', 'customer.address.address3', '' );
226
		$expr[] = $search->compare( '==', 'customer.address.postal', '11099' );
227
		$expr[] = $search->compare( '==', 'customer.address.city', 'Berlin' );
228
		$expr[] = $search->compare( '==', 'customer.address.state', 'Berlin' );
229
		$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' );
230
		$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' );
231
		$expr[] = $search->compare( '==', 'customer.address.telephone', '055544332221' );
232
		$expr[] = $search->compare( '==', 'customer.address.email', '[email protected]' );
233
		$expr[] = $search->compare( '==', 'customer.address.telefax', '055544333212' );
234
		$expr[] = $search->compare( '==', 'customer.address.website', 'unittest.aimeos.org' );
235
		$expr[] = $search->compare( '>=', 'customer.address.longitude', '10.0' );
236
		$expr[] = $search->compare( '>=', 'customer.address.latitude', '50.0' );
237
		$expr[] = $search->compare( '==', 'customer.address.flag', 0 );
238
		$expr[] = $search->compare( '==', 'customer.address.position', 1 );
239
		$expr[] = $search->compare( '!=', 'customer.address.mtime', '1970-01-01 00:00:00' );
240
		$expr[] = $search->compare( '!=', 'customer.address.ctime', '1970-01-01 00:00:00' );
241
		$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor );
242
243
		$search->setConditions( $search->combine( '&&', $expr ) );
244
		$result = $this->object->searchItems( $search, [], $total );
245
		$this->assertEquals( 1, count( $result ) );
246
	}
247
248
249
	public function testSearchItemsTotal()
250
	{
251
		$total = 0;
252
253
		$search = $this->object->createSearch();
254
		$search->setConditions( $search->compare( '==', 'customer.address.editor', $this->editor ) );
255
		$search->setSlice( 0, 2 );
256
257
		$results = $this->object->searchItems( $search, [], $total );
258
		$this->assertEquals( 2, count( $results ) );
259
		$this->assertEquals( 3, $total );
260
261
		foreach($results as $itemId => $item) {
262
			$this->assertEquals( $itemId, $item->getId() );
263
		}
264
	}
265
266
267 View Code Duplication
	public function testSearchItemsCriteria()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
268
	{
269
		$search = $this->object->createSearch( true );
270
		$conditions = array(
271
			$search->compare( '==', 'customer.address.editor', $this->editor ),
272
			$search->getConditions()
273
		);
274
		$search->setConditions( $search->combine( '&&', $conditions ) );
275
		$this->assertEquals( 2, count( $this->object->searchItems( $search, [], $total ) ) );
276
	}
277
278
279
	public function testSearchItemsRef()
280
	{
281
		$search = $this->object->createSearch();
282
		$search->setConditions( $search->compare( '==', 'customer.code', 'UTC001' ) );
283
284
		$results = $this->object->searchItems( $search, ['customer/address', 'text'] );
285
286
		if( ( $item = reset( $results ) ) === false ) {
287
			throw new \Exception( 'No customer item for "UTC001" available' );
288
		}
289
290
		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) );
291
		$this->assertEquals( 1, count( $item->getAddressItems() ) );
292
	}
293
294
295 View Code Duplication
	public function testGetSubManager()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
296
	{
297
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address' ) );
298
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address', 'Standard' ) );
299
300
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
301
		$this->object->getSubManager( 'unknown' );
302
	}
303
304
305
	public function testGetSubManagerInvalidName()
306
	{
307
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
308
		$this->object->getSubManager( 'address', 'unknown' );
309
	}
310
}
311