Completed
Push — master ( 58b639...6e0030 )
by Aimeos
11:05
created

LaravelTest::testSearchItemsNoCriteria()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 2
eloc 10
nc 2
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
	public function testCreateSearch()
137
	{
138
		$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() );
139
	}
140
141
142
	public function testSearchItems()
143
	{
144
		$total = 0;
145
		$search = $this->object->createSearch();
146
147
		$expr = [];
148
		$expr[] = $search->compare( '!=', 'customer.id', null );
149
		$expr[] = $search->compare( '==', 'customer.label', 'unitCustomer2' );
150
		$expr[] = $search->compare( '==', 'customer.code', 'UTC002' );
151
152
		$expr[] = $search->compare( '>=', 'customer.salutation', '' );
153
		$expr[] = $search->compare( '>=', 'customer.company', '' );
154
		$expr[] = $search->compare( '>=', 'customer.vatid', '' );
155
		$expr[] = $search->compare( '>=', 'customer.title', '' );
156
		$expr[] = $search->compare( '>=', 'customer.firstname', '' );
157
		$expr[] = $search->compare( '>=', 'customer.lastname', '' );
158
		$expr[] = $search->compare( '>=', 'customer.address1', '' );
159
		$expr[] = $search->compare( '>=', 'customer.address2', '' );
160
		$expr[] = $search->compare( '>=', 'customer.address3', '' );
161
		$expr[] = $search->compare( '>=', 'customer.postal', '' );
162
		$expr[] = $search->compare( '>=', 'customer.city', '' );
163
		$expr[] = $search->compare( '>=', 'customer.state', '' );
164
		$expr[] = $search->compare( '!=', 'customer.languageid', null );
165
		$expr[] = $search->compare( '>=', 'customer.countryid', '' );
166
		$expr[] = $search->compare( '>=', 'customer.telephone', '' );
167
		$expr[] = $search->compare( '>=', 'customer.email', '' );
168
		$expr[] = $search->compare( '>=', 'customer.telefax', '' );
169
		$expr[] = $search->compare( '>=', 'customer.website', '' );
170
		$expr[] = $search->compare( '>=', 'customer.longitude', '10.0' );
171
		$expr[] = $search->compare( '>=', 'customer.latitude', '50.0' );
172
173
		$expr[] = $search->compare( '==', 'customer.birthday', '1970-01-01' );
174
		$expr[] = $search->compare( '>=', 'customer.password', '' );
175
		$expr[] = $search->compare( '==', 'customer.status', 0 );
176
		$expr[] = $search->compare( '!=', 'customer.mtime', '1970-01-01 00:00:00' );
177
		$expr[] = $search->compare( '!=', 'customer.ctime', '1970-01-01 00:00:00' );
178
		$expr[] = $search->compare( '==', 'customer.editor', $this->editor );
179
180
		$expr[] = $search->compare( '!=', 'customer.address.id', null );
181
		$expr[] = $search->compare( '!=', 'customer.address.parentid', null );
182
		$expr[] = $search->compare( '==', 'customer.address.company', 'ABC GmbH' );
183
		$expr[] = $search->compare( '==', 'customer.address.vatid', 'DE999999999' );
184
		$expr[] = $search->compare( '==', 'customer.address.salutation', 'mr' );
185
		$expr[] = $search->compare( '==', 'customer.address.title', 'Dr.' );
186
		$expr[] = $search->compare( '==', 'customer.address.firstname', 'Good' );
187
		$expr[] = $search->compare( '==', 'customer.address.lastname', 'Unittest' );
188
		$expr[] = $search->compare( '==', 'customer.address.address1', 'Pickhuben' );
189
		$expr[] = $search->compare( '==', 'customer.address.address2', '2-4' );
190
		$expr[] = $search->compare( '==', 'customer.address.address3', '' );
191
		$expr[] = $search->compare( '==', 'customer.address.postal', '11099' );
192
		$expr[] = $search->compare( '==', 'customer.address.city', 'Berlin' );
193
		$expr[] = $search->compare( '==', 'customer.address.state', 'Berlin' );
194
		$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' );
195
		$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' );
196
		$expr[] = $search->compare( '==', 'customer.address.telephone', '055544332221' );
197
		$expr[] = $search->compare( '==', 'customer.address.email', '[email protected]' );
198
		$expr[] = $search->compare( '==', 'customer.address.telefax', '055544333212' );
199
		$expr[] = $search->compare( '==', 'customer.address.website', 'unittest.aimeos.org' );
200
		$expr[] = $search->compare( '>=', 'customer.address.longitude', '10.0' );
201
		$expr[] = $search->compare( '>=', 'customer.address.latitude', '50.0' );
202
		$expr[] = $search->compare( '==', 'customer.address.flag', 0 );
203
		$expr[] = $search->compare( '==', 'customer.address.position', 1 );
204
		$expr[] = $search->compare( '!=', 'customer.address.mtime', '1970-01-01 00:00:00' );
205
		$expr[] = $search->compare( '!=', 'customer.address.ctime', '1970-01-01 00:00:00' );
206
		$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor );
207
208
		$search->setConditions( $search->combine( '&&', $expr ) );
209
		$result = $this->object->searchItems( $search, [], $total );
210
		$this->assertEquals( 1, count( $result ) );
211
	}
212
213
214
	public function testSearchItemsTotal()
215
	{
216
		$total = 0;
217
218
		$search = $this->object->createSearch();
219
		$search->setConditions( $search->compare( '==', 'customer.address.editor', $this->editor ) );
220
		$search->setSlice( 0, 2 );
221
222
		$results = $this->object->searchItems( $search, [], $total );
223
		$this->assertEquals( 2, count( $results ) );
224
		$this->assertEquals( 3, $total );
225
226
		foreach($results as $itemId => $item) {
227
			$this->assertEquals( $itemId, $item->getId() );
228
		}
229
	}
230
231
232 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...
233
	{
234
		$search = $this->object->createSearch( true );
235
		$conditions = array(
236
			$search->compare( '==', 'customer.address.editor', $this->editor ),
237
			$search->getConditions()
238
		);
239
		$search->setConditions( $search->combine( '&&', $conditions ) );
240
		$this->assertEquals( 2, count( $this->object->searchItems( $search, [], $total ) ) );
241
	}
242
243
244
	public function testSearchItemsRef()
245
	{
246
		$search = $this->object->createSearch();
247
		$search->setConditions( $search->compare( '==', 'customer.code', 'UTC001' ) );
248
249
		$results = $this->object->searchItems( $search, ['customer/address', 'text'] );
250
251
		if( ( $item = reset( $results ) ) === false ) {
252
			throw new \Exception( 'No customer item for "UTC001" available' );
253
		}
254
255
		$this->assertEquals( 1, count( $item->getRefItems( 'text' ) ) );
256
		$this->assertEquals( 1, count( $item->getAddressItems() ) );
257
	}
258
259
260 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...
261
	{
262
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address' ) );
263
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'address', 'Standard' ) );
264
265
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
266
		$this->object->getSubManager( 'unknown' );
267
	}
268
269
270
	public function testGetSubManagerInvalidName()
271
	{
272
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
273
		$this->object->getSubManager( 'address', 'unknown' );
274
	}
275
}
276