Completed
Push — master ( 94eb6c...a336e2 )
by Aimeos
02:13
created

StandardTest::testFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
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-2018
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();
0 ignored issues
show
Bug Best Practice introduced by
The property context does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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
		$list = $this->object->aggregate( 'index.attribute.id' );
33
34
		$this->assertGreaterThan( 0, count( $list ) );
35
	}
36
37
38
	public function testAllOf()
39
	{
40
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
41
42
		$length = $manager->findItem( '30', [], 'product', 'length' )->getId();
43
		$width = $manager->findItem( '29', [], 'product', 'width' )->getId();
44
45
		$this->assertEquals( 1, count( $this->object->allOf( [$length, $width] )->search() ) );
46
	}
47
48
49
	public function testCategory()
50
	{
51
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
52
		$catId = $manager->findItem( 'cafe' )->getId();
53
54
		$this->assertEquals( 2, count( $this->object->category( $catId, 'promotion' )->search() ) );
55
	}
56
57
58
	public function testCategoryTree()
59
	{
60
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
61
62
		$catId = $manager->findItem( 'categories' )->getId();
63
		$grpId = $manager->findItem( 'group' )->getId();
64
65
		$this->object->category( [$catId, $grpId], 'promotion', \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE );
66
		$this->assertEquals( 3, count( $this->object->search() ) );
67
	}
68
69
70
	public function testCompare()
71
	{
72
		$this->assertEquals( 1, count( $this->object->compare( '==', 'product.type', 'bundle' )->search() ) );
73
	}
74
75
76
	public function testFind()
77
	{
78
		$item = $this->object->uses( ['product'] )->find( 'U:BUNDLE' );
79
80
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item );
81
		$this->assertEquals( 2, count( $item->getRefItems( 'product' ) ) );
82
	}
83
84
85
	public function testFunction()
86
	{
87
		$str = $this->object->function( 'product:has', ['domain', 'type', 'refid'] );
88
		$this->assertEquals( 'product:has("domain","type","refid")', $str );
89
	}
90
91
92
	public function testGet()
93
	{
94
		$item = \Aimeos\MShop::create( $this->context, 'product' )->findItem( 'U:BUNDLE' );
95
		$item = $this->object->uses( ['product'] )->get( $item->getId() );
96
97
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item );
98
		$this->assertEquals( 2, count( $item->getRefItems( 'product' ) ) );
99
	}
100
101
102
	public function testHas()
103
	{
104
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
105
		$attrId = $manager->findItem( '30', [], 'product', 'length' )->getId();
106
107
		$this->assertEquals( 1, count( $this->object->has( 'attribute', 'variant', $attrId )->search() ) );
108
	}
109
110
111
	public function testOneOf()
112
	{
113
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
114
115
		$length = $manager->findItem( '30', [], 'product', 'length' )->getId();
116
		$width = $manager->findItem( '30', [], 'product', 'width' )->getId();
117
118
		$this->assertEquals( 2, count( $this->object->oneOf( [$length, $width] )->search() ) );
119
	}
120
121
122
	public function testOneOfList()
123
	{
124
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
125
126
		$length = $manager->findItem( '30', [], 'product', 'length' )->getId();
127
		$width = $manager->findItem( '30', [], 'product', 'width' )->getId();
128
129
		$this->assertEquals( 1, count( $this->object->oneOf( [[$length], [$width]] )->search() ) );
130
	}
131
132
133
	public function testParse()
134
	{
135
		$cond = ['&&' => [['>' => ['product.status' => 0]], ['==' => ['product.type' => 'default']]]];
136
		$this->assertEquals( 4, count( $this->object->parse( $cond )->search() ) );
137
	}
138
139
140
	public function testProduct()
141
	{
142
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
143
144
		$cncId = $manager->findItem( 'CNC' )->getId();
145
		$cneId = $manager->findItem( 'CNE' )->getId();
146
147
		$this->assertEquals( 2, count( $this->object->product( [$cncId, $cneId] )->search() ) );
148
	}
149
150
151
	public function testProperty()
152
	{
153
		$this->assertEquals( 1, count( $this->object->property( 'package-weight', '1.25' )->search() ) );
154
	}
155
156
157
	public function testResolve()
158
	{
159
		$item = $this->object->resolve( 'Cafe_Noire_Cappuccino' );
160
161
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item );
162
		$this->assertEquals( 'Cafe Noire Cappuccino', $item->getLabel() );
