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