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