Passed
Push — master ( c9dfc7...a4ce90 )
by Aimeos
01:38
created

StandardTest::testUses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
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 testSearch()
151
	{
152
		$total = 0;
153
		$items = $this->object->uses( ['price'] )->sort( 'code' )->search( $total );
154
155
		$this->assertEquals( 8, count( $items ) );
156
		$this->assertEquals( 8, $total );
157
		$this->assertEquals( 2, count( current( $items )->getRefItems( 'price' ) ) );
158
	}
159
160
161
	public function testSlice()
162
	{
163
		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) );
164
	}
165
166
167
	public function testSort()
168
	{
169
		$this->assertEquals( 8, count( $this->object->sort( 'relevance' )->search() ) );
170
	}
171
172
173
	public function testSortGeneric()
174
	{
175
		$this->assertEquals( 8, count( $this->object->sort( 'product.status' )->search() ) );
176
	}
177
178
179
	public function testSortCode()
180
	{
181
		$result = $this->object->sort( 'code' )->search();
182
		$this->assertEquals( 'CNC', reset( $result )->getCode() );
183
	}
184
185
186
	public function testSortCodeDesc()
187
	{
188
		$result = $this->object->sort( '-code' )->search();
189
		$this->assertStringStartsWith( 'U:', reset( $result )->getCode() );
190
	}
191
192
193
	public function testSortCtime()
194
	{
195
		$this->assertEquals( 8, count( $this->object->sort( 'ctime' )->search() ) );
196
	}
197
198
199
	public function testSortCtimeDesc()
200
	{
201
		$this->assertEquals( 8, count( $this->object->sort( '-ctime' )->search() ) );
202
	}
203
204
205
	public function testSortName()
206
	{
207
		$result = $this->object->uses( ['text'] )->sort( 'name' )->search();
208
		$this->assertEquals( 'Cafe Noire Cappuccino', reset( $result )->getName() );
209
	}
210
211
212
	public function testSortNameDesc()
213
	{
214
		$result = $this->object->uses( ['text'] )->sort( '-name' )->search();
215
		$this->assertEquals( 'Unterproduct 3', reset( $result )->getName() );
216
	}
217
218
219
	public function testSortPrice()
220
	{
221
		$result = $this->object->uses( ['price'] )->sort( 'price' )->search();
222
		$prices = reset( $result )->getRefItems( 'price', 'default', 'default' );
223
224
		$this->assertEquals( '12.00', reset( $prices )->getValue() );
225
	}
226
227
228
	public function testSortPriceDesc()
229
	{
230
		$result = $this->object->uses( ['price'] )->sort( '-price' )->search();
231
		$prices = reset( $result )->getRefItems( 'price', 'default', 'default' );
232
233
		$this->assertEquals( '600.00', reset( $prices )->getValue() );
234
	}
235
236
237
	public function testSortRelevanceCategory()
238
	{
239
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
240
		$catId = $manager->findItem( 'new' )->getId();
241
242
		$result = $this->object->category( $catId )->sort( 'relevance' )->search();
243
244
		$this->assertEquals( 3, count( $result ) );
245
		$this->assertEquals( 'CNE', reset( $result )->getCode() );
246
		$this->assertEquals( 'U:BUNDLE', end( $result )->getCode() );
247
	}
248
249
250
	public function testSortRelevanceSupplier()
251
	{
252
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
253
		$supId = $manager->findItem( 'unitCode001' )->getId();
254
255
		$result = $this->object->supplier( $supId )->sort( 'relevance' )->search();
256
257
		$this->assertEquals( 2, count( $result ) );
258
		$this->assertEquals( 'CNC', reset( $result )->getCode() );
259
		$this->assertEquals( 'CNE', end( $result )->getCode() );
260
	}
261
262
263
	public function testSupplier()
264
	{
265
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
266
		$supId = $manager->findItem( 'unitCode001' )->getId();
267
268
		$this->assertEquals( 2, count( $this->object->supplier( $supId )->search() ) );
269
	}
270
271
272
	public function testText()
273
	{
274
		$this->assertEquals( 3, count( $this->object->text( 'Cafe' )->search() ) );
275
	}
276
277
278
	public function testUses()
279
	{
280
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
281
	}
282
}
283