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