Passed
Push — master ( 517d52...c8a2c5 )
by Aimeos
02:30
created

StandardTest::testAllOf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
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
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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( 2, 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 testGet()
86
	{
87
		$item = \Aimeos\MShop::create( $this->context, 'product' )->findItem( 'U:BUNDLE' );
88
		$item = $this->object->uses( ['product'] )->get( $item->getId() );
89
90
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item );
91
		$this->assertEquals( 2, count( $item->getRefItems( 'product' ) ) );
92
	}
93
94
95
	public function testHas()
96
	{
97
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
98
		$attrId = $manager->findItem( '30', [], 'product', 'length' )->getId();
99
100
		$this->assertEquals( 1, count( $this->object->has( 'attribute', 'variant', $attrId )->search() ) );
101
	}
102
103
104
	public function testOneOf()
105
	{
106
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
107
108
		$length = $manager->findItem( '30', [], 'product', 'length' )->getId();
109
		$width = $manager->findItem( '30', [], 'product', 'width' )->getId();
110
111
		$this->assertEquals( 3, count( $this->object->oneOf( [$length, $width] )->search() ) );
112
	}
113
114
115
	public function testOneOfList()
116
	{
117
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
118
119
		$length = $manager->findItem( '30', [], 'product', 'length' )->getId();
120
		$width = $manager->findItem( '30', [], 'product', 'width' )->getId();
121
122
		$this->assertEquals( 1, count( $this->object->oneOf( [[$length], [$width]] )->search() ) );
123
	}
124
125
126
	public function testParse()
127
	{
128
		$cond = ['&&' => [['>' => ['product.status' => 0]], ['==' => ['product.type' => 'default']]]];
129
		$this->assertEquals( 4, count( $this->object->parse( $cond )->search() ) );
130
	}
131
132
133
	public function testProduct()
134
	{
135
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
136
137
		$cncId = $manager->findItem( 'CNC' )->getId();
138
		$cneId = $manager->findItem( 'CNE' )->getId();
139
140
		$this->assertEquals( 2, count( $this->object->product( [$cncId, $cneId] )->search() ) );
141
	}
142
143
144
	public function testProperty()
145
	{
146
		$this->assertEquals( 1, count( $this->object->property( 'package-weight', '1.25' )->search() ) );
147
	}
148
149
150
	public function testResolve()
151
	{
152
		$item = $this->object->resolve( 'Cafe_Noire_Cappuccino' );
153
154
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item );
155
		$this->assertEquals( 'Cafe Noire Cappuccino', $item->getLabel() );
156
	}
157
158
159
	public function testSearch()
160
	{
161
		$total = 0;
162
		$items = $this->object->uses( ['price'] )->sort( 'code' )->search( $total );
163
164
		$this->assertEquals( 8, count( $items ) );
165
		$this->assertEquals( 8, $total );
166
		$this->assertEquals( 2, count( current( $items )->getRefItems( 'price' ) ) );
167
	}
168
169
170
	public function testSlice()
171
	{
172
		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) );
173
	}
174
175
176
	public function testSort()
177
	{
178
		$this->assertEquals( 8, count( $this->object->sort( 'relevance' )->search() ) );
179
	}
180
181
182
	public function testSortGeneric()
183
	{
184
		$this->assertEquals( 8, count( $this->object->sort( 'product.status' )->search() ) );
185
	}
186
187
188
	public function testSortCode()
189
	{
190
		$result = $this->object->sort( 'code' )->search();
191
		$this->assertEquals( 'CNC', reset( $result )->getCode() );
192
	}
193
194
195
	public function testSortCodeDesc()
196
	{
197
		$result = $this->object->sort( '-code' )->search();
198
		$this->assertStringStartsWith( 'U:', reset( $result )->getCode() );
199
	}
200
201
202
	public function testSortCtime()
203
	{
204
		$this->assertEquals( 8, count( $this->object->sort( 'ctime' )->search() ) );
205
	}
206
207
208
	public function testSortCtimeDesc()
209
	{
210
		$this->assertEquals( 8, count( $this->object->sort( '-ctime' )->search() ) );
211
	}
212
213
214
	public function testSortName()
215
	{
216
		$result = $this->object->uses( ['text'] )->sort( 'name' )->search();
217
		$this->assertEquals( 'Cafe Noire Cappuccino', reset( $result )->getName() );
218
	}
219
220
221
	public function testSortNameDesc()
222
	{
223
		$result = $this->object->uses( ['text'] )->sort( '-name' )->search();
224
		$this->assertEquals( 'Unterproduct 3', reset( $result )->getName() );
225
	}
226
227
228
	public function testSortPrice()
229
	{
230
		$result = $this->object->uses( ['price'] )->sort( 'price' )->search();
231
		$prices = reset( $result )->getRefItems( 'price', 'default', 'default' );
232
233
		$this->assertEquals( '12.00', reset( $prices )->getValue() );
234
	}
235
236
237
	public function testSortPriceDesc()
238
	{
239
		$result = $this->object->uses( ['price'] )->sort( '-price' )->search();
240
		$prices = reset( $result )->getRefItems( 'price', 'default', 'default' );
241
242
		$this->assertEquals( '600.00', reset( $prices )->getValue() );
243
	}
244
245
246
	public function testSortRelevanceCategory()
247
	{
248
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
249
		$catId = $manager->findItem( 'new' )->getId();
250
251
		$result = $this->object->category( $catId )->sort( 'relevance' )->search();
252
253
		$this->assertEquals( 3, count( $result ) );
254
		$this->assertEquals( 'CNE', reset( $result )->getCode() );
255
		$this->assertEquals( 'U:BUNDLE', end( $result )->getCode() );
256
	}
257
258
259
	public function testSortRelevanceSupplier()
260
	{
261
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
262
		$supId = $manager->findItem( 'unitCode001' )->getId();
263
264
		$result = $this->object->supplier( $supId )->sort( 'relevance' )->search();
265
266
		$this->assertEquals( 2, count( $result ) );
267
		$this->assertEquals( 'CNC', reset( $result )->getCode() );
268
		$this->assertEquals( 'CNE', end( $result )->getCode() );
269
	}
270
271
272
	public function testSupplier()
273
	{
274
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
275
		$supId = $manager->findItem( 'unitCode001' )->getId();
276
277
		$this->assertEquals( 2, count( $this->object->supplier( $supId )->search() ) );
278
	}
279
280
281
	public function testText()
282
	{
283
		$this->assertEquals( 3, count( $this->object->text( 'Cafe' )->search() ) );
284
	}
285
286
287
	public function testUses()
288
	{
289
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
290
	}
291
}
292