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 testAddFilterCategory() |
50
|
|
|
{ |
51
|
|
|
$filter = $this->object->createFilter(); |
52
|
|
|
$filter = $this->object->addFilterCategory( $filter, 0 ); |
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.catalog.id', $list[0]->getName() ); |
61
|
|
|
$this->assertEquals( array( 0 ), $list[0]->getValue() ); |
62
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function testAddFilterText() |
67
|
|
|
{ |
68
|
|
|
$filter = $this->object->createFilter(); |
69
|
|
|
$filter = $this->object->addFilterText( $filter, 'Espresso' ); |
70
|
|
|
|
71
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
72
|
|
|
|
73
|
|
|
$list = $filter->getConditions()->getExpressions(); |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
if( !isset( $list[0] ) || !( $list[0] instanceof \Aimeos\MW\Criteria\Expression\Compare\Iface ) ) { |
77
|
|
|
throw new \RuntimeException( 'Wrong expression' ); |
78
|
|
|
} |
79
|
|
|
$this->assertEquals( 'index.text.relevance("default","de","Espresso")', $list[0]->getName() ); |
80
|
|
|
$this->assertEquals( 0, $list[0]->getValue() ); |
81
|
|
|
|
82
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
83
|
|
|
$this->assertEquals( 0, $filter->getSliceStart() ); |
84
|
|
|
$this->assertEquals( 100, $filter->getSliceSize() ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
public function testCreateFilterSortRelevanceCategory() |
89
|
|
|
{ |
90
|
|
|
$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_ONE; |
91
|
|
|
|
92
|
|
|
$filter = $this->object->createFilter(); |
93
|
|
|
$filter = $this->object->addFilterCategory( $filter, 0, $level, 'relevance', '-', 'test' ); |
94
|
|
|
|
95
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
96
|
|
|
|
97
|
|
|
$sort = $filter->getSortations(); |
98
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
99
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$this->assertEquals( 'sort:index.catalog.position("test",["0"])', $item->getName() ); |
103
|
|
|
$this->assertEquals( '-', $item->getOperator() ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
public function testCreateFilterSortRelevanceText() |
108
|
|
|
{ |
109
|
|
|
$filter = $this->object->createFilter( 'relevance', '-', 1, 2, 'test' ); |
110
|
|
|
$filter = $this->object->addFilterText( $filter, 'Espresso' ); |
111
|
|
|
|
112
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
113
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
114
|
|
|
$this->assertEquals( 1, $filter->getSliceStart() ); |
115
|
|
|
$this->assertEquals( 2, $filter->getSliceSize() ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testCreateFilterSortCode() |
120
|
|
|
{ |
121
|
|
|
$filter = $this->object->createFilter( 'code' ); |
122
|
|
|
|
123
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
124
|
|
|
|
125
|
|
|
$sort = $filter->getSortations(); |
126
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
127
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
$this->assertEquals( 'product.code', $item->getName() ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
public function testCreateFilterSortName() |
135
|
|
|
{ |
136
|
|
|
$filter = $this->object->createFilter( 'name' ); |
137
|
|
|
|
138
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
139
|
|
|
|
140
|
|
|
$sort = $filter->getSortations(); |
141
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
142
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$this->assertEquals( 'sort:index.text.value("default","de","name")', $item->getName() ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
public function testCreateFilterSortPrice() |
150
|
|
|
{ |
151
|
|
|
$filter = $this->object->createFilter( 'price' ); |
152
|
|
|
|
153
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
154
|
|
|
|
155
|
|
|
$sort = $filter->getSortations(); |
156
|
|
|
if( ( $item = reset( $sort ) ) === false ) { |
157
|
|
|
throw new \RuntimeException( 'Sortation not set' ); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
$this->assertStringStartsWith( 'sort:index.price.value("default","EUR","default")', $item->getName() ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
public function testCreateFilterSortInvalid() |
165
|
|
|
{ |
166
|
|
|
$filter = $this->object->createFilter( '', 'failure' ); |
167
|
|
|
|
168
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
169
|
|
|
$this->assertEquals( array(), $filter->getSortations() ); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function testGetItemsCategory() |
174
|
|
|
{ |
175
|
|
|
$catalogManager = \Aimeos\MShop\Catalog\Manager\Factory::createManager( \TestHelperFrontend::getContext() ); |
176
|
|
|
$search = $catalogManager->createSearch(); |
177
|
|
|
|
178
|
|
|
$search->setConditions( $search->compare( '==', 'catalog.code', 'new' ) ); |
179
|
|
|
$search->setSlice( 0, 1 ); |
180
|
|
|
$items = $catalogManager->searchItems( $search ); |
181
|
|
|
|
182
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
183
|
|
|
throw new \RuntimeException( 'Index item not found' ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
$filter = $this->object->createFilter( 'position', '+', 1, 1 ); |
187
|
|
|
$filter = $this->object->addFilterCategory( $filter, $item->getId() ); |
188
|
|
|
|
189
|
|
|
$total = 0; |
190
|
|
|
$results = $this->object->getItems( $filter, array(), $total ); |
191
|
|
|
|
192
|
|
|
$this->assertEquals( 3, $total ); |
193
|
|
|
$this->assertEquals( 1, count( $results ) ); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
public function testGetIndexItemsText() |
198
|
|
|
{ |
199
|
|
|
$filter = $this->object->createFilter( 'relevance', '+', 0, 1, 'unittype13' ); |
200
|
|
|
$filter = $this->object->addFilterText( $filter, 'Expresso', 'unittype13' ); |
201
|
|
|
|
202
|
|
|
$total = 0; |
203
|
|
|
$results = $this->object->getItems( $filter, array(), $total ); |
204
|
|
|
|
205
|
|
|
$this->assertEquals( 2, $total ); |
206
|
|
|
$this->assertEquals( 1, count( $results ) ); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
|
210
|
|
|
public function testCreateTextFilter() |
211
|
|
|
{ |
212
|
|
|
$filter = $this->object->createTextFilter( 'Expresso', 'name', '+', 0, 1 ); |
213
|
|
|
|
214
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $filter ); |
215
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Expression\\Combine\\Iface', $filter->getConditions() ); |
216
|
|
|
$this->assertEquals( 3, count( $filter->getConditions()->getExpressions() ) ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
public function testGetTextListName() |
221
|
|
|
{ |
222
|
|
|
$filter = $this->object->createTextFilter( 'Cafe Noire', 'relevance', '-', 0, 25, 'unittype19', 'name' ); |
223
|
|
|
$results = $this->object->getTextList( $filter ); |
224
|
|
|
|
225
|
|
|
$this->assertEquals( 1, count( $results ) ); |
226
|
|
|
$this->assertContains( 'Cafe Noire Cappuccino', $results ); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
} |
230
|
|
|
|