1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Customer\Manager\Lists; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class LaravelTest extends \PHPUnit\Framework\TestCase |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
private $editor = 'ai-laravel:unittest'; |
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::create( $this->context, 'Laravel' ); |
24
|
|
|
$this->object = $manager->getSubManager( 'lists', 'Laravel' ); |
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-laravel:unittest' ), |
46
|
|
|
); |
47
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
48
|
|
|
|
49
|
|
|
$result = $this->object->aggregate( $search, 'customer.lists.domain' ); |
50
|
|
|
|
51
|
|
|
$this->assertEquals( 3, 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
|
|
|
public function testGetItem() |
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 \RuntimeException( '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 \RuntimeException( 'No item found' ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$item->setId( null ); |
88
|
|
|
$item->setDomain( 'unittest' ); |
89
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
90
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
91
|
|
|
|
92
|
|
|
$itemExp = clone $itemSaved; |
93
|
|
|
$itemExp->setDomain( 'unittest2' ); |
94
|
|
|
$resultUpd = $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->assertEquals( $item->getId(), $itemSaved->getId() ); |
102
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
103
|
|
|
$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
104
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
105
|
|
|
$this->assertEquals( $item->getRefId(), $itemSaved->getRefId() ); |
106
|
|
|
$this->assertEquals( $item->getDomain(), $itemSaved->getDomain() ); |
107
|
|
|
$this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() ); |
108
|
|
|
$this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() ); |
109
|
|
|
$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
110
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
111
|
|
|
$this->assertStringStartsWith(date('Y-m-d', time()), $itemSaved->getTimeCreated()); |
112
|
|
|
$this->assertStringStartsWith(date('Y-m-d', time()), $itemSaved->getTimeModified()); |
113
|
|
|
|
114
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
115
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
116
|
|
|
$this->assertRegExp('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
117
|
|
|
|
118
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
119
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
120
|
|
|
$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
121
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
122
|
|
|
$this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() ); |
123
|
|
|
$this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() ); |
124
|
|
|
$this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() ); |
125
|
|
|
$this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() ); |
126
|
|
|
$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
127
|
|
|
|
128
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
129
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
130
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
131
|
|
|
|
132
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
133
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
134
|
|
|
|
135
|
|
|
$this->setExpectedException('\\Aimeos\\MShop\\Exception'); |
136
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
public function testMoveItemLastToFront() |
141
|
|
|
{ |
142
|
|
|
$listItems = $this->getListItems(); |
143
|
|
|
$this->assertGreaterThan( 1, count( $listItems ) ); |
144
|
|
|
|
145
|
|
|
if( ( $first = reset( $listItems ) ) === false ) { |
146
|
|
|
throw new \RuntimeException( 'No first customer list item' ); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
if( ( $last = end( $listItems ) ) === false ) { |
150
|
|
|
throw new \RuntimeException( 'No last customer list item' ); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
$this->object->moveItem( $last->getId(), $first->getId() ); |
154
|
|
|
|
155
|
|
|
$newFirst = $this->object->getItem( $last->getId() ); |
156
|
|
|
$newSecond = $this->object->getItem( $first->getId() ); |
157
|
|
|
|
158
|
|
|
$this->object->moveItem( $last->getId() ); |
159
|
|
|
|
160
|
|
|
$this->assertEquals( 1, $newFirst->getPosition() ); |
161
|
|
|
$this->assertEquals( 2, $newSecond->getPosition() ); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
public function testMoveItemFirstToLast() |
166
|
|
|
{ |
167
|
|
|
$listItems = $this->getListItems(); |
168
|
|
|
$this->assertGreaterThan( 1, count( $listItems ) ); |
169
|
|
|
|
170
|
|
|
if( ( $first = reset( $listItems ) ) === false ) { |
171
|
|
|
throw new \RuntimeException( 'No first customer list item' ); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
if( ( $second = next( $listItems ) ) === false ) { |
175
|
|
|
throw new \RuntimeException( 'No second customer list item' ); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
if( ( $last = end( $listItems ) ) === false ) { |
179
|
|
|
throw new \RuntimeException( 'No last customer list item' ); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$this->object->moveItem( $first->getId() ); |
183
|
|
|
|
184
|
|
|
$newBefore = $this->object->getItem( $last->getId() ); |
185
|
|
|
$newLast = $this->object->getItem( $first->getId() ); |
186
|
|
|
|
187
|
|
|
$this->object->moveItem( $first->getId(), $second->getId() ); |
188
|
|
|
|
189
|
|
|
$this->assertEquals( $last->getPosition() - 1, $newBefore->getPosition() ); |
190
|
|
|
$this->assertEquals( $last->getPosition(), $newLast->getPosition() ); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
public function testMoveItemFirstUp() |
195
|
|
|
{ |
196
|
|
|
$listItems = $this->getListItems(); |
197
|
|
|
$this->assertGreaterThan( 1, count( $listItems ) ); |
198
|
|
|
|
199
|
|
|
if( ( $first = reset( $listItems ) ) === false ) { |
200
|
|
|
throw new \RuntimeException( 'No first customer list item' ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
if( ( $second = next( $listItems ) ) === false ) { |
204
|
|
|
throw new \RuntimeException( 'No second customer list item' ); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
if( ( $last = end( $listItems ) ) === false ) { |
208
|
|
|
throw new \RuntimeException( 'No last customer list item' ); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
$this->object->moveItem( $first->getId(), $last->getId() ); |
212
|
|
|
|
213
|
|
|
$newLast = $this->object->getItem( $last->getId() ); |
214
|
|
|
$newUp = $this->object->getItem( $first->getId() ); |
215
|
|
|
|
216
|
|
|
$this->object->moveItem( $first->getId(), $second->getId() ); |
217
|
|
|
|
218
|
|
|
$this->assertEquals( $last->getPosition() - 1, $newUp->getPosition() ); |
219
|
|
|
$this->assertEquals( $last->getPosition(), $newLast->getPosition() ); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
|
223
|
|
|
public function testSearchItems() |
224
|
|
|
{ |
225
|
|
|
$total = 0; |
226
|
|
|
$search = $this->object->createSearch(); |
227
|
|
|
|
228
|
|
|
$expr = []; |
229
|
|
|
$expr[] = $search->compare( '!=', 'customer.lists.id', null ); |
230
|
|
|
$expr[] = $search->compare( '!=', 'customer.lists.siteid', null ); |
231
|
|
|
$expr[] = $search->compare( '>', 'customer.lists.parentid', 0 ); |
232
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.domain', 'text' ); |
233
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.type', 'default' ); |
234
|
|
|
$expr[] = $search->compare( '>', 'customer.lists.refid', 0 ); |
235
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.datestart', '2010-01-01 00:00:00' ); |
236
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.dateend', '2022-01-01 00:00:00' ); |
237
|
|
|
$expr[] = $search->compare( '!=', 'customer.lists.config', null ); |
238
|
|
|
$expr[] = $search->compare( '>', 'customer.lists.position', 1 ); |
239
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.status', 1 ); |
240
|
|
|
$expr[] = $search->compare( '>=', 'customer.lists.mtime', '1970-01-01 00:00:00' ); |
241
|
|
|
$expr[] = $search->compare( '>=', 'customer.lists.ctime', '1970-01-01 00:00:00' ); |
242
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.editor', $this->editor ); |
243
|
|
|
|
244
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
245
|
|
|
$search->setSlice( 0, 2 ); |
246
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
247
|
|
|
$this->assertEquals( 2, count( $results ) ); |
248
|
|
|
$this->assertEquals( 3, $total ); |
249
|
|
|
|
250
|
|
|
foreach( $results as $itemId => $item ) { |
251
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
252
|
|
|
} |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
public function testSearchItemsAll() |
257
|
|
|
{ |
258
|
|
|
//search without base criteria |
259
|
|
|
$search = $this->object->createSearch(); |
260
|
|
|
$search->setConditions( $search->compare( '==', 'customer.lists.editor', $this->editor ) ); |
261
|
|
|
$result = $this->object->searchItems( $search ); |
262
|
|
|
$this->assertEquals( 6, count( $result ) ); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
|
266
|
|
|
public function testSearchItemsBase() |
267
|
|
|
{ |
268
|
|
|
//search with base criteria |
269
|
|
|
$search = $this->object->createSearch( true ); |
270
|
|
|
$conditions = array( |
271
|
|
|
$search->compare( '==', 'customer.lists.editor', $this->editor ), |
272
|
|
|
$search->getConditions() |
273
|
|
|
); |
274
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
275
|
|
|
$this->assertEquals( 6, count( $this->object->searchItems( $search ) ) ); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
|
279
|
|
|
public function testGetSubManager() |
280
|
|
|
{ |
281
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type') ); |
282
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type', 'Standard') ); |
283
|
|
|
|
284
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
285
|
|
|
$this->object->getSubManager( 'unknown' ); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
|
289
|
|
|
protected function getListItems() |
290
|
|
|
{ |
291
|
|
|
$manager = \Aimeos\MShop\Customer\Manager\Factory::create( $this->context, 'Laravel' ); |
292
|
|
|
|
293
|
|
|
$search = $manager->createSearch(); |
294
|
|
|
$search->setConditions( $search->compare( '==', 'customer.code', 'UTC003' ) ); |
295
|
|
|
$search->setSlice( 0, 1 ); |
296
|
|
|
|
297
|
|
|
$results = $manager->searchItems( $search ); |
298
|
|
|
|
299
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
300
|
|
|
throw new \RuntimeException( 'No customer item found' ); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
$search = $this->object->createSearch(); |
304
|
|
|
$expr = array( |
305
|
|
|
$search->compare( '==', 'customer.lists.parentid', $item->getId() ), |
306
|
|
|
$search->compare( '==', 'customer.lists.domain', 'text' ), |
307
|
|
|
$search->compare( '==', 'customer.lists.editor', $this->editor ), |
308
|
|
|
$search->compare( '==', 'customer.lists.type', 'default' ), |
309
|
|
|
); |
310
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
311
|
|
|
$search->setSortations( array( $search->sort( '+', 'customer.lists.position' ) ) ); |
312
|
|
|
|
313
|
|
|
return $this->object->searchItems( $search ); |
314
|
|
|
} |
315
|
|
|
} |
316
|
|
|
|
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