Completed
Push — master ( ac66b3...ab3b6f )
by Aimeos
07:35 queued 01:23
created

EzpublishTest::testMoveItemFirstToLast()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 27
Code Lines 15

Duplication

Lines 27
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 27
loc 27
rs 8.5806
cc 4
eloc 15
nc 4
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 */
7
8
9
namespace Aimeos\MShop\Customer\Manager\Lists;
10
11
12
class EzpublishTest extends \PHPUnit_Framework_TestCase
13
{
14
	private $object;
15
	private $context;
16
	private $editor = '';
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelper::getContext();
22
		$this->editor = $this->context->getEditor();
23
		$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $this->context, 'Ezpublish' );
24
		$this->object = $manager->getSubManager( 'lists', 'Ezpublish' );
25
	}
26
27
28
	protected function tearDown()
29
	{
30
		unset( $this->object, $this->context );
31
	}
32
33
34
	public function testCleanup()
35
	{
36
		$this->object->cleanup( array( -1 ) );
37
	}
38
39
40
	public function testAggregate()
41
	{
42
		$search = $this->object->createSearch( true );
43
		$expr = array(
44
			$search->getConditions(),
45
			$search->compare( '==', 'customer.lists.editor', 'ai-ezpublish:unittest' ),
46
		);
47
		$search->setConditions( $search->combine( '&&', $expr ) );
48
49
		$result = $this->object->aggregate( $search, 'customer.lists.domain' );
50
51
		$this->assertEquals( 1, count( $result ) );
52
		$this->assertArrayHasKey( 'text', $result );
53
		$this->assertEquals( 4, $result['text'] );
54
	}
55
56
57
	public function testCreateItem()
58
	{
59
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $this->object->createItem() );
60
	}
61
62
63 View Code Duplication
	public function testGetItem()
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...
64
	{
65
		$search = $this->object->createSearch();
66
		$search->setSlice(0, 1);
67
		$results = $this->object->searchItems( $search );
68
69
		if( ( $item = reset( $results ) ) === false ) {
70
			throw new \Exception( 'No item found' );
71
		}
72
73
		$this->assertEquals( $item, $this->object->getItem( $item->getId() ) );
74
	}
75
76
77
	public function testSaveUpdateDeleteItem()
78
	{
79
		$search = $this->object->createSearch();
80
		$search->setSlice(0, 1);
81
		$items = $this->object->searchItems( $search );
82
83
		if( ( $item = reset( $items ) ) === false ) {
84
			throw new \Exception( 'No item found' );
85
		}
86
87
		$item->setId( null );
88
		$item->setDomain( 'unittest' );
89
		$this->object->saveItem( $item );
90
		$itemSaved = $this->object->getItem( $item->getId() );
91
92
		$itemExp = clone $itemSaved;
93
		$itemExp->setDomain( 'unittest2' );
94
		$this->object->saveItem( $itemExp );
95
		$itemUpd = $this->object->getItem( $itemExp->getId() );
96
97
		$this->object->deleteItem( $itemSaved->getId() );
98
99
100
		$this->assertTrue( $item->getId() !== null );
101
		$this->assertTrue( $itemSaved->getType() !== null );
102
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
103
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
104
		$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() );
105
		$this->assertEquals( $item->getTypeId(), $itemSaved->getTypeId() );
106
		$this->assertEquals( $item->getRefId(), $itemSaved->getRefId() );
107
		$this->assertEquals( $item->getDomain(), $itemSaved->getDomain() );
108
		$this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() );
109
		$this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() );
110
		$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() );
111
		$this->assertEquals( $this->editor, $itemSaved->getEditor() );
112
		$this->assertStringStartsWith(date('Y-m-d', time()), $itemSaved->getTimeCreated());
113
		$this->assertStringStartsWith(date('Y-m-d', time()), $itemSaved->getTimeModified());
114
115
		$this->assertEquals( $this->editor, $itemSaved->getEditor() );
116
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
117
		$this->assertRegExp('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
118
119
		$this->assertTrue( $itemUpd->getType() !== null );
120
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
121
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
122
		$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() );
123
		$this->assertEquals( $itemExp->getTypeId(), $itemUpd->getTypeId() );