163
	}
164
165
166
	public function testSearch()
167
	{
168
		$total = 0;
169
		$items = $this->object->uses( ['price'] )->sort( 'code' )->search( $total );
170
171
		$this->assertEquals( 8, count( $items ) );
172
		$this->assertEquals( 8, $total );
173
		$this->assertEquals( 2, count( current( $items )->getRefItems( 'price' ) ) );
174
	}
175
176
177
	public function testSlice()
178
	{
179
		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) );
180
	}
181
182
183
	public function testSort()
184
	{
185
		$this->assertEquals( 8, count( $this->object->sort( '+relevance' )->search() ) );
186
	}
187
188
189
	public function testSortGeneric()
190
	{
191
		$this->assertEquals( 8, count( $this->object->sort( '-product.status' )->search() ) );
192
	}
193
194
195
	public function testSortMultiple()
196
	{
197
		$this->assertEquals( 8, count( $this->object->sort( '-product.status,product.id' )->search() ) );
198
	}
199
200
201
	public function testSortCode()
202
	{
203
		$result = $this->object->sort( 'code' )->search();
204
		$this->assertEquals( 'CNC', reset( $result )->getCode() );
205
	}
206
207
208
	public function testSortCodeDesc()
209
	{
210
		$result = $this->object->sort( '-code' )->search();
211
		$this->assertStringStartsWith( 'U:', reset( $result )->getCode() );
212
	}
213
214
215
	public function testSortCtime()
216
	{
217
		$this->assertEquals( 8, count( $this->object->sort( 'ctime' )->search() ) );
218
	}
219
220
221
	public function testSortCtimeDesc()
222
	{
223
		$this->assertEquals( 8, count( $this->object->sort( '-ctime' )->search() ) );
224
	}
225
226
227
	public function testSortName()
228
	{
229
		$result = $this->object->uses( ['text'] )->sort( 'name' )->search();
230
		$this->assertEquals( 'Cafe Noire Cappuccino', reset( $result )->getName() );
231
	}
232
233
234
	public function testSortNameDesc()
235
	{
236
		$result = $this->object->uses( ['text'] )->sort( '-name' )->search();
237
		$this->assertEquals( 'Unterproduct 3', reset( $result )->getName() );
238
	}
239
240
241
	public function testSortPrice()
242
	{
243
		$result = $this->object->uses( ['price'] )->sort( 'price' )->search();
244
		$prices = reset( $result )->getRefItems( 'price', 'default', 'default' );
245
246
		$this->assertEquals( '12.00', reset( $prices )->getValue() );
247
	}
248
249
250
	public function testSortPriceDesc()
251
	{
252
		$result = $this->object->uses( ['price'] )->sort( '-price' )->search();
253
		$prices = reset( $result )->getRefItems( 'price', 'default', 'default' );
254
255
		$this->assertEquals( '600.00', reset( $prices )->getValue() );
256
	}
257
258
259
	public function testSortRelevanceCategory()
260
	{
261
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
262
		$catId = $manager->findItem( 'new' )->getId();
263
264
		$result = $this->object->category( $catId )->sort( 'relevance' )->search();
265
266
		$this->assertEquals( 3, count( $result ) );
267
		$this->assertEquals( 'CNE', reset( $result )->getCode() );
268
		$this->assertEquals( 'U:BUNDLE', end( $result )->getCode() );
269
	}
270
271
272
	public function testSortRelevanceSupplier()
273
	{
274
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
275
		$supId = $manager->findItem( 'unitCode001' )->getId();
276
277
		$result = $this->object->supplier( $supId )->sort( 'relevance' )->search();
278
279
		$this->assertEquals( 2, count( $result ) );
280
		$this->assertEquals( 'CNC', reset( $result )->getCode() );
281
		$this->assertEquals( 'CNE', end( $result )->getCode() );
282
	}
283
284
285
	public function testSupplier()
286
	{
287
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
288
		$supId = $manager->findItem( 'unitCode001' )->getId();
289
290
		$this->assertEquals( 2, count( $this->object->supplier( $supId )->search() ) );
291
	}
292
293
294
	public function testText()
295
	{
296
		$this->assertEquals( 2, count( $this->object->text( 'Cafe' )->search() ) );
297
	}
298
299
300
	public function testUses()
301
	{
302
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
303
	}
304
}
305