1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Product\Manager; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $context; |
16
|
|
|
private $object; |
17
|
|
|
private $editor = ''; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->context = \TestHelperMShop::getContext(); |
23
|
|
|
$this->editor = $this->context->getEditor(); |
24
|
|
|
|
25
|
|
|
$this->object = new \Aimeos\MShop\Product\Manager\Standard( $this->context ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function tearDown() |
29
|
|
|
{ |
30
|
|
|
$this->object = null; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public function testCleanup() |
35
|
|
|
{ |
36
|
|
|
$this->object->cleanup( array( -1 ) ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function testCreateItem() |
41
|
|
|
{ |
42
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Product\\Item\\Iface', $this->object->createItem() ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testCreateSearch() |
47
|
|
|
{ |
48
|
|
|
$search = $this->object->createSearch(); |
49
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\SQL', $search ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testGetResourceType() |
54
|
|
|
{ |
55
|
|
|
$result = $this->object->getResourceType(); |
56
|
|
|
|
57
|
|
|
$this->assertContains( 'product', $result ); |
58
|
|
|
$this->assertContains( 'product/type', $result ); |
59
|
|
|
$this->assertContains( 'product/lists', $result ); |
60
|
|
|
$this->assertContains( 'product/lists/type', $result ); |
61
|
|
|
$this->assertContains( 'product/property', $result ); |
62
|
|
|
$this->assertContains( 'product/property/type', $result ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function testGetSearchAttributes() |
67
|
|
|
{ |
68
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
69
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
public function testFindItem() |
75
|
|
|
{ |
76
|
|
|
$item = $this->object->findItem( 'CNC' ); |
77
|
|
|
|
78
|
|
|
$this->assertEquals( 'CNC', $item->getCode() ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testGetItem() |
83
|
|
|
{ |
84
|
|
|
$domains = array( 'text', 'product', 'price', 'media', 'attribute', 'product/property' ); |
85
|
|
|
|
86
|
|
|
$search = $this->object->createSearch(); |
87
|
|
|
$conditions = array( |
88
|
|
|
$search->compare( '==', 'product.code', 'CNC' ), |
89
|
|
|
$search->compare( '==', 'product.editor', $this->editor ) |
90
|
|
|
); |
91
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
92
|
|
|
$products = $this->object->searchItems( $search, $domains ); |
93
|
|
|
|
94
|
|
|
if( ( $product = reset( $products ) ) === false ) { |
95
|
|
|
throw new \RuntimeException( sprintf( 'Found no Productitem with text "%1$s"', 'Cafe Noire Cappuccino' ) ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$this->assertEquals( $product, $this->object->getItem( $product->getId(), $domains ) ); |
99
|
|
|
$this->assertEquals( 6, count( $product->getRefItems( 'text', null, null, false ) ) ); |
100
|
|
|
$this->assertEquals( 4, count( $product->getPropertyItems() ) ); |
101
|
|
|
$this->assertNotEquals( '', $product->getTypeName() ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function testSaveUpdateDeleteItem() |
106
|
|
|
{ |
107
|
|
|
$search = $this->object->createSearch(); |
108
|
|
|
$conditions = array( |
109
|
|
|
$search->compare( '==', 'product.code', 'CNC' ), |
110
|
|
|
$search->compare( '==', 'product.editor', $this->editor ) |
111
|
|
|
); |
112
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
113
|
|
|
$items = $this->object->searchItems( $search ); |
114
|
|
|
|
115
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
116
|
|
|
throw new \RuntimeException( 'No product item found' ); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$item->setId( null ); |
120
|
|
|
$item->setCode( 'CNC unit test' ); |
121
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
122
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
123
|
|
|
|
124
|
|
|
$itemExp = clone $itemSaved; |
125
|
|
|
$itemExp->setCode( 'unit save test' ); |
126
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
127
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
128
|
|
|
|
129
|
|
|
$this->object->deleteItem( $itemSaved->getId() ); |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
$this->assertTrue( $item->getId() !== null ); |
133
|
|
|
$this->assertTrue( $itemSaved->getType() !== null ); |
134
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
135
|
|
|
$this->assertEquals( $item->getSiteid(), $itemSaved->getSiteId() ); |
136
|
|
|
$this->assertEquals( $item->getTypeId(), $itemSaved->getTypeId() ); |
137
|
|
|
$this->assertEquals( $item->getCode(), $itemSaved->getCode() ); |
138
|
|
|
$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() ); |
139
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
140
|
|
|
$this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() ); |
141
|
|
|
$this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() ); |
142
|
|
|
$this->assertEquals( $item->getConfig(), $itemSaved->getConfig() ); |
143
|
|
|
$this->assertEquals( $item->getTarget(), $itemSaved->getTarget() ); |
144
|
|
|
|
145
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
146
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
147
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
148
|
|
|
|
149
|
|
|
$this->assertTrue( $itemUpd->getType() !== null ); |
150
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
151
|
|
|
$this->assertEquals( $itemExp->getSiteid(), $itemUpd->getSiteId() ); |
152
|
|
|
$this->assertEquals( $itemExp->getTypeId(), $itemUpd->getTypeId() ); |
153
|
|
|
$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() ); |
154
|
|
|
$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() ); |
155
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
156
|
|
|
$this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() ); |
157
|
|
|
$this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() ); |
158
|
|
|
$this->assertEquals( $itemExp->getConfig(), $itemUpd->getConfig() ); |
159
|
|
|
$this->assertEquals( $itemExp->getTarget(), $itemUpd->getTarget() ); |
160
|
|
|
|
161
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
162
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
163
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
164
|
|
|
|
165
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved ); |
166
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd ); |
167
|
|
|
|
168
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
169
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function testSaveItemRefItems() |
174
|
|
|
{ |
175
|
|
|
$context = \TestHelperMShop::getContext(); |
176
|
|
|
|
177
|
|
|
$manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $context ); |
178
|
|
|
$typeManager = $manager->getSubManager( 'type' ); |
179
|
|
|
|
180
|
|
|
$item = $manager->createItem(); |
181
|
|
|
$item->setTypeId( $typeManager->findItem( 'default', [], 'product' )->getId() ); |
182
|
|
|
$item->setCode( 'unitreftest' ); |
183
|
|
|
|
184
|
|
|
$listManager = $manager->getSubManager( 'lists' ); |
185
|
|
|
$listTypeManager = $listManager->getSubManager( 'type' ); |
186
|
|
|
|
187
|
|
|
$listItem = $listManager->createItem(); |
188
|
|
|
$listItem->setTypeId( $listTypeManager->findItem( 'default', [], 'product' )->getId() ); |
189
|
|
|
|
190
|
|
|
$textManager = \Aimeos\MShop\Text\Manager\Factory::createManager( $context ); |
191
|
|
|
$textTypeManager = $textManager->getSubManager( 'type' ); |
192
|
|
|
|
193
|
|
|
$textItem = $textManager->createItem(); |
194
|
|
|
$textItem->setTypeId( $textTypeManager->findItem( 'name', [], 'product' )->getId() ); |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
$item->addRefItem( 'text', $listItem, $textItem ); |
198
|
|
|
|
199
|
|
|
$item = $manager->saveItem( $item ); |
|
|
|
|
200
|
|
|
$item2 = $manager->getItem( $item->getId(), ['text'] ); |
|
|
|
|
201
|
|
|
|
202
|
|
|
$item->deleteRefItem( 'text', $listItem, $textItem ); |
|
|
|
|
203
|
|
|
|
204
|
|
|
$item = $manager->saveItem( $item ); |
|
|
|
|
205
|
|
|
$item3 = $manager->getItem( $item->getId(), ['text'] ); |
|
|
|
|
206
|
|
|
|
207
|
|
|
$manager->deleteItem( $item->getId() ); |
|
|
|
|
208
|
|
|
|
209
|
|
|
|
210
|
|
|
$this->assertEquals( 0, count( $item->getRefItems( 'text', 'name', 'default', false ) ) ); |
|
|
|
|
211
|
|
|
$this->assertEquals( 1, count( $item2->getRefItems( 'text', 'name', 'default', false ) ) ); |
212
|
|
|
$this->assertEquals( 0, count( $item3->getRefItems( 'text', 'name', 'default', false ) ) ); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
|
216
|
|
|
public function testSaveItemSitecheck() |
217
|
|
|
{ |
218
|
|
|
$manager = \Aimeos\MShop\Product\Manager\Factory::createManager( \TestHelperMShop::getContext() ); |
219
|
|
|
|
220
|
|
|
$search = $manager->createSearch(); |
221
|
|
|
$search->setConditions( $search->compare( '==', 'product.editor', $this->editor ) ); |
222
|
|
|
$search->setSlice( 0, 1 ); |
223
|
|
|
$products = $manager->searchItems( $search ); |
224
|
|
|
|
225
|
|
|
if( ( $item = reset( $products ) ) === false ) { |
226
|
|
|
throw new \RuntimeException( 'No product found' ); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
$item->setId( null ); |
230
|
|
|
$item->setCode( 'unittest' ); |
231
|
|
|
|
232
|
|
|
$manager->saveItem( $item ); |
233
|
|
|
$manager->getItem( $item->getId() ); |
234
|
|
|
$manager->deleteItem( $item->getId() ); |
235
|
|
|
|
236
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
237
|
|
|
$manager->getItem( $item->getId() ); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
|
241
|
|
|
public function testUpdateListItems() |
242
|
|
|
{ |
243
|
|
|
$attrManager = \Aimeos\MShop\Attribute\Manager\Factory::createManager( $this->context ); |
244
|
|
|
$attrId = $attrManager->findItem( 's', [], 'product', 'size' )->getId(); |
245
|
|
|
$item = $this->object->findItem( 'CNC', array( 'attribute' ) ); |
246
|
|
|
|
247
|
|
|
// create new list item |
248
|
|
|
$map = array( $attrId => array( 'product.lists.datestart' => '2000-01-01 00:00:00' ) ); |
249
|
|
|
$this->object->updateListItems( $item, $map, 'attribute', 'hidden' ); |
|
|
|
|
250
|
|
|
|
251
|
|
|
$item = $this->object->findItem( 'CNC', array( 'attribute' ) ); |
252
|
|
|
$listItems = $item->getListItems( 'attribute', 'hidden', null, false ); |
253
|
|
|
|
254
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
255
|
|
|
$this->assertEquals( '2000-01-01 00:00:00', reset( $listItems )->getDateStart() ); |
256
|
|
|
|
257
|
|
|
|
258
|
|
|
// update existing list item |
259
|
|
|
$map = array( $attrId => array( 'product.lists.config' => array( 'key' => 'value' ) ) ); |
260
|
|
|
$this->object->updateListItems( $item, $map, 'attribute', 'hidden' ); |
|
|
|
|
261
|
|
|
|
262
|
|
|
$item = $this->object->findItem( 'CNC', array( 'attribute' ) ); |
263
|
|
|
$listItems = $item->getListItems( 'attribute', 'hidden' ); |
264
|
|
|
|
265
|
|
|
$this->assertEquals( 1, count( $listItems ) ); |
266
|
|
|
$this->assertEquals( '2000-01-01 00:00:00', reset( $listItems )->getDateStart() ); |
267
|
|
|
$this->assertEquals( array( 'key' => 'value' ), reset( $listItems )->getConfig() ); |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
// delete existing list item |
271
|
|
|
$this->object->updateListItems( $item, [], 'attribute', 'hidden' ); |
|
|
|
|
272
|
|
|
|
273
|
|
|
$item = $this->object->findItem( 'CNC', array( 'attribute' ) ); |
274
|
|
|
$this->assertEquals( 0, count( $item->getListItems( 'attribute', 'hidden' ) ) ); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
|
278
|
|
|
public function testSearchItems() |
279
|
|
|
{ |
280
|
|
|
$total = 0; |
281
|
|
|
$listManager = $this->object->getSubManager( 'lists' ); |
282
|
|
|
|
283
|
|
|
$search = $listManager->createSearch(); |
284
|
|
|
$expr = array( |
285
|
|
|
$search->compare( '==', 'product.lists.type.domain', 'product' ), |
286
|
|
|
$search->compare( '==', 'product.lists.type.code', 'suggestion' ), |
287
|
|
|
$search->compare( '==', 'product.lists.datestart', null ), |
288
|
|
|
$search->compare( '==', 'product.lists.dateend', null ), |
289
|
|
|
$search->compare( '!=', 'product.lists.config', null ), |
290
|
|
|
$search->compare( '==', 'product.lists.position', 0 ), |
291
|
|
|
$search->compare( '==', 'product.lists.status', 1 ), |
292
|
|
|
$search->compare( '==', 'product.lists.editor', $this->editor ), |
293
|
|
|
); |
294
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
295
|
|
|
|
296
|
|
|
$results = $listManager->searchItems( $search ); |
297
|
|
|
if( ( $listItem = reset( $results ) ) === false ) { |
298
|
|
|
throw new \RuntimeException( 'No list item found' ); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
$search = $this->object->createSearch(); |
302
|
|
|
|
303
|
|
|
$expr = []; |
304
|
|
|
$expr[] = $search->compare( '!=', 'product.id', null ); |
305
|
|
|
$expr[] = $search->compare( '!=', 'product.siteid', null ); |
306
|
|
|
$expr[] = $search->compare( '!=', 'product.typeid', null ); |
307
|
|
|
$expr[] = $search->compare( '==', 'product.code', 'CNE' ); |
308
|
|
|
$expr[] = $search->compare( '==', 'product.label', 'Cafe Noire Expresso' ); |
309
|
|
|
$expr[] = $search->compare( '~=', 'product.config', 'css-class' ); |
310
|
|
|
$expr[] = $search->compare( '==', 'product.datestart', null ); |
311
|
|
|
$expr[] = $search->compare( '==', 'product.dateend', null ); |
312
|
|
|
$expr[] = $search->compare( '==', 'product.status', 1 ); |
313
|
|
|
$expr[] = $search->compare( '>=', 'product.ctime', '1970-01-01 00:00:00' ); |
314
|
|
|
$expr[] = $search->compare( '>=', 'product.mtime', '1970-01-01 00:00:00' ); |
315
|
|
|
$expr[] = $search->compare( '==', 'product.editor', $this->editor ); |
316
|
|
|
$expr[] = $search->compare( '>=', 'product.target', '' ); |
317
|
|
|
|
318
|
|
|
$param = array( 'product', $listItem->getTypeId(), array( $listItem->getRefId() ) ); |
319
|
|
|
$expr[] = $search->compare( '>', $search->createFunction( 'product.contains', $param ), 0 ); |
320
|
|
|
|
321
|
|
|
$expr[] = $search->compare( '!=', 'product.type.id', null ); |
322
|
|
|
$expr[] = $search->compare( '!=', 'product.type.siteid', null ); |
323
|
|
|
$expr[] = $search->compare( '==', 'product.type.domain', 'product' ); |
324
|
|
|
$expr[] = $search->compare( '==', 'product.type.code', 'default' ); |
325
|
|
|
$expr[] = $search->compare( '==', 'product.type.label', 'Article' ); |
326
|
|
|
$expr[] = $search->compare( '==', 'product.type.status', 1 ); |
327
|
|
|
$expr[] = $search->compare( '==', 'product.type.editor', $this->editor ); |
328
|
|
|
|
329
|
|
|
$expr[] = $search->compare( '!=', 'product.lists.id', null ); |
330
|
|
|
$expr[] = $search->compare( '!=', 'product.lists.siteid', null ); |
331
|
|
|
$expr[] = $search->compare( '!=', 'product.lists.parentid', null ); |
332
|
|
|
$expr[] = $search->compare( '!=', 'product.lists.typeid', null ); |
333
|
|
|
$expr[] = $search->compare( '==', 'product.lists.domain', 'product' ); |
334
|
|
|
$expr[] = $search->compare( '>', 'product.lists.refid', 0 ); |
335
|
|
|
$expr[] = $search->compare( '==', 'product.lists.datestart', null ); |
336
|
|
|
$expr[] = $search->compare( '==', 'product.lists.dateend', null ); |
337
|
|
|
$expr[] = $search->compare( '!=', 'product.lists.config', null ); |
338
|
|
|
$expr[] = $search->compare( '==', 'product.lists.position', 0 ); |
339
|
|
|
$expr[] = $search->compare( '==', 'product.lists.status', 1 ); |
340
|
|
|
$expr[] = $search->compare( '==', 'product.lists.editor', $this->editor ); |
341
|
|
|
|
342
|
|
|
$expr[] = $search->compare( '!=', 'product.lists.type.id', null ); |
343
|
|
|
$expr[] = $search->compare( '!=', 'product.lists.type.siteid', null ); |
344
|
|
|
$expr[] = $search->compare( '==', 'product.lists.type.domain', 'product' ); |
345
|
|
|
$expr[] = $search->compare( '==', 'product.lists.type.code', 'suggestion' ); |
346
|
|
|
$expr[] = $search->compare( '==', 'product.lists.type.label', 'Suggestion' ); |
347
|
|
|
$expr[] = $search->compare( '==', 'product.lists.type.status', 1 ); |
348
|
|
|
$expr[] = $search->compare( '==', 'product.lists.type.editor', $this->editor ); |
349
|
|
|
|
350
|
|
|
$expr[] = $search->compare( '!=', 'product.property.id', null ); |
351
|
|
|
$expr[] = $search->compare( '!=', 'product.property.siteid', null ); |
352
|
|
|
$expr[] = $search->compare( '!=', 'product.property.typeid', null ); |
353
|
|
|
$expr[] = $search->compare( '==', 'product.property.languageid', null ); |
354
|
|
|
$expr[] = $search->compare( '==', 'product.property.value', '1' ); |
355
|
|
|
$expr[] = $search->compare( '==', 'product.property.editor', $this->editor ); |
356
|
|
|
|
357
|
|
|
$expr[] = $search->compare( '!=', 'product.property.type.id', null ); |
358
|
|
|
$expr[] = $search->compare( '!=', 'product.property.type.siteid', null ); |
359
|
|
|
$expr[] = $search->compare( '==', 'product.property.type.code', 'package-weight' ); |
360
|
|
|
$expr[] = $search->compare( '==', 'product.property.type.domain', 'product' ); |
361
|
|
|
$expr[] = $search->compare( '==', 'product.property.type.label', 'Package Weight' ); |
362
|
|
|
$expr[] = $search->compare( '==', 'product.property.type.status', 1 ); |
363
|
|
|
$expr[] = $search->compare( '>=', 'product.property.type.mtime', '1970-01-01 00:00:00' ); |
364
|
|
|
$expr[] = $search->compare( '>=', 'product.property.type.ctime', '1970-01-01 00:00:00' ); |
365
|
|
|
$expr[] = $search->compare( '==', 'product.property.type.editor', $this->editor ); |
366
|
|
|
|
367
|
|
|
|
368
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
369
|
|
|
$search->setSlice( 0, 1 ); |
370
|
|
|
|
371
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
372
|
|
|
$this->assertEquals( 1, count( $results ) ); |
373
|
|
|
$this->assertEquals( 1, $total ); |
374
|
|
|
|
375
|
|
|
foreach( $results as $itemId => $item ) { |
376
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
$search = $this->object->createSearch(); |
380
|
|
|
$search->setConditions( $search->compare( '==', 'product.editor', $this->editor ) ); |
381
|
|
|
$search->setSlice( 0, 10 ); |
382
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
383
|
|
|
$this->assertEquals( 10, count( $results ) ); |
384
|
|
|
$this->assertEquals( 28, $total ); |
385
|
|
|
|
386
|
|
|
|
387
|
|
|
$search = $this->object->createSearch( true ); |
388
|
|
|
$expr = array( |
389
|
|
|
$search->compare( '==', 'product.code', array( 'CNC', 'CNE' ) ), |
390
|
|
|
$search->compare( '==', 'product.editor', $this->editor ), |
391
|
|
|
$search->getConditions(), |
392
|
|
|
); |
393
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
394
|
|
|
$result = $this->object->searchItems( $search, array( 'media' ) ); |
395
|
|
|
|
396
|
|
|
$this->assertEquals( 2, count( $result ) ); |
397
|
|
|
} |
398
|
|
|
|
399
|
|
|
|
400
|
|
|
public function testSearchWildcards() |
401
|
|
|
{ |
402
|
|
|
$search = $this->object->createSearch(); |
403
|
|
|
$search->setConditions( $search->compare( '=~', 'product.code', 'CN_' ) ); |
404
|
|
|
$result = $this->object->searchItems( $search ); |
405
|
|
|
|
406
|
|
|
$this->assertEquals( 0, count( $result ) ); |
407
|
|
|
|
408
|
|
|
|
409
|
|
|
$search = $this->object->createSearch(); |
410
|
|
|
$search->setConditions( $search->compare( '=~', 'product.code', 'CN%' ) ); |
411
|
|
|
$result = $this->object->searchItems( $search ); |
412
|
|
|
|
413
|
|
|
$this->assertEquals( 0, count( $result ) ); |
414
|
|
|
|
415
|
|
|
|
416
|
|
|
$search = $this->object->createSearch(); |
417
|
|
|
$search->setConditions( $search->compare( '=~', 'product.code', 'CN[C]' ) ); |
418
|
|
|
$result = $this->object->searchItems( $search ); |
419
|
|
|
|
420
|
|
|
$this->assertEquals( 0, count( $result ) ); |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
|
424
|
|
|
public function testSearchItemsLimit() |
425
|
|
|
{ |
426
|
|
|
$start = 0; |
427
|
|
|
$numproducts = 0; |
428
|
|
|
|
429
|
|
|
$search = $this->object->createSearch(); |
430
|
|
|
$search->setConditions( $search->compare( '==', 'product.editor', 'core:unittest' ) ); |
431
|
|
|
$search->setSlice( $start, 5 ); |
432
|
|
|
|
433
|
|
|
do |
434
|
|
|
{ |
435
|
|
|
$result = $this->object->searchItems( $search ); |
436
|
|
|
|
437
|
|
|
foreach( $result as $item ) { |
438
|
|
|
$numproducts++; |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
$count = count( $result ); |
442
|
|
|
$start += $count; |
443
|
|
|
$search->setSlice( $start, 5 ); |
444
|
|
|
} |
445
|
|
|
while( $count > 0 ); |
446
|
|
|
|
447
|
|
|
$this->assertEquals( 28, $numproducts ); |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
|
451
|
|
|
public function testGetSubManager() |
452
|
|
|
{ |
453
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'lists' ) ); |
454
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'lists', 'Standard' ) ); |
455
|
|
|
|
456
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'property' ) ); |
457
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'property', 'Standard' ) ); |
458
|
|
|
|
459
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type' ) ); |
460
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'type', 'Standard' ) ); |
461
|
|
|
|
462
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
463
|
|
|
$this->object->getSubManager( 'unknown' ); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
|
467
|
|
|
public function testGetSubManagerInvalidName() |
468
|
|
|
{ |
469
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
470
|
|
|
$this->object->getSubManager( 'lists', 'unknown' ); |
471
|
|
|
} |
472
|
|
|
} |
473
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.