Completed
Push — master ( 76cfc1...e87582 )
by Aimeos
01:44
created

StandardTest   A

Complexity

Total Complexity 28

Size/Duplication

Total Lines 230
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 28
lcom 1
cbo 3
dl 0
loc 230
rs 10
c 0
b 0
f 0

28 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
A setUp() 0 5 1
A testAggregate() 0 6 1
A testAllOf() 0 9 1
A testCategory() 0 7 1
A testCategoryTree() 0 10 1
A testCompare() 0 4 1
A testGet() 0 6 1
A testFind() 0 4 1
A testOneOf() 0 9 1
A testOneOfList() 0 9 1
A testParse() 0 5 1
A testProduct() 0 9 1
A testSearch() 0 4 1
A testSlice() 0 4 1
A testSort() 0 4 1
A testSortCode() 0 5 1
A testSortCodeDesc() 0 5 1
A testSortCtime() 0 4 1
A testSortCtimeDesc() 0 4 1
A testSortName() 0 5 1
A testSortNameDesc() 0 5 1
A testSortPrice() 0 5 1
A testSortPriceDesc() 0 5 1
A testSortRelevanceCategory() 0 11 1
A testSortRelevanceSupplier() 0 11 1
A testSupplier() 0 7 1
A testText() 0 4 1
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();
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 testGet()
77
	{
78
		$item = \Aimeos\MShop::create( $this->context, 'product' )->findItem( 'CNC' );
79
80
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $this->object->get( $item->getId() ) );
81
	}
82
83
84
	public function testFind()
85
	{
86
		$this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $this->object->find( 'CNC' ) );
87
	}
88
89
90
	public function testOneOf()
91
	{
92
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
93
94
		$length = $manager->findItem( '30', [], 'product', 'length' )->getId();
95
		$width = $manager->findItem( '29', [], 'product', 'width' )->getId();
96
97
		$this->assertEquals( 4, count( $this->object->oneOf( [$length, $width] )->search() ) );
98
	}
99
100
101
	public function testOneOfList()
102
	{
103
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
104
105
		$length = $manager->findItem( '30', [], 'product', 'length' )->getId();
106
		$width = $manager->findItem( '29', [], 'product', 'width' )->getId();
107
108
		$this->assertEquals( 4, count( $this->object->oneOf( [[$length, $width]] )->search() ) );
109
	}
110
111
112
	public function testParse()
113
	{
114
		$cond = ['&&' => [['>' => ['product.status' => 0]], ['==' => ['product.type' => 'default']]]];
115
		$this->assertEquals( 4, count( $this->object->parse( $cond )->search() ) );
116
	}
117
118
119
	public function testProduct()
120
	{
121
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
122
123
		$cncId = $manager->findItem( 'CNC' )->getId();
124
		$cneId = $manager->findItem( 'CNE' )->getId();
125
126
		$this->assertEquals( 2, count( $this->object->product( [$cncId, $cneId] )->search() ) );
127
	}
128
129
130
	public function testSearch()
131
	{
132
		$this->assertEquals( 8, count( $this->object->search() ) );
133
	}
134
135
136
	public function testSlice()
137
	{
138
		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) );
139
	}
140
141
142
	public function testSort()
143
	{
144
		$this->assertEquals( 8, count( $this->object->sort( 'relevance' )->search() ) );
145
	}
146
147
148
	public function testSortCode()
149
	{
150
		$result = $this->object->sort( 'code' )->search( [] );
151
		$this->assertEquals( 'CNC', reset( $result )->getCode() );
152
	}
153
154
155
	public function testSortCodeDesc()
156
	{
157
		$result = $this->object->sort( '-code' )->search( [] );
158
		$this->assertStringStartsWith( 'U:', reset( $result )->getCode() );
159
	}
160
161
162
	public function testSortCtime()
163
	{
164
		$this->assertEquals( 8, count( $this->object->sort( 'ctime' )->search( [] ) ) );
165
	}
166
167
168
	public function testSortCtimeDesc()
169
	{
170
		$this->assertEquals( 8, count( $this->object->sort( '-ctime' )->search( [] ) ) );
171
	}
172
173
174
	public function testSortName()
175
	{
176
		$result = $this->object->sort( 'name' )->search( ['text'] );
177
		$this->assertEquals( 'Cafe Noire Cappuccino', reset( $result )->getName() );
178
	}
179
180
181
	public function testSortNameDesc()
182
	{
183
		$result = $this->object->sort( '-name' )->search( ['text'] );
184
		$this->assertEquals( 'Unterproduct 3', reset( $result )->getName() );
185
	}
186
187
188
	public function testSortPrice()
189
	{
190
		$result = $this->object->sort( 'price' )->search( [] );
191
		$this->assertEquals( 'IJKL', reset( $result )->getCode() );
192
	}
193
194
195
	public function testSortPriceDesc()
196
	{
197
		$result = $this->object->sort( '-price' )->search( [] );
198
		$this->assertTrue( in_array( reset( $result )->getCode(), ['CNC', 'U:BUNDLE'] ) );
199
	}
200
201
202
	public function testSortRelevanceCategory()
203
	{
204
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
205
		$catId = $manager->findItem( 'new' )->getId();
206
207
		$result = $this->object->category( $catId )->sort( 'relevance' )->search( [] );
208
209
		$this->assertEquals( 3, count( $result ) );
210
		$this->assertEquals( 'CNE', reset( $result )->getCode() );
211
		$this->assertEquals( 'U:BUNDLE', end( $result )->getCode() );
212
	}
213
214
215
	public function testSortRelevanceSupplier()
216
	{
217
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
218
		$supId = $manager->findItem( 'unitCode001' )->getId();
219
220
		$result = $this->object->supplier( $supId )->sort( 'relevance' )->search( [] );
221
222
		$this->assertEquals( 2, count( $result ) );
223
		$this->assertEquals( 'CNC', reset( $result )->getCode() );
224
		$this->assertEquals( 'CNE', end( $result )->getCode() );
225
	}
226
227
228
	public function testSupplier()
229
	{
230
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
231
		$supId = $manager->findItem( 'unitCode001' )->getId();
232
233
		$this->assertEquals( 2, count( $this->object->supplier( $supId )->search( [] ) ) );
234
	}
235
236
237
	public function testText()
238
	{
239
		$this->assertEquals( 3, count( $this->object->text( 'Cafe' )->search( [] ) ) );
240
	}
241
}
242