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-2020 |
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() : void |
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() : void |
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:lib/mshoplib' ) ); |
38
|
|
|
$result = $this->object->aggregate( $search, 'order.base.product.stocktype' )->toArray(); |
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:lib/mshoplib' ) ); |
50
|
|
|
$result = $this->object->aggregate( $search, 'order.base.product.type', 'order.base.product.price', 'avg' )->toArray(); |
51
|
|
|
|
52
|
|
|
$this->assertEquals( 2, count( $result ) ); |
53
|
|
|
$this->assertArrayHasKey( 'default', $result ); |
54
|
|
|
$this->assertEquals( '253.83', round( $result['default'], 2 ) ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function testAggregateSum() |
59
|
|
|
{ |
60
|
|
|
$search = $this->object->createSearch(); |
61
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.product.editor', 'core:lib/mshoplib' ) ); |
62
|
|
|
$result = $this->object->aggregate( $search, 'order.base.product.type', 'order.base.product.quantity', 'sum' )->toArray(); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( 2, count( $result ) ); |
65
|
|
|
$this->assertArrayHasKey( 'default', $result ); |
66
|
|
|
$this->assertEquals( 25, $result['default'] ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testClear() |
71
|
|
|
{ |
72
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testDeleteItems() |
77
|
|
|
{ |
78
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->deleteItems( [-1] ) ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testGetResourceType() |
83
|
|
|
{ |
84
|
|
|
$result = $this->object->getResourceType(); |
85
|
|
|
|
86
|
|
|
$this->assertContains( 'order/base/product', $result ); |
87
|
|
|
$this->assertContains( 'order/base/product/attribute', $result ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testGetSearchAttributes() |
92
|
|
|
{ |
93
|
|
|
foreach( $this->object->getSearchAttributes( true ) as $attribute ) { |
94
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Attribute\Iface::class, $attribute ); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function testCreateItem() |
100
|
|
|
{ |
101
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Iface::class, $this->object->createItem() ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function testCreateSearch() |
106
|
|
|
{ |
107
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Iface::class, $this->object->createSearch( true ) ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function testCreateSearchSite() |
112
|
|
|
{ |
113
|
|
|
$result = $this->object->createSearch( false, true ); |
114
|
|
|
$this->assertInstanceOf( \Aimeos\MW\Criteria\Expression\Combine\Iface::class, $result->getConditions() ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testSearchItem() |
119
|
|
|
{ |
120
|
|
|
$siteid = $this->context->getLocale()->getSiteId(); |
121
|
|
|
|
122
|
|
|
$total = 0; |
123
|
|
|
$search = $this->object->createSearch(); |
124
|
|
|
|
125
|
|
|
$expr = []; |
126
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.id', null ); |
127
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.siteid', $siteid ); |
128
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.baseid', null ); |
129
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.orderproductid', null ); |
130
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.orderaddressid', null ); |
131
|
|
|
$expr[] = $search->compare( '>=', 'order.base.product.type', '' ); |
132
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.productid', null ); |
133
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.prodcode', 'CNE' ); |
134
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.suppliercode', 'unitsupplier' ); |
135
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.stocktype', 'unit_type1' ); |
136
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.name', 'Cafe Noire Expresso' ); |
137
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.description', '' ); |
138
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.mediaurl', 'somewhere/thump1.jpg' ); |
139
|
|
|
$expr[] = $search->compare( '>=', 'order.base.product.timeframe', '4-5d' ); |
140
|
|
|
$expr[] = $search->compare( '>=', 'order.base.product.target', '' ); |
141
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.quantity', 9 ); |
142
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.price', '4.50' ); |
143
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.costs', '0.00' ); |
144
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.rebate', '0.00' ); |
145
|
|
|
$expr[] = $search->compare( '=~', 'order.base.product.taxrates', '{' ); |
146
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.taxflag', 1 ); |
147
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.taxvalue', '0.00' ); |
148
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.flags', 0 ); |
149
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.position', 1 ); |
150
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.status', 1 ); |
151
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.mtime', '1970-01-01 00:00:00' ); |
152
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.ctime', '1970-01-01 00:00:00' ); |
153
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.editor', $this->editor ); |
154
|
|
|
|
155
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.attribute.id', null ); |
156
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.siteid', $siteid ); |
157
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.attribute.parentid', null ); |
158
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.code', 'width' ); |
159
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.value', '33' ); |
160
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.name', '33' ); |
161
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.quantity', 1 ); |
162
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.attribute.mtime', '1970-01-01 00:00:00' ); |
163
|
|
|
$expr[] = $search->compare( '!=', 'order.base.product.attribute.ctime', '1970-01-01 00:00:00' ); |
164
|
|
|
$expr[] = $search->compare( '==', 'order.base.product.attribute.editor', $this->editor ); |
165
|
|
|
|
166
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
167
|
|
|
$result = $this->object->searchItems( $search, [], $total )->toArray(); |
168
|
|
|
|
169
|
|
|
$this->assertEquals( 1, count( $result ) ); |
170
|
|
|
$this->assertEquals( 1, $total ); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
|
174
|
|
|
public function testSearchItemRef() |
175
|
|
|
{ |
176
|
|
|
$search = $this->object->createSearch()->setSlice( 0, 1 ); |
177
|
|
|
$search->setConditions( $search->compare( '==', 'order.base.product.prodcode', 'CNE' ) ); |
178
|
|
|
$result = $this->object->searchItems( $search, ['product'] ); |
179
|
|
|
|
180
|
|
|
$this->assertEquals( 1, count( $result ) ); |
181
|
|
|
$this->assertNotNull( $result->first()->getProductItem() ); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
|
185
|
|
|
public function testSearchItemTotal() |
186
|
|
|
{ |
187
|
|
|
$total = 0; |
188
|
|
|
$search = $this->object->createSearch(); |
189
|
|
|
|
190
|
|
|
$conditions = array( |
191
|
|
|
$search->compare( '==', 'order.base.product.suppliercode', 'unitsupplier' ), |
192
|
|
|
$search->compare( '==', 'order.base.product.editor', $this->editor ) |
193
|
|
|
); |
194
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
195
|
|
|
$search->setSlice( 0, 2 ); |
196
|
|
|
|
197
|
|
|
$results = $this->object->searchItems( $search, [], $total )->toArray(); |
198
|
|
|
|
199
|
|
|
$this->assertEquals( 2, count( $results ) ); |
200
|
|
|
$this->assertEquals( 14, $total ); |
201
|
|
|
|
202
|
|
|
foreach( $results as $itemId => $item ) { |
203
|
|
|
$this->assertEquals( $itemId, $item->getId() ); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
|
208
|
|
|
public function testGetItem() |
209
|
|
|
{ |
210
|
|
|
$search = $this->object->createSearch()->setSlice( 0, 1 ); |
211
|
|
|
$conditions = array( |
212
|
|
|
$search->compare( '==', 'order.base.product.prodcode', 'CNE' ), |
213
|
|
|
$search->compare( '==', 'order.base.product.editor', $this->editor ) |
214
|
|
|
); |
215
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
216
|
|
|
$results = $this->object->searchItems( $search )->toArray(); |
217
|
|
|
|
218
|
|
|
if( ( $item = reset( $results ) ) === false ) { |
219
|
|
|
throw new \RuntimeException( 'empty result' ); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
$this->assertEquals( $item, $this->object->getItem( $item->getId() ) ); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
|
226
|
|
|
public function testSaveUpdateDeleteItem() |
227
|
|
|
{ |
228
|
|
|
$search = $this->object->createSearch(); |
229
|
|
|
$conditions = array( |
230
|
|
|
$search->compare( '==', 'order.base.product.price', '0.00' ), |
231
|
|
|
$search->compare( '==', 'order.base.product.editor', $this->editor ) |
232
|
|
|
); |
233
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
234
|
|
|
$orderItems = $this->object->searchItems( $search )->toArray(); |
235
|
|
|
|
236
|
|
|
if( !( $item = reset( $orderItems ) ) ) { |
237
|
|
|
throw new \RuntimeException( 'empty search result' ); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
$item->setId( null ); |
241
|
|
|
$item->setPosition( $item->getPosition() + 1 ); |
242
|
|
|
$resultSaved = $this->object->saveItem( $item ); |
243
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
244
|
|
|
|
245
|
|
|
$itemExp = clone $itemSaved; |
246
|
|
|
$itemExp->setProductCode( 'unitUpdCode' ); |
247
|
|
|
$resultUpd = $this->object->saveItem( $itemExp ); |
248
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
249
|
|
|
|
250
|
|
|
$this->object->deleteItem( $itemUpd->getId() ); |
251
|
|
|
|
252
|
|
|
|
253
|
|
|
$this->assertTrue( $item->getId() !== null ); |
254
|
|
|
$this->assertNotEquals( [], $item->getAttributeItems() ); |
255
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
256
|
|
|
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
257
|
|
|
$this->assertEquals( $item->getBaseId(), $itemSaved->getBaseId() ); |
258
|
|
|
$this->assertEquals( $item->getOrderProductId(), $itemSaved->getOrderProductId() ); |
259
|
|
|
$this->assertEquals( $item->getOrderAddressId(), $itemSaved->getOrderAddressId() ); |
260
|
|
|
$this->assertEquals( $item->getType(), $itemSaved->getType() ); |
261
|
|
|
$this->assertEquals( $item->getProductId(), $itemSaved->getProductId() ); |
262
|
|
|
$this->assertEquals( $item->getProductCode(), $itemSaved->getProductCode() ); |
263
|
|
|
$this->assertEquals( $item->getSupplierCode(), $itemSaved->getSupplierCode() ); |
264
|
|
|
$this->assertEquals( $item->getStockType(), $itemSaved->getStockType() ); |
265
|
|
|
$this->assertEquals( $item->getName(), $itemSaved->getName() ); |
266
|
|
|
$this->assertEquals( $item->getDescription(), $itemSaved->getDescription() ); |
267
|
|
|
$this->assertEquals( $item->getMediaUrl(), $itemSaved->getMediaUrl() ); |
268
|
|
|
$this->assertEquals( $item->getTarget(), $itemSaved->getTarget() ); |
269
|
|
|
$this->assertEquals( $item->getPrice()->getValue(), $itemSaved->getPrice()->getValue() ); |
270
|
|
|
$this->assertEquals( $item->getPrice()->getCosts(), $itemSaved->getPrice()->getCosts() ); |
271
|
|
|
$this->assertEquals( $item->getPrice()->getRebate(), $itemSaved->getPrice()->getRebate() ); |
272
|
|
|
$this->assertEquals( $item->getPrice()->getTaxflag(), $itemSaved->getPrice()->getTaxflag() ); |
273
|
|
|
$this->assertEquals( $item->getPrice()->getTaxValue(), $itemSaved->getPrice()->getTaxValue() ); |
274
|
|
|
$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
275
|
|
|
$this->assertEquals( $item->getQuantity(), $itemSaved->getQuantity() ); |
276
|
|
|
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
277
|
|
|
$this->assertEquals( $item->getFlags(), $itemSaved->getFlags() ); |
278
|
|
|
|
279
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
280
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
281
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
282
|
|
|
|
283
|
|
|
|
284
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
285
|
|
|
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
286
|
|
|
$this->assertEquals( $itemExp->getBaseId(), $itemUpd->getBaseId() ); |
287
|
|
|
$this->assertEquals( $itemExp->getOrderProductId(), $itemUpd->getOrderProductId() ); |
288
|
|
|
$this->assertEquals( $itemExp->getOrderAddressId(), $itemUpd->getOrderAddressId() ); |
289
|
|
|
$this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
290
|
|
|
$this->assertEquals( $itemExp->getProductId(), $itemUpd->getProductId() ); |
291
|
|
|
$this->assertEquals( $itemExp->getProductCode(), $itemUpd->getProductCode() ); |
292
|
|
|
$this->assertEquals( $itemExp->getSupplierCode(), $itemUpd->getSupplierCode() ); |
293
|
|
|
$this->assertEquals( $itemExp->getStockType(), $itemUpd->getStockType() ); |
294
|
|
|
$this->assertEquals( $itemExp->getName(), $itemUpd->getName() ); |
295
|
|
|
$this->assertEquals( $itemExp->getDescription(), $itemUpd->getDescription() ); |
296
|
|
|
$this->assertEquals( $itemExp->getMediaUrl(), $itemUpd->getMediaUrl() ); |
297
|
|
|
$this->assertEquals( $itemExp->getTarget(), $itemUpd->getTarget() ); |
298
|
|
|
$this->assertEquals( $itemExp->getPrice()->getValue(), $itemUpd->getPrice()->getValue() ); |
299
|
|
|
$this->assertEquals( $itemExp->getPrice()->getCosts(), $itemUpd->getPrice()->getCosts() ); |
300
|
|
|
$this->assertEquals( $itemExp->getPrice()->getRebate(), $itemUpd->getPrice()->getRebate() ); |
301
|
|
|
$this->assertEquals( $itemExp->getPrice()->getTaxflag(), $itemUpd->getPrice()->getTaxflag() ); |
302
|
|
|
$this->assertEquals( $itemExp->getPrice()->getTaxValue(), $itemUpd->getPrice()->getTaxValue() ); |
303
|
|
|
$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
304
|
|
|
$this->assertEquals( $itemExp->getQuantity(), $itemUpd->getQuantity() ); |
305
|
|
|
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
306
|
|
|
$this->assertEquals( $itemExp->getFlags(), $itemUpd->getFlags() ); |
307
|
|
|
$this->assertEquals( [], $itemUpd->getAttributeItems()->toArray() ); |
308
|
|
|
|
309
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
310
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
311
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
312
|
|
|
|
313
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
314
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
315
|
|
|
|
316
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
317
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
|
321
|
|
|
public function testGetSubManager() |
322
|
|
|
{ |
323
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'attribute' ) ); |
324
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'attribute', 'Standard' ) ); |
325
|
|
|
|
326
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
327
|
|
|
$this->object->getSubManager( 'unknown' ); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
|
331
|
|
|
public function testGetSubManagerInvalidName() |
332
|
|
|
{ |
333
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
334
|
|
|
$this->object->getSubManager( 'attribute', 'unknown' ); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
|
338
|
|
|
public function testGetSubManagerInvalidTypeName() |
339
|
|
|
{ |
340
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
341
|
|
|
$this->object->getSubManager( '$$$' ); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
|
345
|
|
|
public function testGetSubManagerInvalidDefaultName() |
346
|
|
|
{ |
347
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
348
|
|
|
$this->object->getSubManager( 'attribute', '$$$' ); |
349
|
|
|
} |
350
|
|
|
} |
351
|
|
|
|