Completed
Push — master ( 75d10e...433dcb )
by Aimeos
01:39
created

StandardTest::testGetItems()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 3
nc 4
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();
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 testParse()
102
	{
103
		$cond = ['&&' => [['>' => ['product.status' => 0]], ['==' => ['product.type' => 'default']]]];
104
		$this->assertEquals( 4, count( $this->object->parse( $cond )->search() ) );
105
	}
106
107
108
	public function testProduct()
109
	{
110
		$manager = \Aimeos\MShop::create( $this->context, 'product' );
111
112
		$cncId = $manager->findItem( 'CNC' )->getId();
113
		$cneId = $manager->findItem( 'CNE' )->getId();
114
115
		$this->assertEquals( 2, count( $this->object->product( [$cncId, $cneId] )->search() ) );
116
	}
117
118
119
	public function testSearch()
120
	{
121
		$this->assertEquals( 8, count( $this->object->search() ) );
122
	}
123
124
125
	public function testSlice()
126
	{
127
		$this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) );
128
	}
129
130
131
	public function testSort()
132
	{
133
		$this->assertEquals( 8, count( $this->object->sort( 'relevance' )->search() ) );
134
	}
135
136
137
	public function testSortCode()
138
	{
139
		$result = $this->object->sort( 'code' )->search( [] );
140
		$this->assertEquals( 'CNC', reset( $result )->getCode() );
141
	}
142
143
144
	public function testSortCodeDesc()
145
	{
146
		$result = $this->object->sort( '-code' )->search( [] );
147
		$this->assertEquals( 'U:noSel', reset( $result )->getCode() );
148
	}
149
150
151
	public function testSortCtime()
152
	{
153
		$this->assertEquals( 8, count( $this->object->sort( 'ctime' )->search( [] ) ) );
154
	}
155
156
157
	public function testSortCtimeDesc()
158
	{
159
		$this->assertEquals( 8, count( $this->object->sort( '-ctime' )->search( [] ) ) );
160
	}
161
162
163
	public function testSortName()
164
	{
165
		$result = $this->object->sort( 'name' )->search( ['text'] );
166
		$this->assertEquals( 'Cafe Noire Cappuccino', reset( $result )->getName() );
167
	}
168
169
170
	public function testSortNameDesc()
171
	{
172
		$result = $this->object->sort( '-name' )->search( ['text'] );
173
		$this->assertEquals( 'Unterproduct 3', reset( $result )->getName() );
174
	}
175
176
177
	public function testSortPrice()
178
	{
179
		$result = $this->object->sort( 'price' )->search( [] );
180
		$this->assertEquals( 'IJKL', reset( $result )->getCode() );
181
	}
182
183
184
	public function testSortPriceDesc()
185
	{
186
		$result = $this->object->sort( '-price' )->search( [] );
187
		$this->assertTrue( in_array( reset( $result )->getCode(), ['CNC', 'U:BUNDLE'] ) );
188
	}
189
190
191
	public function testSortRelevanceCategory()
192
	{
193
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
194
		$catId = $manager->findItem( 'new' )->getId();
195
196
		$result = $this->object->category( $catId )->sort( 'relevance' )->search( [] );
197
198
		$this->assertEquals( 3, count( $result ) );
199
		$this->assertEquals( 'CNE', reset( $result )->getCode() );
200
		$this->assertEquals( 'U:BUNDLE', end( $result )->getCode() );
201
	}
202
203
204
	public function testSortRelevanceSupplier()
205
	{
206
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
207
		$supId = $manager->findItem( 'unitCode001' )->getId();
208
209
		$result = $this->object->supplier( $supId )->sort( 'relevance' )->search( [] );
210
211
		$this->assertEquals( 2, count( $result ) );
212
		$this->assertEquals( 'CNC', reset( $result )->getCode() );
213
		$this->assertEquals( 'CNE', end( $result )->getCode() );
214
	}
215
216
217
	public function testSupplier()
218
	{
219
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
220
		$supId = $manager->findItem( 'unitCode001' )->getId();
221
222
		$this->assertEquals( 2, count( $this->object->supplier( $supId )->search( [] ) ) );
223
	}
224
225
226
	public function testText()
227
	{
228
		$this->assertEquals( 3, count( $this->object->text( 'Cafe' )->search( [] ) ) );
229
	}
230
}
231