124
		$this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() );
125
		$this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() );
126
		$this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() );
127
		$this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() );
128
		$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() );
129
130
		$this->assertEquals( $this->editor, $itemUpd->getEditor() );
131
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
132
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
133
134
		$this->setExpectedException('\\Aimeos\\MShop\\Exception');
135
		$this->object->getItem( $itemSaved->getId() );
136
	}
137
138
139
	public function testMoveItemLastToFront()
140
	{
141
		$listItems = $this->getListItems();
142
		$this->assertGreaterThan( 1, count( $listItems ) );
143
144
		if( ( $first = reset( $listItems ) ) === false ) {
145
			throw new \Exception( 'No first customer list item' );
146
		}
147
148
		if( ( $last = end( $listItems ) ) === false ) {
149
			throw new \Exception( 'No last customer list item' );
150
		}
151
152
		$this->object->moveItem( $last->getId(), $first->getId() );
153
154
		$newFirst = $this->object->getItem( $last->getId() );
155
		$newSecond = $this->object->getItem( $first->getId() );
156
157
		$this->object->moveItem( $last->getId() );
158
159
		$this->assertEquals( 0, $newFirst->getPosition() );
160
		$this->assertEquals( 1, $newSecond->getPosition() );
161
	}
162
163
164 View Code Duplication
	public function testMoveItemFirstToLast()
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...
165
	{
166
		$listItems = $this->getListItems();
167
		$this->assertGreaterThan( 1, count( $listItems ) );
168
169
		if( ( $first = reset( $listItems ) ) === false ) {
170
			throw new \Exception( 'No first customer list item' );
171
		}
172
173
		if( ( $second = next( $listItems ) ) === false ) {
174
			throw new \Exception( 'No second customer list item' );
175
		}
176
177
		if( ( $last = end( $listItems ) ) === false ) {
178
			throw new \Exception( 'No last customer list item' );
179
		}
180
181
		$this->object->moveItem( $first->getId() );
182
183
		$newBefore = $this->object->getItem( $last->getId() );
184
		$newLast = $this->object->getItem( $first->getId() );
185
186
		$this->object->moveItem( $first->getId(), $second->getId() );
187
188
		$this->assertEquals( $last->getPosition() - 1, $newBefore->getPosition() );
189
		$this->assertEquals( $last->getPosition(), $newLast->getPosition() );
190
	}
191
192
193 View Code Duplication
	public function testMoveItemFirstUp()
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...
194
	{
195
		$listItems = $this->getListItems();
196
		$this->assertGreaterThan( 1, count( $listItems ) );
197
198
		if( ( $first = reset( $listItems ) ) === false ) {
199
			throw new \Exception( 'No first customer list item' );
200
		}
201
202
		if( ( $second = next( $listItems ) ) === false ) {
203
			throw new \Exception( 'No second customer list item' );
204
		}
205
206
		if( ( $last = end( $listItems ) ) === false ) {
207
			throw new \Exception( 'No last customer list item' );
208
		}
209
210
		$this->object->moveItem( $first->getId(), $last->getId() );
211
212
		$newLast = $this->object->getItem( $last->getId() );
213
		$newUp = $this->object->getItem( $first->getId() );
214
215
		$this->object->moveItem( $first->getId(), $second->getId() );
216
217
		$this->assertEquals( $last->getPosition() - 1, $newUp->getPosition() );
218
		$this->assertEquals( $last->getPosition(), $newLast->getPosition() );
219
	}
220
221
222
	public function testSearchItems()
