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