Completed
Push — master ( 2804eb...df2cda )
by Aimeos
02:03
created

LaravelTest::testGetSubManagerInvalidName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Aimeos\MShop\Customer\Manager;
4
5
6
/**
7
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
8
 * @copyright Aimeos (aimeos.org), 2015-2017
9
 */
10
class LaravelTest extends \PHPUnit\Framework\TestCase
11
{
12
	private $object;
13
	private $fixture;
14
	private $address;
15
	private $editor = 'ai-laravel:unittest';
16
17
18
	protected function setUp()
19
	{
20
		$context = \TestHelper::getContext();
21
		$this->editor = $context->getEditor();
22
		$this->object = new \Aimeos\MShop\Customer\Manager\Laravel( $context );
23
24
		$this->fixture = array(
25
			'label' => 'unitTest',
26
			'status' => 2,
27
		);
28
29
		$this->address = new \Aimeos\MShop\Common\Item\Address\Standard( 'common.address.' );
30
	}
31
32
33
	protected function tearDown()
34
	{
35
		unset( $this->object, $this->fixture, $this->address );
36
	}
37
38
39
	public function testCleanup()
40
	{
41
		$this->object->cleanup( array( -1 ) );
42
	}
43
44
45
	public function testGetSearchAttributes()
46
	{
47
		foreach( $this->object->getSearchAttributes() as $attribute )
48
		{
49
			$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute );
50
		}
51
	}
52
53
54
	public function testCreateItem()
55
	{
56
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $this->object->createItem() );
57
	}
58
59
60
	public function testGetItem()
61
	{
62
		$search = $this->object->createSearch();
63
		$conditions = array(
64
			$search->compare( '==', 'customer.code', 'unitCustomer3' ),
65
			$search->compare( '==', 'customer.editor', $this->editor )
66
		);
67
		$search->setConditions( $search->combine( '&&', $conditions ) );
68
		$items = $this->object->searchItems( $search, array( 'text' ) );
69
70
		if( ( $expected = reset( $items ) ) === false ) {
71
			throw new \RuntimeException( 'No customer item with code "unitCustomer3" found' );
72
		}
73
74
		$actual = $this->object->getItem( $expected->getId(), array( 'text' ) );
75
76
		$this->assertEquals( $expected, $actual );
77
		$this->assertEquals( 3, count( $actual->getListItems( 'text' ) ) );
78
		$this->assertEquals( 3, count( $actual->getRefItems( 'text' ) ) );
79
	}
80
81
82
	public function testSaveUpdateDeleteItem()
83
	{
84
		$item = $this->object->createItem();
85
86
		$item->setCode( 'unitTest' );
87
		$item->setLabel( 'unitTest' );
88
		$resultSaved = $this->object->saveItem( $item );
89
		$itemSaved = $this->object->getItem( $item->getId() );
90
91
		$itemExp = clone $itemSaved;
92
		$itemExp->setCode( 'unitTest2' );
93
		$itemExp->setLabel( 'unitTest2' );
94
		$resultUpd = $this->object->saveItem( $itemExp );
95
		$itemUpd = $this->object->getItem( $itemExp->getId() );
96
97
		$this->object->deleteItem( $item->getId() );
98
99
		$this->assertTrue( $item->getId() !== null );
100
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
101
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
102
		$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() );
103
		$this->assertEquals( $item->getCode(), $itemSaved->getCode() );
104
		$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() );
105
		$this->assertEquals( $item->getPaymentAddress(), $itemSaved->getPaymentAddress() );
106
		$this->assertEquals( $item->getBirthday(), $itemSaved->getBirthday() );
107
		$this->assertEquals( $item->getPassword(), $itemSaved->getPassword() );
108
109
		$this->assertEquals( $this->editor, $itemSaved->getEditor() );
110
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
111
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
112
113
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
114
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
115
		$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() );
116
		$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() );
117
		$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() );
118
		$this->assertEquals( $itemExp->getPaymentAddress(), $itemUpd->getPaymentAddress() );
119
		$this->assertEquals( $itemExp->getBirthday(), $itemUpd->getBirthday() );
120
		$this->assertEquals( $itemExp->getPassword(), $itemUpd->getPassword() );
121
122
		$this->assertEquals( $this->editor, $itemUpd->getEditor() );
123
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
124
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
125
126
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved );
127
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd );
128
129
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
130
		$this->object->getItem( $item->getId() );
131
	}
132
133
134
	public function testCreateSearch()
135
	{
136
		$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() );
137
	}
138
139
140
	public function testSearchItems()
