1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\Controller\Frontend\Catalog; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
protected function setUp() |
19
|
|
|
{ |
20
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Catalog\Standard( \TestHelperFrontend::getContext() ); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
protected function tearDown() |
25
|
|
|
{ |
26
|
|
|
unset( $this->object ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
public function testCreateManager() |
31
|
|
|
{ |
32
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->createManager( 'product' ) ); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function testCreateCatalogFilter() |
37
|
|
|
{ |
38
|
|
|
$filter = $this->object->createCatalogFilter( true ); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
41
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Expression\\Compare\\Iface', $filter->getConditions() ); |
42
|
|
|
$this->assertEquals( 'catalog.status', $filter->getConditions()->getName() ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testGetCatalogPath() |
47
|
|
|
{ |
48
|
|
|
$manager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
49
|
|
|
$item = $manager->getTree( null, array(), \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST ); |
50
|
|
|
|
51
|
|
|
$list = array(); |
52
|
|
|
foreach( $this->object->getCatalogPath( $item->getChild( 0 )->getId(), array( 'text' ) ) as $item ) { |
|
|
|
|
53
|
|
|
$list[$item->getCode()] = $item; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$this->assertEquals( 2, count( $list ) ); |
57
|
|
|
$this->assertArrayHasKey( 'root', $list ); |
58
|
|
|
$this->assertArrayHasKey( 'categories', $list ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testGetCatalogTree() |
63
|
|
|
{ |
64
|
|
|
$item = $this->object->getCatalogTree( null, array( 'text' ), \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE ); |
|
|
|
|
65
|
|
|
|
66
|
|
|
$this->assertEquals( 'Root', $item->getName() ); |
67
|
|
|
$this->assertEquals( 0, count( $item->getChildren() ) ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testAggregateIndex() |
72
|
|
|
{ |
73
|
|
|
$filter = $this->object->createIndexFilter(); |
|
|
|
|
74
|
|
|
$list = $this->object->aggregateIndex( $filter, 'index.attribute.id' ); |
|
|
|
|
75
|
|
|
|
76
|
|
|
$this->assertGreaterThan( 0, count( $list ) ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
public function testCreateIndexFilter() |
81
|
|
|
{ |
82
|
|
|
$filter = $this->object->createIndexFilter(); |
|
|
|
|
83
|
|
|
|
84
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
85
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
86
|
|
|
$this->assertEquals( 0, $filter->getSliceStart() ); |
87
|
|
|
$this->assertEquals( 100, $filter->getSliceSize() ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testCreateIndexFilterCategory() |
92
|
|
|
{ |
93
|
|
|
$filter = $this->object->createIndexFilterCategory( 0 ); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
96
|
|
|
|
97
|
|
|
$list = $filter->getConditions()->getExpressions(); |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) { |
101
|
|
|
throw new \RuntimeException( 'Wrong expression' ); |
102
|
|
|
} |
103
|
|
|
$this->assertEquals( 'index.catalog.id', $list[0]->getName() ); |
104
|
|
|
$this->assertEquals( array( 0 ), $list[0]->getValue() ); |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
108
|
|
|
$this->assertEquals( 0, $filter->getSliceStart() ); |
109
|
|
|
$this->assertEquals( 100, $filter->getSliceSize() ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
public function testCreateIndexFilterCategoryPosition() |
114
|
|
|
{ |
115
|
|
|
$filter = $this->object->createIndexFilterCategory( 0, 'relevance', '-', 1, 2, 'test' ); |
|
|
|
|
116
|
|
|
|
117
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
118
|
|
|
|
119
|
|
|
$sort = $filter->getSortations(); |
120
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
121
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$this->assertEquals( 'sort:index.catalog.position("test",["0"])', $item->getName() ); |
125
|
|
|
$this->assertEquals( '-', $item->getOperator() ); |
126
|
|
|
|
127
|
|
|
$this->assertEquals( 1, $filter->getSliceStart() ); |
128
|
|
|
$this->assertEquals( 2, $filter->getSliceSize() ); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
|
132
|
|
|
public function testCreateIndexFilterCategoryCode() |
133
|
|
|
{ |
134
|
|
|
$filter = $this->object->createIndexFilterCategory( 0, 'code' ); |
|
|
|
|
135
|
|
|
|
136
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
137
|
|
|
|
138
|
|
|
$sort = $filter->getSortations(); |
139
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
140
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$this->assertStringStartsWith( 'product.code', $item->getName() ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
public function testCreateIndexFilterCategoryName() |
148
|
|
|
{ |
149
|
|
|
$filter = $this->object->createIndexFilterCategory( 0, 'name' ); |
|
|
|
|
150
|
|
|
|
151
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
152
|
|
|
|
153
|
|
|
$sort = $filter->getSortations(); |
154
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
155
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$this->assertEquals( 'sort:index.text.value("default","de","name")', $item->getName() ); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
public function testCreateIndexFilterCategoryPrice() |
163
|
|
|
{ |
164
|
|
|
$filter = $this->object->createIndexFilterCategory( 0, 'price' ); |
|
|
|
|
165
|
|
|
|
166
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
167
|
|
|
|
168
|
|
|
$sort = $filter->getSortations(); |
169
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
170
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
$this->assertStringStartsWith( 'sort:index.price.value("default","EUR","default")', $item->getName() ); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
public function testCreateIndexFilterCategoryInvalidSortation() |
178
|
|
|
{ |
179
|
|
|
$filter = $this->object->createIndexFilterCategory( 0, 'failure' ); |
|
|
|
|
180
|
|
|
|
181
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
182
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
public function testAddIndexFilterCategory() |
187
|
|
|
{ |
188
|
|
|
$filter = $this->object->createIndexFilter(); |
|
|
|
|
189
|
|
|
$filter = $this->object->addIndexFilterCategory( $filter, 0 ); |
|
|
|
|
190
|
|
|
|
191
|
|
|
$list = $filter->getConditions()->getExpressions(); |
192
|
|
|
|
193
|
|
|
if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) { |
194
|
|
|
throw new \RuntimeException( 'Wrong expression' ); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
$this->assertEquals( 'index.catalog.id', $list[0]->getName() ); |
198
|
|
|
$this->assertEquals( array( 0 ), $list[0]->getValue() ); |
199
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
|
203
|
|
|
public function testCreateIndexFilterText() |
204
|
|
|
{ |
205
|
|
|
$filter = $this->object->createIndexFilterText( 'Espresso' ); |
|
|
|
|
206
|
|
|
|
207
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
208
|
|
|
|
209
|
|
|
$list = $filter->getConditions()->getExpressions(); |
210
|
|
|
|
211
|
|
|
|
212
|
|
|
if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) { |
213
|
|
|
throw new \RuntimeException( 'Wrong expression' ); |
214
|
|
|
} |
215
|
|
|
$this->assertEquals( 'index.text.relevance("default","de","Espresso")', $list[0]->getName() ); |
216
|
|
|
$this->assertEquals( 0, $list[0]->getValue() ); |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
220
|
|
|
$this->assertEquals( 0, $filter->getSliceStart() ); |
221
|
|
|
$this->assertEquals( 100, $filter->getSliceSize() ); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
public function testCreateIndexFilterTextRelevance() |
226
|
|
|
{ |
227
|
|
|
$filter = $this->object->createIndexFilterText( 'Espresso', 'relevance', '-', 1, 2, 'test' ); |
|
|
|
|
228
|
|
|
|
229
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
230
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
231
|
|
|
$this->assertEquals( 1, $filter->getSliceStart() ); |
232
|
|
|
$this->assertEquals( 2, $filter->getSliceSize() ); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
|
236
|
|
|
public function testCreateIndexFilterTextCode() |
237
|
|
|
{ |
238
|
|
|
$filter = $this->object->createIndexFilterText( 'Espresso', 'code' ); |
|
|
|
|
239
|
|
|
|
240
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
241
|
|
|
|
242
|
|
|
$sort = $filter->getSortations(); |
243
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
244
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
$this->assertEquals( 'product.code', $item->getName() ); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
|
251
|
|
|
public function testCreateIndexFilterTextName() |
252
|
|
|
{ |
253
|
|
|
$filter = $this->object->createIndexFilterText( 'Espresso', 'name' ); |
|
|
|
|
254
|
|
|
|
255
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
256
|
|
|
|
257
|
|
|
$sort = $filter->getSortations(); |
258
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
259
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
$this->assertEquals( 'sort:index.text.value("default","de","name")', $item->getName() ); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
|
266
|
|
|
public function testCreateIndexFilterTextPrice() |
267
|
|
|
{ |
268
|
|
|
$filter = $this->object->createIndexFilterCategory( 'Espresso', 'price' ); |
|
|
|
|
269
|
|
|
|
270
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
271
|
|
|
|
272
|
|
|
$sort = $filter->getSortations(); |
273
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
274
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
$this->assertStringStartsWith( 'sort:index.price.value("default","EUR","default")', $item->getName() ); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
public function testCreateIndexFilterTextInvalidSortation() |
282
|
|
|
{ |
283
|
|
|
$filter = $this->object->createIndexFilterText( '', 'failure' ); |
|
|
|
|
284
|
|
|
|
285
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
286
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
|
290
|
|
|
public function testAddIndexFilterText() |
291
|
|
|
{ |
292
|
|
|
$filter = $this->object->createIndexFilterText( 'Espresso' ); |
|
|
|
|
293
|
|
|
$filter = $this->object->addIndexFilterText( $filter, 'Espresso' ); |
|
|
|
|
294
|
|
|
|
295
|
|
|
$list = $filter->getConditions()->getExpressions(); |
296
|
|
|
|
297
|
|
|
if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) { |
298
|
|
|
throw new \RuntimeException( 'Wrong expression' ); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
$this->assertEquals( 'index.text.relevance("default","de","Espresso")', $list[0]->getName() ); |
302
|
|
|
$this->assertEquals( 0, $list[0]->getValue() ); |
303
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
|
307
|
|
|
public function testGetIndexItemsCategory() |
308
|
|
|
{ |
309
|
|
|
$catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
310
|
|
|
$search = $catalogManager->createSearch(); |
311
|
|
|
|
312
|
|
|
$search->setConditions( $search->compare( '==', 'catalog.code', 'new' ) ); |
313
|
|
|
$search->setSlice( 0, 1 ); |
314
|
|
|
$items = $catalogManager->searchItems( $search ); |
315
|
|
|
|
316
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
317
|
|
|
throw new \RuntimeException( 'Catalog item not found' ); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
$total = 0; |
321
|
|
|
$filter = $this->object->createIndexFilterCategory( $item->getId(), 'position', '+', 1, 1 ); |
|
|
|
|
322
|
|
|
$results = $this->object->getIndexItems( $filter, array(), $total ); |
|
|
|
|
323
|
|
|
|
324
|
|
|
$this->assertEquals( 3, $total ); |
325
|
|
|
$this->assertEquals( 1, count( $results ) ); |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
|
329
|
|
|
public function testGetIndexItemsText() |
330
|
|
|
{ |
331
|
|
|
$total = 0; |
332
|
|
|
$filter = $this->object->createIndexFilterText( 'Expresso', 'relevance', '+', 0, 1, 'unittype13' ); |
|
|
|
|
333
|
|
|
$results = $this->object->getIndexItems( $filter, array(), $total ); |
|
|
|
|
334
|
|
|
|
335
|
|
|
$this->assertEquals( 2, $total ); |
336
|
|
|
$this->assertEquals( 1, count( $results ) ); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
|
340
|
|
|
public function testGetProductItems() |
341
|
|
|
{ |
342
|
|
|
$list = $this->object->getProductItems( [-1] ); |
|
|
|
|
343
|
|
|
$this->assertEquals( 0, count( $list ) ); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
|
347
|
|
|
public function testCreateTextFilter() |
348
|
|
|
{ |
349
|
|
|
$filter = $this->object->createTextFilter( 'Expresso', 'name', '+', 0, 1 ); |
|
|
|
|
350
|
|
|
|
351
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
352
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Expression\\Combine\\Iface', $filter->getConditions() ); |
353
|
|
|
$this->assertEquals( 3, count( $filter->getConditions()->getExpressions() ) ); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
|
357
|
|
|
public function testGetTextListName() |
358
|
|
|
{ |
359
|
|
|
$filter = $this->object->createTextFilter( 'Cafe Noire', 'relevance', '-', 0, 25, 'unittype19', 'name' ); |
|
|
|
|
360
|
|
|
$results = $this->object->getTextList( $filter ); |
|
|
|
|
361
|
|
|
|
362
|
|
|
$this->assertEquals( 1, count( $results ) ); |
363
|
|
|
$this->assertContains( 'Cafe Noire Cappuccino', $results ); |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
} |
367
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.