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::createManager( \TestHelper::getContext(), 'Typo3' ); |
25
|
|
|
$this->object = $manager->getSubManager( 'lists', 'Typo3' ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
protected function tearDown() |
30
|
|
|
{ |
31
|
|
|
unset( $this->object ); |
32
|
|
|
\Aimeos\MShop\Factory::clear(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function testAggregate() |
37
|
|
|
{ |
38
|
|
|
$search = $this->object->createSearch( true ); |
39
|
|
|
$result = $this->object->aggregate( $search, 'customer.lists.domain' ); |
40
|
|
|
|
41
|
|
|
$this->assertEquals( 1, count( $result ) ); |
42
|
|
|
$this->assertArrayHasKey( 'text', $result ); |
43
|
|
|
$this->assertEquals( 4, $result['text'] ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
public function testCreateItem() |
48
|
|
|
{ |
49
|
|
|
$item = $this->object->createItem(); |
50
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Lists\\Iface', $item ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testGetItem() |
55
|
|
|
{ |
56
|
|
|
$search = $this->object->createSearch(); |
57
|
|
|
$search->setSlice(0, 1); |
58
|
|
|
$results = $this->object->searchItems( $search ); |
59
|
|
|
|
60
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
61
|
|
|
throw new \RuntimeException( 'No item found' ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$this->assertEquals( $item, $this->object->getItem( $item->getId() ) ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testSaveUpdateDeleteItem() |
69
|
|
|
{ |
70
|
|
|
$search = $this->object->createSearch(); |
71
|
|
|
$search->setSlice(0, 1); |
72
|
|
|
$items = $this->object->searchItems( $search ); |
73
|
|
|
|
74
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
75
|
|
|
throw new \RuntimeException( 'No item found' ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$item->setId(null); |
79
|
|
|
$item->setDomain( 'unittest' ); |
80
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
81
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
82
|
|
|
|
83
|
|
|
$itemExp = clone $itemSaved; |
84
|
|
|
$itemExp->setDomain( 'unittest2' ); |
85
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
86
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
87
|
|
|
|
88
|
|
|
$this->object->deleteItem( $itemSaved->getId() ); |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
$this->assertTrue( $item->getId() !== null ); |
92
|
|
|
$this->assertTrue( $itemSaved->getType() !== null ); |
93
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
94
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
95
|
|
|
$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
96
|
|
|
$this->assertEquals( $item->getTypeId(), $itemSaved->getTypeId() ); |
97
|
|
|
$this->assertEquals( $item->getRefId(), $itemSaved->getRefId() ); |
98
|
|
|
$this->assertEquals( $item->getDomain(), $itemSaved->getDomain() ); |
99
|
|
|
$this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() ); |
100
|
|
|
$this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() ); |
101
|
|
|
$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
102
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
103
|
|
|
$this->assertStringStartsWith(date('Y-m-d', time()), $itemSaved->getTimeCreated()); |
104
|
|
|
$this->assertStringStartsWith(date('Y-m-d', time()), $itemSaved->getTimeModified()); |
105
|
|
|
|
106
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
107
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
108
|
|
|
$this->assertRegExp('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
109
|
|
|
|
110
|
|
|
$this->assertTrue( $itemUpd->getType() !== null ); |
111
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
112
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
113
|
|
|
$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
114
|
|
|
$this->assertEquals( $itemExp->getTypeId(), $itemUpd->getTypeId() ); |
115
|
|
|
$this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() ); |
116
|
|
|
$this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() ); |
117
|
|
|
$this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() ); |
118
|
|
|
$this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() ); |
119
|
|
|
$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
120
|
|
|
|
121
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
122
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
123
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
124
|
|
|
|
125
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved ); |
126
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd ); |
127
|
|
|
|
128
|
|
|
$this->setExpectedException('\\Aimeos\\MShop\\Exception'); |
129
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
public function testSaveItemException() |
134
|
|
|
{ |
135
|
|
|
$this->setExpectedException( '\Aimeos\MW\Common\Exception' ); |
136
|
|
|
$this->object->saveItem( new \Aimeos\MShop\Common\Item\Type\Standard( 'common.lists.type.' ) ); |
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.typeid', 0 ); |
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', '2100-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
|
|
|
$expr[] = $search->compare( '!=', 'customer.lists.type.id', 0 ); |
245
|
|
|
$expr[] = $search->compare( '!=', 'customer.lists.type.siteid', null ); |
246
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.type.code', 'default' ); |
247
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.type.domain', 'text' ); |
248
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.type.label', 'Standard' ); |
249
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.type.status', 1 ); |
250
|
|
|
$expr[] = $search->compare( '>=', 'customer.lists.type.mtime', '1970-01-01 00:00:00' ); |
251
|
|
|
$expr[] = $search->compare( '>=', 'customer.lists.type.ctime', '1970-01-01 00:00:00' ); |
252
|
|
|
$expr[] = $search->compare( '==', 'customer.lists.type.editor', $this->editor ); |
253
|
|
|
|
254
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
255
|
|
|
$search->setSlice(0, 1); |
256
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
257
|
|
|
$this->assertEquals( 1, count( $results ) ); |
258
|
|
|
$this->assertEquals( 2, $total ); |
259
|
|
|
|
260
|
|
|
foreach($results as $itemId => $item) { |
261
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
|
266
|
|
|
public function testSearchItemsNoCriteria() |
267
|
|
|
{ |
268
|
|
|
$search = $this->object->createSearch(); |
269
|
|
|
$search->setConditions( $search->compare( '==', 'customer.lists.editor', $this->editor ) ); |
270
|
|
|
$this->assertEquals( 4, count( $this->object->searchItems($search) ) ); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
|
274
|
|
|
public function testSearchItemsBaseCriteria() |
275
|
|
|
{ |
276
|
|
|
$search = $this->object->createSearch(true); |
277
|
|
|
$conditions = array( |
278
|
|
|
$search->compare( '==', 'customer.lists.editor', $this->editor ), |
279
|
|
|
$search->getConditions() |
280
|
|
|
); |
281
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
282
|
|
|
$this->assertEquals( 4, count( $this->object->searchItems($search) ) ); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
|
286
|
|
|
public function testGetSubManager() |
287
|
|
|
{ |
288
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type') ); |
289
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager('type', 'Typo3') ); |
290
|
|
|
|
291
|
|
|
$this->setExpectedException('\\Aimeos\\MShop\\Exception'); |
292
|
|
|
$this->object->getSubManager('unknown'); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
|
296
|
|
|
protected function getListItems() |
297
|
|
|
{ |
298
|
|
|
$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager( $this->context, 'Typo3' ); |
299
|
|
|
|
300
|
|
|
$search = $manager->createSearch(); |
301
|
|
|
$search->setConditions( $search->compare( '==', 'customer.code', 'UTC003' ) ); |
302
|
|
|
$search->setSlice( 0, 1 ); |
303
|
|
|
|
304
|
|
|
$results = $manager->searchItems( $search ); |
305
|
|
|
|
306
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
307
|
|
|
throw new \RuntimeException( 'No customer item found' ); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
$search = $this->object->createSearch(); |
311
|
|
|
$expr = array( |
312
|
|
|
$search->compare( '==', 'customer.lists.parentid', $item->getId() ), |
313
|
|
|
$search->compare( '==', 'customer.lists.domain', 'text' ), |
314
|
|
|
$search->compare( '==', 'customer.lists.editor', $this->editor ), |
315
|
|
|
$search->compare( '==', 'customer.lists.type.code', 'default' ), |
316
|
|
|
); |
317
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
318
|
|
|
$search->setSortations( array( $search->sort( '+', 'customer.lists.position' ) ) ); |
319
|
|
|
|
320
|
|
|
return $this->object->searchItems( $search ); |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
|