Passed
Push — master ( c4e37e...d53723 )
by Aimeos
02:45
created

StandardTest::testRadius()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2022
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Product;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $object;
16
17
18
	protected function setUp() : void
19
	{
20
		$this->context = \TestHelper::context();
21
		$this->object = new \Aimeos\Controller\Frontend\Product\Standard( $this->context );
22
	}
23
24
25
	protected function tearDown() : void
26
	{
27
		unset( $this->object, $this->context );
28
	}
29
30
31
	public function testAggregate()
32
	{
33
		$list = $this->object->aggregate( 'index.attribute.id' );
34
35
		$this->assertGreaterThan( 0, count( $list ) );
36
	}
37
38
39
	public function testAllOf()
40
	{
41
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
42
43
		$length = $manager->find( '30', [], 'product', 'length' )->getId();
44
		$width = $manager->find( '29', [], 'product', 'width' )->getId();
45
46
		$this->assertEquals( 2, count( $this->object->allOf( [$length, $width] )->search() ) );
47
	}
48
49
50
	public function testCategory()
51
	{
52
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
53
		$catId = $manager->find( 'cafe' )->getId();
54
55
		$this->assertEquals( 2, count( $this->object->category( $catId, 'promotion' )->search() ) );
56
	}
57
58
59
	public function testCategoryTree()
60
	{
61
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
62
63
		$catId = $manager->find( 'categories' )->getId();
64
		$grpId = $manager->find( 'group' )->getId();
65
66
		$this->object->category( [$catId, $grpId], 'promotion', \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
67
		$this->assertEquals( 3, count( $this->object->search() ) );
68
	}
69
70
71
	public function testCompare()
72
	{
73
		$this->assertEquals( 1, count( $this->object->compare( '==', 'product.type', 'bundle' )->search() ) );
74
	}
75
76
77
	public function testFind()
78
	{
79
		$item = $this->object->uses( ['product'] )->find( 'U:BUNDLE' );
80
81
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item );
82
		$this->assertEquals( 2, count( $item->getRefItems( 'product' ) ) );
83
	}
84
85
86
	public function testFunction()
87
	{
88
		$str = $this->object->function( 'product:has', ['domain', 'type', 'refid'] );
89
		$this->assertEquals( 'product:has("domain","type","refid")', $str );
90
	}
91
92
93
	public function testGet()
94
	{
95
		$item = \Aimeos\MShop::create( $this->context, 'product' )->find( 'U:BUNDLE' );
96
		$item = $this->object->uses( ['product'] )->get( $item->getId() );
97
98
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item );
99
		$this->assertEquals( 2, count( $item->getRefItems( 'product' ) ) );
100
	}
101
102
103
	public function testHas()
104
	{
105
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
106
		$attrId = $manager->find( '30', [], 'product', 'length' )->getId();
107
108
		$this->assertEquals( 1, count( $this->object->has( 'attribute', 'variant', $attrId )->search() ) );
109
	}
110
111
112
	public function testOneOf()
113
	{
114
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
115
116
		$length = $manager->find( '30', [], 'product', 'length' )->getId();
117
		$width = $manager->find( '29', [], 'product', 'width' )->getId();
118
119
		$this->assertEquals( 4, count( $this->object->oneOf( [$length, $width] )->search() ) );
120
	}
121
122
123
	public function testOneOfList()
124
	{
125
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
126
127
		$length = $manager->find( '30', [], 'product', 'length' )->getId();
128
		$width = $manager->find( '30', [], 'product', 'width' )->getId();
129
130
		$this->assertEquals( 1, count( $this->object->oneOf( [[$length], [$width]] )->search() ) );
131
	}
132
133
134
	public function testParse()
135
	{
136
		$cond = ['&&' => [['>' => ['product.status' => 0]], ['==' => ['product.type' => 'default']]]];
137
		$this->assertEquals( 4, count( $this->object->parse( $cond )->search() ) );
138
	}
139
140
141
	public function testPrice()
142
	{
143
		$this->assertEquals( 5, count( $this->object->price( 20 )->search() ) );
144
	}
145
146
147
	public function testPriceArray()
148
	{
149
		$this->assertEquals( 5, count( $this->object->price( [20] )->search() ) );
150
	}
151
152
153
	public function testPriceBoth()
154
	{
155
		$this->assertEquals( 4, count( $this->object->price( [15, 20] )->search() ) );
156
	}
157
158
159
	public function testProduct()
160
	{
161
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
162
163
		$cncId = $manager->find( 'CNC' )->getId();
164
		$cneId = $manager->find( 'CNE' )->getId();
165
166
		$this->assertEquals( 2, count( $this->object->product( [$cncId, $cneId] )->search() ) );
167
	}
168
169
170
	public function testProperty()
171
	{
172
		$this->assertEquals( 1, count( $this->object->property( 'package-weight', '1.25' )->search() ) );
173
	}
174
175
176
	public function testRadius()
177
	{
178
		$this->assertEquals( 2, count( $this->object->radius( [52.5, 10], 115 )->search() ) );
179
	}
180
181
182
	public function testResolve()