141
	{
142
		$total = 0;
143
		$search = $this->object->createSearch();
144
145
		$expr = [];
146
		$expr[] = $search->compare( '!=', 'customer.id', null );
147
		$expr[] = $search->compare( '==', 'customer.label', 'Erika Mustermann' );
148
		$expr[] = $search->compare( '==', 'customer.code', 'unitCustomer2' );
149
150
		$expr[] = $search->compare( '>=', 'customer.salutation', '' );
151
		$expr[] = $search->compare( '>=', 'customer.company', '' );
152
		$expr[] = $search->compare( '>=', 'customer.vatid', '' );
153
		$expr[] = $search->compare( '>=', 'customer.title', '' );
154
		$expr[] = $search->compare( '>=', 'customer.firstname', '' );
155
		$expr[] = $search->compare( '>=', 'customer.lastname', '' );
156
		$expr[] = $search->compare( '>=', 'customer.address1', '' );
157
		$expr[] = $search->compare( '>=', 'customer.address2', '' );
158
		$expr[] = $search->compare( '>=', 'customer.address3', '' );
159
		$expr[] = $search->compare( '>=', 'customer.postal', '' );
160
		$expr[] = $search->compare( '>=', 'customer.city', '' );
161
		$expr[] = $search->compare( '>=', 'customer.state', '' );
162
		$expr[] = $search->compare( '!=', 'customer.languageid', null );
163
		$expr[] = $search->compare( '>=', 'customer.countryid', '' );
164
		$expr[] = $search->compare( '>=', 'customer.telephone', '' );
165
		$expr[] = $search->compare( '>=', 'customer.email', '' );
166
		$expr[] = $search->compare( '>=', 'customer.telefax', '' );
167
		$expr[] = $search->compare( '>=', 'customer.website', '' );
168
		$expr[] = $search->compare( '>=', 'customer.longitude', '10.0' );
169
		$expr[] = $search->compare( '>=', 'customer.latitude', '50.0' );
170
171
		$expr[] = $search->compare( '==', 'customer.birthday', '1970-01-01' );
172
		$expr[] = $search->compare( '>=', 'customer.password', '' );
173
		$expr[] = $search->compare( '==', 'customer.status', 0 );
174
		$expr[] = $search->compare( '!=', 'customer.mtime', '1970-01-01 00:00:00' );
175
		$expr[] = $search->compare( '!=', 'customer.ctime', '1970-01-01 00:00:00' );
176
		$expr[] = $search->compare( '==', 'customer.editor', $this->editor );
177
178
		$expr[] = $search->compare( '!=', 'customer.address.id', null );
179
		$expr[] = $search->compare( '!=', 'customer.address.parentid', null );
180
		$expr[] = $search->compare( '==', 'customer.address.company', 'ABC GmbH' );
181
		$expr[] = $search->compare( '==', 'customer.address.vatid', 'DE999999999' );
182
		$expr[] = $search->compare( '==', 'customer.address.salutation', 'mr' );
183
		$expr[] = $search->compare( '==', 'customer.address.title', 'Dr.' );
184
		$expr[] = $search->compare( '==', 'customer.address.firstname', 'Good' );
185
		$expr[] = $search->compare( '==', 'customer.address.lastname', 'Unittest' );
186
		$expr[] = $search->compare( '==', 'customer.address.address1', 'Pickhuben' );
187
		$expr[] = $search->compare( '==', 'customer.address.address2', '2-4' );
188
		$expr[] = $search->compare( '==', 'customer.address.address3', '' );
189
		$expr[] = $search->compare( '==', 'customer.address.postal', '11099' );
190
		$expr[] = $search->compare( '==', 'customer.address.city', 'Berlin' );
191
		$expr[] = $search->compare( '==', 'customer.address.state', 'Berlin' );
192
		$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' );
193
		$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' );
194
		$expr[] = $search->compare( '==', 'customer.address.telephone', '055544332221' );
195
		$expr[] = $search->compare( '==', 'customer.address.email', '[email protected]' );
196
		$expr[] = $search->compare( '==', 'customer.address.telefax', '055544333212' );
197
		$expr[] = $search->compare( '==', 'customer.address.website', 'unittest.aimeos.org' );
198
		$expr[] = $search->compare( '>=', 'customer.address.longitude', '10.0' );
199
		$expr[] = $search->compare( '>=', 'customer.address.latitude', '50.0' );
200
		$expr[] = $search->compare( '==', 'customer.address.flag', 0 );
201
		$expr[] = $search->compare( '==', 'customer.address.position', 1 );
202
		$expr[] = $search->compare( '!=', 'customer.address.mtime', '1970-01-01 00:00:00' );
203
		$expr[] = $search->compare( '!=', 'customer.address.ctime', '1970-01-01 00:00:00' );
204
		$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor );
205
206
		$search->setConditions( $search->combine( '&&', $expr ) );
207
		$result = $this->object->searchItems( $search, [], $total );
208
		$this->assertEquals( 1, count( $result ) );
209
	}
210
211
212
	public function testSearchItemsNoCriteria()
213
	{
214
		$total = 0;
215
216
		$search = $this->object->createSearch();
217
		$search->setConditions( $search->compare( '==', 'customer.address.editor', $this->editor ) );
218
		$search->setSlice( 0, 2 );
219
220
		$results = $this->object->searchItems( $search, [], $total );
221
		$this->assertEquals( 2, count( $results ) );
222
		$this->assertEquals( 3, $total );
223
224
		foreach($results as $itemId => $item) {
225
			$this->assertEquals( $itemId, $item->getId() );
226
		}
227
	}
228
229
230 View Code Duplication
	public function testSearchItemsBaseCriteria()
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...
231
	{
232
		$search = $this->object->createSearch( true );
233
		$conditions = array(
234
			$search->compare( '==', 'customer.address.editor', $this->editor ),
235
			$search->getConditions()
236
		);
237
		$search->setConditions( $search->combine( '&&', $conditions ) );
238
		$this->assertEquals( 2, count( $this->object->searchItems( $search, [], $total ) ) );
239
	}
240
241
242
	public function testSearchItemsRef()
243
	{
244
		$search = $this->object->createSearch();
245
		$search->setConditions( $search->compare( '==', 'customer.code', 'unitCustomer1' ) );
246
247
		$results = $this->object->searchItems( $search, ['customer/address', 'text'] );
248
249
		if( ( $item = reset( $results ) ) === false ) {
250
			throw new \Exception( 'No customer item for "unitCustomer1" available' );
251
		}
252
253
		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) );
254
		$this->assertEquals( 1, count( $item->getAddressItems() ) );
255
	}
256
257
258 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...
259
	{
260
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address' ) );
261
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address', 'Standard' ) );
262
263
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
264
		$this->object->getSubManager( 'unknown' );
265
	}
266
267
268
	public function testGetSubManagerInvalidName()
269
	{
270
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
271
		$this->object->getSubManager( 'address', 'unknown' );
272
	}
273
}
274