1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Order\Manager\Base\Product; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $context; |
16
|
|
|
private $object; |
17
|
|
|
private $editor = ''; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->editor = \TestHelperMShop::getContext()->getEditor(); |
23
|
|
|
$this->context = \TestHelperMShop::getContext(); |
24
|
|
|
$this->object = new \Aimeos\MShop\Order\Manager\Base\Product\Standard( $this->context ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
protected function tearDown() |
29
|
|
|
{ |
30
|
|
|
unset( $this->object ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public function testAggregate() |
35
|
|
|
{ |
36
|
|
|
$search = $this->object->createSearch(); |
37
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.product.editor', 'core:unittest' ) ); |
38
|
|
|
$result = $this->object->aggregate( $search, 'order.base.product.stocktype' ); |
39
|
|
|
|
40
|
|
|
$this->assertEquals( 3, count( $result ) ); |
41
|
|
|
$this->assertArrayHasKey( 'unit_type1', $result ); |
42
|
|
|
$this->assertEquals( 11, $result['unit_type1'] ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
public function testAggregateAvg() |
47
|
|
|
{ |
48
|
|
|
$search = $this->object->createSearch(); |
49
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.product.editor', 'core:unittest' ) ); |
50
|
|
|
$result = $this->object->aggregate( $search, 'order.base.product.type', 'order.base.product.price', 'avg' ); |
51
|
|
|
|
52
|
|
|
$this->assertEquals( 2, count( $result ) ); |
53
|
|
|
$this->assertArrayHasKey( 'default', $result ); |
54
|
|
|
$this->assertEquals( '106.916667', $result['default'] ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function testAggregateSum() |
59
|
|
|
{ |
60
|
|
|
$search = $this->object->createSearch(); |
61
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.product.editor', 'core:unittest' ) ); |
62
|
|
|
$result = $this->object->aggregate( $search, 'order.base.product.type', 'order.base.product.quantity', 'sum' ); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( 2, count( $result ) ); |
65
|
|
|
$this->assertArrayHasKey( 'default', $result ); |
66
|
|
|
$this->assertEquals( 15, $result['default'] ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testCleanup() |
71
|
|
|
{ |
72
|
|
|
$this->object->cleanup( array( -1 ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testGetResourceType() |
77
|
|
|
{ |
78
|
|
|
$result = $this->object->getResourceType(); |
79
|
|
|
|
80
|
|
|
$this->assertContains( 'order/base/product', $result ); |
81
|
|
|
$this->assertContains( 'order/base/product/attribute', $result ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testGetSearchAttributes() |
86
|
|
|
{ |
87
|
|
|
foreach( $this->object->getSearchAttributes( true ) as $attribute ) { |
88
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testCreateItem() |
94
|
|
|
{ |
95
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Order\\Item\\Base\\Product\\Iface', $this->object->createItem() ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function testCreateSearch() |
100
|
|
|
{ |
101
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch( true ) ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function testSearchItem() |
106
|
|
|
{ |
107
|
|
|
$siteid = $this->context->getLocale()->getSiteId(); |
108
|
|
|
|
109
|
|
|
$total = 0; |
110
|
|
|
$search = $this->object->createSearch(); |
111
|
|
|
|
112
|
|
|
$expr = []; |
113
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.id', null ); |
114
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.siteid', $siteid ); |
115
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.baseid', null ); |
116
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.orderproductid', null ); |
117
|
|
|
$expr[] = $search->compare( '>=', 'order.base.product.type', '' ); |
118
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.productid', null ); |
119
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.prodcode', 'CNE' ); |
120
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.suppliercode', 'unitsupplier' ); |
121
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.stocktype', 'unit_type1' ); |
122
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.name', 'Cafe Noire Expresso' ); |
123
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.mediaurl', 'somewhere/thump1.jpg' ); |
124
|
|
|
$expr[] = $search->compare( '>=', 'order.base.product.target', '' ); |
125
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.quantity', 9 ); |
126
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.price', '4.50' ); |
127
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.costs', '0.00' ); |
128
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.rebate', '0.00' ); |
129
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.taxrate', '0.00' ); |
130
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.taxflag', 1 ); |
131
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.taxvalue', '0.00' ); |
132
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.flags', 0 ); |
133
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.position', 1 ); |
134
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.status', 1 ); |
135
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.mtime', '1970-01-01 00:00:00' ); |
136
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.ctime', '1970-01-01 00:00:00' ); |
137
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.editor', $this->editor ); |
138
|
|
|
|
139
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.attribute.id', null ); |
140
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.siteid', $siteid ); |
141
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.attribute.parentid', null ); |
142
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.code', 'width' ); |
143
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.value', '33' ); |
144
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.name', '33' ); |
145
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.attribute.mtime', '1970-01-01 00:00:00' ); |
146
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.attribute.ctime', '1970-01-01 00:00:00' ); |
147
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.editor', $this->editor ); |
148
|
|
|
|
149
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
150
|
|
|
$result = $this->object->searchItems( $search, [], $total ); |
151
|
|
|
|
152
|
|
|
$this->assertEquals( 1, count( $result ) ); |
153
|
|
|
$this->assertEquals( 1, $total ); |
154
|
|
|
|
155
|
|
|
$conditions = array( |
156
|
|
|
$search->compare( '==', 'order.base.product.suppliercode', 'unitsupplier' ), |
157
|
|
|
$search->compare( '==', 'order.base.product.editor', $this->editor ) |
158
|
|
|
); |
159
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
160
|
|
|
$search->setSlice( 0, 2 ); |
161
|
|
|
|
162
|
|
|
$results = $this->object->searchItems( $search, [], $total ); |
163
|
|
|
|
164
|
|
|
$this->assertEquals( 2, count( $results ) ); |
165
|
|
|
$this->assertEquals( 14, $total ); |
166
|
|
|
|
167
|
|
|
foreach( $results as $itemId => $item ) { |
168
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function testGetItem() |
174
|
|
|
{ |
175
|
|
|
$search = $this->object->createSearch(); |
176
|
|
|
$conditions = array( |
177
|
|
|
$search->compare( '==', 'order.base.product.prodcode', 'CNE' ), |
178
|
|
|
$search->compare( '==', 'order.base.product.editor', $this->editor ) |
179
|
|
|
); |
180
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
181
|
|
|
$results = $this->object->searchItems( $search ); |
182
|
|
|
|
183
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
184
|
|
|
throw new \RuntimeException( 'empty result' ); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
$this->assertEquals( $item, $this->object->getItem( $item->getId() ) ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
public function testSaveInvalid() |
192
|
|
|
{ |
193
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Order\Exception' ); |
194
|
|
|
$this->object->saveItem( new \Aimeos\MShop\Locale\Item\Standard() ); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
|
198
|
|
|
public function testSaveUpdateDeleteItem() |
199
|
|
|
{ |
200
|
|
|
$search = $this->object->createSearch(); |
201
|
|
|
$conditions = array( |
202
|
|
|
$search->compare( '==', 'order.base.product.price', '0.00' ), |
203
|
|
|
$search->compare( '==', 'order.base.product.editor', $this->editor ) |
204
|
|
|
); |
205
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
206
|
|
|
$orderItems = $this->object->searchItems( $search ); |
207
|
|
|
|
208
|
|
|
if( !( $item = reset( $orderItems ) ) ) { |
209
|
|
|
throw new \RuntimeException( 'empty search result' ); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
$item->setId( null ); |
213
|
|
|
$item->setPosition( $item->getPosition() + 1 ); |
214
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
215
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
216
|
|
|
|
217
|
|
|
$itemExp = clone $itemSaved; |
218
|
|
|
$itemExp->setProductCode( 'unitUpdCode' ); |
219
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
220
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
221
|
|
|
|
222
|
|
|
$this->object->deleteItem( $itemUpd->getId() ); |
223
|
|
|
|
224
|
|
|
|
225
|
|
|
$this->assertTrue( $item->getId() !== null ); |
226
|
|
|
$this->assertNotEquals( [], $item->getAttributes() ); |
227
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
228
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
229
|
|
|
$this->assertEquals( $item->getBaseId(), $itemSaved->getBaseId() ); |
230
|
|
|
$this->assertEquals( $item->getOrderProductId(), $itemSaved->getOrderProductId() ); |
231
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
232
|
|
|
$this->assertEquals( $item->getProductId(), $itemSaved->getProductId() ); |
233
|
|
|
$this->assertEquals( $item->getProductCode(), $itemSaved->getProductCode() ); |
234
|
|
|
$this->assertEquals( $item->getSupplierCode(), $itemSaved->getSupplierCode() ); |
235
|
|
|
$this->assertEquals( $item->getStockType(), $itemSaved->getStockType() ); |
236
|
|
|
$this->assertEquals( $item->getName(), $itemSaved->getName() ); |
237
|
|
|
$this->assertEquals( $item->getMediaUrl(), $itemSaved->getMediaUrl() ); |
238
|
|
|
$this->assertEquals( $item->getTarget(), $itemSaved->getTarget() ); |
239
|
|
|
$this->assertEquals( $item->getPrice(), $itemSaved->getPrice() ); |
240
|
|
|
$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
241
|
|
|
$this->assertEquals( $item->getQuantity(), $itemSaved->getQuantity() ); |
242
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
243
|
|
|
$this->assertEquals( $item->getFlags(), $itemSaved->getFlags() ); |
244
|
|
|
|
245
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
246
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
247
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
251
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
252
|
|
|
$this->assertEquals( $itemExp->getBaseId(), $itemUpd->getBaseId() ); |
253
|
|
|
$this->assertEquals( $itemExp->getOrderProductId(), $itemUpd->getOrderProductId() ); |
254
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
255
|
|
|
$this->assertEquals( $itemExp->getProductId(), $itemUpd->getProductId() ); |
256
|
|
|
$this->assertEquals( $itemExp->getProductCode(), $itemUpd->getProductCode() ); |
257
|
|
|
$this->assertEquals( $itemExp->getSupplierCode(), $itemUpd->getSupplierCode() ); |
258
|
|
|
$this->assertEquals( $itemExp->getStockType(), $itemUpd->getStockType() ); |
259
|
|
|
$this->assertEquals( $itemExp->getName(), $itemUpd->getName() ); |
260
|
|
|
$this->assertEquals( $itemExp->getMediaUrl(), $itemUpd->getMediaUrl() ); |
261
|
|
|
$this->assertEquals( $itemExp->getTarget(), $itemUpd->getTarget() ); |
262
|
|
|
$this->assertEquals( $itemExp->getPrice(), $itemUpd->getPrice() ); |
263
|
|
|
$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
264
|
|
|
$this->assertEquals( $itemExp->getQuantity(), $itemUpd->getQuantity() ); |
265
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
266
|
|
|
$this->assertEquals( $itemExp->getFlags(), $itemUpd->getFlags() ); |
267
|
|
|
$this->assertEquals( [], $itemUpd->getAttributes() ); |
268
|
|
|
|
269
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
270
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
271
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
272
|
|
|
|
273
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved ); |
274
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd ); |
275
|
|
|
|
276
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
277
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
public function testGetSubManager() |
282
|
|
|
{ |
283
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'attribute' ) ); |
284
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Manager\\Iface', $this->object->getSubManager( 'attribute', 'Standard' ) ); |
285
|
|
|
|
286
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
287
|
|
|
$this->object->getSubManager( 'unknown' ); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
|
291
|
|
|
public function testGetSubManagerInvalidName() |
292
|
|
|
{ |
293
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
294
|
|
|
$this->object->getSubManager( 'attribute', 'unknown' ); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
|
298
|
|
|
public function testGetSubManagerInvalidTypeName() |
299
|
|
|
{ |
300
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
301
|
|
|
$this->object->getSubManager( '$$$' ); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
|
305
|
|
|
public function testGetSubManagerInvalidDefaultName() |
306
|
|
|
{ |
307
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
308
|
|
|
$this->object->getSubManager( 'attribute', '$$$' ); |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
|