1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Product; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
protected function setUp() |
18
|
|
|
{ |
19
|
|
|
$this->context = \TestHelperFrontend::getContext(); |
20
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Product\Standard( $this->context ); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
protected function tearDown() |
25
|
|
|
{ |
26
|
|
|
unset( $this->object ); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
public function testAggregate() |
31
|
|
|
{ |
32
|
|
|
$filter = $this->object->createFilter(); |
33
|
|
|
$list = $this->object->aggregate( $filter, 'index.attribute.id' ); |
34
|
|
|
|
35
|
|
|
$this->assertGreaterThan( 0, count( $list ) ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function testCreateFilter() |
40
|
|
|
{ |
41
|
|
|
$filter = $this->object->createFilter(); |
42
|
|
|
|
43
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
44
|
|
|
$this->assertEquals( [], $filter->getSortations() ); |
45
|
|
|
$this->assertEquals( 0, $filter->getSliceStart() ); |
46
|
|
|
$this->assertEquals( 100, $filter->getSliceSize() ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
public function testCreateFilterIgnoreDates() |
51
|
|
|
{ |
52
|
|
|
$this->context->getConfig()->set( 'controller/frontend/product/ignore-dates', true ); |
53
|
|
|
|
54
|
|
|
$filter = $this->object->createFilter(); |
55
|
|
|
|
56
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
public function testAddFilterAttribute() |
61
|
|
|
{ |
62
|
|
|
$filter = $this->object->createFilter(); |
63
|
|
|
$filter = $this->object->addFilterAttribute( $filter, array( 0, 1 ), [], [] ); |
64
|
|
|
|
65
|
|
|
$list = $filter->getConditions()->getExpressions(); |
66
|
|
|
|
67
|
|
|
if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) { |
68
|
|
|
throw new \RuntimeException( 'Wrong expression' ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$this->assertEquals( 'index.attributeaggregate([0,1])', $list[0]->getName() ); |
72
|
|
|
$this->assertEquals( 2, $list[0]->getValue() ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testAddFilterAttributeOptions() |
77
|
|
|
{ |
78
|
|
|
$filter = $this->object->createFilter(); |
79
|
|
|
$filter = $this->object->addFilterAttribute( $filter, [], array( 1 ), [] ); |
80
|
|
|
|
81
|
|
|
$list = $filter->getConditions()->getExpressions(); |
82
|
|
|
|
83
|
|
|
if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) { |
84
|
|
|
throw new \RuntimeException( 'Wrong expression' ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$this->assertEquals( 'index.attributeaggregate([1])', $list[0]->getName() ); |
88
|
|
|
$this->assertEquals( 0, $list[0]->getValue() ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function testAddFilterAttributeOne() |
93
|
|
|
{ |
94
|
|
|
$filter = $this->object->createFilter(); |
95
|
|
|
$filter = $this->object->addFilterAttribute( $filter, [], [], array( 'test' => array( 2 ) ) ); |
96
|
|
|
|
97
|
|
|
$list = $filter->getConditions()->getExpressions(); |
98
|
|
|
|
99
|
|
|
if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) { |
100
|
|
|
throw new \RuntimeException( 'Wrong expression' ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$this->assertEquals( 'index.attributeaggregate([2])', $list[0]->getName() ); |
104
|
|
|
$this->assertEquals( 0, $list[0]->getValue() ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testAddFilterCategory() |
109
|
|
|
{ |
110
|
|
|
$context = \TestHelperFrontend::getContext(); |
111
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $context, 'catalog' ); |
112
|
|
|
|
113
|
|
|
$catId = $manager->findItem( 'root' )->getId(); |
114
|
|
|
$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_LIST; |
115
|
|
|
|
116
|
|
|
$filter = $this->object->createFilter(); |
117
|
|
|
$filter = $this->object->addFilterCategory( $filter, $catId, $level ); |
118
|
|
|
|
119
|
|
|
$list = $filter->getConditions()->getExpressions(); |
120
|
|
|
|
121
|
|
|
if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) { |
122
|
|
|
throw new \RuntimeException( 'Wrong expression' ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$this->assertEquals( 'index.catalog.id', $list[0]->getName() ); |
126
|
|
|
$this->assertEquals( 3, count( $list[0]->getValue() ) ); |
127
|
|
|
$this->assertEquals( [], $filter->getSortations() ); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
public function testAddFilterText() |
132
|
|
|
{ |
133
|
|
|
$filter = $this->object->createFilter(); |
134
|
|
|
$filter = $this->object->addFilterText( $filter, 'Espresso' ); |
135
|
|
|
|
136
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
137
|
|
|
|
138
|
|
|
$list = $filter->getConditions()->getExpressions(); |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) { |
142
|
|
|
throw new \RuntimeException( 'Wrong expression' ); |
143
|
|
|
} |
144
|
|
|
$this->assertEquals( 'index.text.relevance("default","de","Espresso")', $list[0]->getName() ); |
145
|
|
|
$this->assertEquals( 0, $list[0]->getValue() ); |
146
|
|
|
|
147
|
|
|
$this->assertEquals( [], $filter->getSortations() ); |
148
|
|
|
$this->assertEquals( 0, $filter->getSliceStart() ); |
149
|
|
|
$this->assertEquals( 100, $filter->getSliceSize() ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
public function testCreateFilterSortRelevanceCategory() |
154
|
|
|
{ |
155
|
|
|
$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE; |
156
|
|
|
|
157
|
|
|
$filter = $this->object->createFilter(); |
158
|
|
|
$filter = $this->object->addFilterCategory( $filter, 0, $level, 'relevance', '-', 'test' ); |
159
|
|
|
|
160
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
161
|
|
|
|
162
|
|
|
$sort = $filter->getSortations(); |
163
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
164
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
$this->assertEquals( 'sort:index.catalog.position("test",["0"])', $item->getName() ); |
168
|
|
|
$this->assertEquals( '-', $item->getOperator() ); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
public function testCreateFilterSortRelevanceText() |
173
|
|
|
{ |
174
|
|
|
$filter = $this->object->createFilter( 'relevance', '-', 1, 2, 'test' ); |
175
|
|
|
$filter = $this->object->addFilterText( $filter, 'Espresso' ); |
176
|
|
|
|
177
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
178
|
|
|
$this->assertEquals( [], $filter->getSortations() ); |
179
|
|
|
$this->assertEquals( 1, $filter->getSliceStart() ); |
180
|
|
|
$this->assertEquals( 2, $filter->getSliceSize() ); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
public function testCreateFilterSortCode() |
185
|
|
|
{ |
186
|
|
|
$filter = $this->object->createFilter( 'code' ); |
187
|
|
|
|
188
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
189
|
|
|
|
190
|
|
|
$sort = $filter->getSortations(); |
191
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
192
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
$this->assertEquals( 'product.code', $item->getName() ); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
public function testCreateFilterSortName() |
200
|
|
|
{ |
201
|
|
|
$filter = $this->object->createFilter( 'name' ); |
202
|
|
|
|
203
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
204
|
|
|
|
205
|
|
|
$sort = $filter->getSortations(); |
206
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
207
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
$this->assertEquals( 'sort:index.text.value("default","de","name")', $item->getName() ); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
|
214
|
|
|
public function testCreateFilterSortPrice() |
215
|
|
|
{ |
216
|
|
|
$filter = $this->object->createFilter( 'price' ); |
217
|
|
|
|
218
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
219
|
|
|
|
220
|
|
|
$sort = $filter->getSortations(); |
221
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
222
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$this->assertStringStartsWith( 'sort:index.price.value("default","EUR","default")', $item->getName() ); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
|
229
|
|
|
public function testCreateFilterSortInvalid() |
230
|
|
|
{ |
231
|
|
|
$filter = $this->object->createFilter( '', 'failure' ); |
232
|
|
|
|
233
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
234
|
|
|
$this->assertEquals( [], $filter->getSortations() ); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
public function testGetItem() |
239
|
|
|
{ |
240
|
|
|
$context = \TestHelperFrontend::getContext(); |
241
|
|
|
$id = \Aimeos\MShop\Factory::createManager( $context, 'product' )->findItem( 'CNC' )->getId(); |
242
|
|
|
|
243
|
|
|
$result = $this->object->getItem( $id ); |
244
|
|
|
|
245
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $result ); |
246
|
|
|
$this->assertGreaterThan( 0, $result->getPropertyItems() ); |
247
|
|
|
$this->assertGreaterThan( 0, $result->getRefItems( 'attribute' ) ); |
248
|
|
|
$this->assertGreaterThan( 0, $result->getRefItems( 'media' ) ); |
249
|
|
|
$this->assertGreaterThan( 0, $result->getRefItems( 'price' ) ); |
250
|
|
|
$this->assertGreaterThan( 0, $result->getRefItems( 'product' ) ); |
251
|
|
|
$this->assertGreaterThan( 0, $result->getRefItems( 'text' ) ); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
|
255
|
|
|
public function testGetItems() |
256
|
|
|
{ |
257
|
|
|
$context = \TestHelperFrontend::getContext(); |
258
|
|
|
$context->getConfig()->set( 'controller/frontend/product/ignore-dates', true ); |
259
|
|
|
|
260
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
261
|
|
|
|
262
|
|
|
$search = $manager->createSearch(); |
263
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', array( 'CNC', 'CNE' ) ) ); |
264
|
|
|
|
265
|
|
|
$ids = []; |
266
|
|
|
foreach( $manager->searchItems( $search ) as $productItem ) { |
267
|
|
|
$ids[] = $productItem->getId(); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
|
271
|
|
|
$result = $this->object->getItems( $ids ); |
272
|
|
|
|
273
|
|
|
$this->assertEquals( 2, count( $result ) ); |
274
|
|
|
|
275
|
|
|
foreach( $result as $productItem ) { |
276
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Product\Item\Iface', $productItem ); |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
public function testSearchItemsCategory() |
282
|
|
|
{ |
283
|
|
|
$catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
284
|
|
|
$search = $catalogManager->createSearch(); |
285
|
|
|
|
286
|
|
|
$search->setConditions( $search->compare( '==', 'catalog.code', 'new' ) ); |
287
|
|
|
$search->setSlice( 0, 1 ); |
288
|
|
|
$items = $catalogManager->searchItems( $search ); |
289
|
|
|
|
290
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
291
|
|
|
throw new \RuntimeException( 'Product item not found' ); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
$filter = $this->object->createFilter( 'position', '+', 1, 1 ); |
295
|
|
|
$filter = $this->object->addFilterCategory( $filter, $item->getId() ); |
296
|
|
|
|
297
|
|
|
$total = 0; |
298
|
|
|
$results = $this->object->searchItems( $filter, [], $total ); |
299
|
|
|
|
300
|
|
|
$this->assertEquals( 3, $total ); |
301
|
|
|
$this->assertEquals( 1, count( $results ) ); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
public function testSearchItemsText() |
306
|
|
|
{ |
307
|
|
|
$filter = $this->object->createFilter( 'relevance', '+', 0, 1, 'unittype13' ); |
308
|
|
|
$filter = $this->object->addFilterText( $filter, 'Expresso', 'relevance', '+', 'unittype13' ); |
309
|
|
|
|
310
|
|
|
$total = 0; |
311
|
|
|
$results = $this->object->searchItems( $filter, [], $total ); |
312
|
|
|
|
313
|
|
|
$this->assertEquals( 2, $total ); |
314
|
|
|
$this->assertEquals( 1, count( $results ) ); |
315
|
|
|
} |
316
|
|
|
} |
317
|
|
|
|