223
	{
224
		$total = 0;
225
		$search = $this->object->createSearch();
226
227
		$expr = array();
228
		$expr[] = $search->compare( '!=', 'customer.lists.id', null );
229
		$expr[] = $search->compare( '!=', 'customer.lists.siteid', null );
230
		$expr[] = $search->compare( '!=', 'customer.lists.parentid', null );
231
		$expr[] = $search->compare( '==', 'customer.lists.domain', 'text' );
232
		$expr[] = $search->compare( '>', 'customer.lists.typeid', 0 );
233
		$expr[] = $search->compare( '>', 'customer.lists.refid', 0 );
234
		$expr[] = $search->compare( '==', 'customer.lists.datestart', '2010-01-01 00:00:00' );
235
		$expr[] = $search->compare( '==', 'customer.lists.dateend', '2100-01-01 00:00:00' );
236
		$expr[] = $search->compare( '!=', 'customer.lists.config', null );
237
		$expr[] = $search->compare( '>', 'customer.lists.position', 0 );
238
		$expr[] = $search->compare( '==', 'customer.lists.status', 1 );
239
		$expr[] = $search->compare( '>=', 'customer.lists.mtime', '1970-01-01 00:00:00' );
240
		$expr[] = $search->compare( '>=', 'customer.lists.ctime', '1970-01-01 00:00:00' );
241
		$expr[] = $search->compare( '==', 'customer.lists.editor', $this->editor );
242
243
		$expr[] = $search->compare( '!=', 'customer.lists.type.id', 0 );
244
		$expr[] = $search->compare( '!=', 'customer.lists.type.siteid', null );
245
		$expr[] = $search->compare( '==', 'customer.lists.type.code', 'default' );
246
		$expr[] = $search->compare( '==', 'customer.lists.type.domain', 'text' );
247
		$expr[] = $search->compare( '==', 'customer.lists.type.label', 'Standard' );
248
		$expr[] = $search->compare( '==', 'customer.lists.type.status', 1 );
249
		$expr[] = $search->compare( '>=', 'customer.lists.type.mtime', '1970-01-01 00:00:00' );
250
		$expr[] = $search->compare( '>=', 'customer.lists.type.ctime', '1970-01-01 00:00:00' );
251
		$expr[] = $search->compare( '==', 'customer.lists.type.editor', $this->editor );
252
253
		$search->setConditions( $search->combine( '&&', $expr ) );
254
		$search->setSlice(0, 2);
255
		$results = $this->object->searchItems( $search, array(), $total );
256
		$this->assertEquals( 2, count( $results ) );
257
		$this->assertEquals( 3, $total );
258
259
		foreach($results as $itemId => $item) {
260
			$this->assertEquals( $itemId, $item->getId() );
261
		}
262
	}
263
264
265
	public function testSearchItemsNoCriteria()
266
	{
267
		$search = $this->object->createSearch();
268
		$search->setConditions( $search->compare( '==', 'customer.lists.editor', $this->editor ) );
269
		$this->assertEquals( 4, count( $this->object->searchItems($search) ) );
270
	}
271
272
273 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...
274
	{
275
		$search = $this->object->createSearch(true);
276
		$conditions = array(
277
			$search->compare( '==', 'customer.lists.editor', $this->editor ),
278
			$search->getConditions()
279
		);
280
		$search->setConditions( $search->combine( '&&', $conditions ) );
281
		$this->assertEquals( 4, count( $this->object->searchItems($search) ) );
282
	}
283
284
285 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...
286
	{
287
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type') );
288
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type', 'Standard') );
289
290
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
291
		$this->object->getSubManager( 'unknown' );
292
	}
293
294
295
	protected function getListItems()
296
	{
297
		$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $this->context, 'Ezpublish' );
298
299
		$search = $manager->createSearch();
300
		$search->setConditions( $search->compare( '==', 'customer.code', 'UTC003' ) );
301
		$search->setSlice( 0, 1 );
302
303
		$results = $manager->searchItems( $search );
304
305
		if( ( $item = reset( $results ) ) === false ) {
306
			throw new \Exception( 'No customer item found' );
307
		}
308
309
		$search = $this->object->createSearch();
310
		$expr = array(
311
			$search->compare( '==', 'customer.lists.parentid', $item->getId() ),
312
			$search->compare( '==', 'customer.lists.domain', 'text' ),
313
			$search->compare( '==', 'customer.lists.editor', $this->editor ),
314
			$search->compare( '==', 'customer.lists.type.code', 'default' ),
315
		);
316
		$search->setConditions( $search->combine( '&&', $expr ) );
317
		$search->setSortations( array( $search->sort( '+', 'customer.lists.position' ) ) );
318
319
		return $this->object->searchItems( $search );
320
	}
321
}
322