183
	{
184
		$item = $this->object->resolve( 'Cafe-Noire-Cappuccino' );
185
186
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item );
187
		$this->assertEquals( 'Cafe Noire Cappuccino', $item->getLabel() );
188
	}
189
190
191
	public function testSearch()
192
	{
193
		$total = 0;
194
		$items = $this->object->uses( ['price'] )->sort( 'code' )->search( $total );
195
196
		$this->assertEquals( 8, count( $items ) );
197
		$this->assertEquals( 8, $total );
198
		$this->assertEquals( 2, count( $items->first()->getRefItems( 'price' ) ) );
199
	}
200
201
202
	public function testSearchAll()
203
	{
204
		$total = 0;
205
		$this->context->config()->set( 'controller/frontend/product/show-all', true );
206
		$object = new \Aimeos\Controller\Frontend\Product\Standard( $this->context );
207
208
		$items = $object->search( $total );
209
210
		$this->assertEquals( 22, count( $items ) );
211
		$this->assertEquals( 22, $total );
212
	}
213
214
215
	public function testSlice()
216
	{
217
		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) );
218
	}
219
220
221
	public function testSort()
222
	{
223
		$this->assertEquals( 8, count( $this->object->sort( '+relevance' )->search() ) );
224
	}
225
226
227
	public function testSortGeneric()
228
	{
229
		$this->assertEquals( 8, count( $this->object->sort( '-product.status' )->search() ) );
230
	}
231
232
233
	public function testSortMultiple()
234
	{
235
		$this->assertEquals( 8, count( $this->object->sort( 'sort:index.text:relevance("de","test(\"\")"),product.id' )->search() ) );
236
	}
237
238
239
	public function testSortCode()
240
	{
241
		$result = $this->object->sort( 'code' )->search();
242
		$this->assertEquals( 'ABCD', $result->first()->getCode() );
243
	}
244
245
246
	public function testSortCodeDesc()
247
	{
248
		$result = $this->object->sort( '-code' )->search();
249
		$this->assertStringStartsWith( 'U:', $result->first()->getCode() );
250
	}
251
252
253
	public function testSortCtime()
254
	{
255
		$this->assertEquals( 8, count( $this->object->sort( 'ctime' )->search() ) );
256
	}
257
258
259
	public function testSortCtimeDesc()
260
	{
261
		$this->assertEquals( 8, count( $this->object->sort( '-ctime' )->search() ) );
262
	}
263
264
265
	public function testSortName()
266
	{
267
		$result = $this->object->uses( ['text'] )->sort( 'name' )->search();
268
		$this->assertEquals( 'Cafe Noire Cappuccino', $result->first()->getName() );
269
	}
270
271
272
	public function testSortNameDesc()
273
	{
274
		$result = $this->object->uses( ['text'] )->sort( '-name' )->search();
275
		$this->assertEquals( 'Unterproduct 1', $result->first()->getName() );
276
	}
277
278
279
	public function testSortPrice()
280
	{
281
		$result = $this->object->uses( ['price'] )->sort( 'price' )->search();
282
		$prices = $result->first()->getRefItems( 'price', 'default', 'default' );
283
284
		$this->assertEquals( '12.00', $prices->first()->getValue() );
285
	}
286
287
288
	public function testSortPriceDesc()
289
	{
290
		$result = $this->object->uses( ['price'] )->sort( '-price' )->search();
291
		$prices = $result->first()->getRefItems( 'price', 'default', 'default' );
292
293
		$this->assertEquals( '600.00', $prices->first()->getValue() );
294
	}
295
296
297
	public function testSortRelevanceCategory()
298
	{
299
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
300
		$catId = $manager->find( 'new' )->getId();
301
302
		$result = $this->object->category( $catId )->sort( 'relevance' )->search();
303
304
		$this->assertEquals( 3, count( $result ) );
305
		$this->assertEquals( 'CNE', $result->first()->getCode() );
306
		$this->assertEquals( 'U:BUNDLE', $result->last()->getCode() );
307
	}
308
309
310
	public function testSortRelevanceSupplier()
311
	{
312
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
313
		$supId = $manager->find( 'unitSupplier001' )->getId();
314
315
		$result = $this->object->supplier( $supId )->sort( 'relevance' )->search();
316
317
		$this->assertEquals( 2, count( $result ) );
318
		$this->assertEquals( 'CNC', $result->first()->getCode() );
319
		$this->assertEquals( 'CNE', $result->last()->getCode() );
320
	}
321
322
323
	public function testSupplier()
324
	{
325
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
326
		$supId = $manager->find( 'unitSupplier001' )->getId();
327
328
		$this->assertEquals( 2, count( $this->object->supplier( $supId )->search() ) );
329
	}
330
331
332
	public function testText()
333
	{
334
		$this->assertEquals( 3, count( $this->object->text( 'Cafe' )->search() ) );
335
	}
336
337
338
	public function testTextCode()
339
	{
340
		$this->assertEquals( 2, count( $this->object->text( 'CNE' )->search() ) );
341
	}
342
343
344
	public function testUses()
345
	{
346
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
347
	}
348
}
349