Total Complexity | 61 |
Total Lines | 828 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Complex classes like StandardTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use StandardTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class StandardTest extends \PHPUnit\Framework\TestCase |
||
14 | { |
||
15 | private $object; |
||
16 | private $context; |
||
17 | private $editor = ''; |
||
18 | |||
19 | |||
20 | protected function setUp() : void |
||
21 | { |
||
22 | $this->context = \TestHelper::context(); |
||
23 | $this->editor = $this->context->editor(); |
||
24 | |||
25 | $this->object = new \Aimeos\MShop\Order\Manager\Base\Standard( $this->context ); |
||
26 | } |
||
27 | |||
28 | |||
29 | protected function tearDown() : void |
||
30 | { |
||
31 | unset( $this->object ); |
||
32 | } |
||
33 | |||
34 | |||
35 | public function testAggregate() |
||
44 | } |
||
45 | |||
46 | |||
47 | public function testAggregateAvg() |
||
48 | { |
||
49 | $search = $this->object->filter()->add( ['order.base.editor' => 'core', 'order.base.address.type' => 'payment'] ); |
||
50 | $result = $this->object->aggregate( $search, 'order.base.address.email', 'order.base.price', 'avg' )->toArray(); |
||
51 | |||
52 | $this->assertEquals( 1, count( $result ) ); |
||
53 | $this->assertArrayHasKey( '[email protected]', $result ); |
||
54 | $this->assertEquals( '784.75', round( $result['[email protected]'], 2 ) ); |
||
55 | } |
||
56 | |||
57 | |||
58 | public function testAggregateSum() |
||
59 | { |
||
60 | $search = $this->object->filter()->add( ['order.base.editor' => 'core', 'order.base.address.type' => 'payment'] ); |
||
61 | $result = $this->object->aggregate( $search, 'order.base.address.email', 'order.base.price', 'sum' )->toArray(); |
||
62 | |||
63 | $this->assertEquals( 1, count( $result ) ); |
||
64 | $this->assertArrayHasKey( '[email protected]', $result ); |
||
65 | $this->assertEquals( '3139.00', $result['[email protected]'] ); |
||
66 | } |
||
67 | |||
68 | |||
69 | public function testClear() |
||
70 | { |
||
71 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->clear( [-1] ) ); |
||
72 | } |
||
73 | |||
74 | |||
75 | public function testDeleteItems() |
||
78 | } |
||
79 | |||
80 | |||
81 | public function testGetResourceType() |
||
82 | { |
||
83 | $result = $this->object->getResourceType(); |
||
84 | |||
85 | $this->assertContains( 'order/base', $result ); |
||
86 | $this->assertContains( 'order/base/address', $result ); |
||
87 | $this->assertContains( 'order/base/coupon', $result ); |
||
88 | $this->assertContains( 'order/base/product', $result ); |
||
89 | $this->assertContains( 'order/base/product/attribute', $result ); |
||
90 | $this->assertContains( 'order/base/service', $result ); |
||
91 | $this->assertContains( 'order/base/service/attribute', $result ); |
||
92 | } |
||
93 | |||
94 | |||
95 | public function testCreateItem() |
||
96 | { |
||
97 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $this->object->create() ); |
||
98 | } |
||
99 | |||
100 | |||
101 | public function testGetItem() |
||
117 | } |
||
118 | |||
119 | |||
120 | public function testSaveUpdateDeleteItem() |
||
121 | { |
||
122 | $orderProductManager = \Aimeos\MShop::create( $this->context, 'order/base/product' ); |
||
|
|||
123 | $search = $this->object->filter()->add( ['order.base.costs' => '1.50', 'order.base.editor' => $this->editor] ); |
||
124 | $item = $this->object->search( $search, ['order/base/product'] ) |
||
125 | ->first( new \RuntimeException( 'No order base item found' ) ); |
||
126 | |||
127 | |||
128 | $item->setId( null )->setComment( 'Unittest1' ); |
||
129 | $resultSaved = $this->object->save( $item ); |
||
130 | |||
131 | $itemSaved = $this->object->get( $item->getId() ); |
||
132 | $itemPrice = $item->getPrice(); |
||
133 | $itemSavedPrice = $item->getPrice(); |
||
134 | |||
135 | |||
136 | $itemExp = clone $itemSaved; |
||
137 | $itemExp->setComment( 'Unittest2' ); |
||
138 | $itemExp->setCustomerId( 'unittest1' ); |
||
139 | $resultUpd = $this->object->save( $itemExp ); |
||
140 | $itemUpd = $this->object->get( $itemExp->getId() ); |
||
141 | $itemExpPrice = $itemExp->getPrice(); |
||
142 | $itemUpdPrice = $itemUpd->getPrice(); |
||
143 | |||
144 | |||
145 | $this->object->delete( $itemSaved->getId() ); |
||
146 | |||
147 | |||
148 | $this->assertTrue( $item->getId() !== null ); |
||
149 | $this->assertEquals( $item->getId(), $itemSaved->getId() ); |
||
150 | $this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
||
151 | $this->assertEquals( $item->getCustomerId(), $itemSaved->getCustomerId() ); |
||
152 | $this->assertEquals( $item->locale()->getLanguageId(), $itemSaved->locale()->getLanguageId() ); |
||
153 | $this->assertEquals( $item->getCustomerReference(), $itemSaved->getCustomerReference() ); |
||
154 | $this->assertEquals( $item->getComment(), $itemSaved->getComment() ); |
||
155 | $this->assertEquals( $item->getSiteCode(), $itemSaved->getSiteCode() ); |
||
156 | $this->assertEquals( $itemPrice->getValue(), $itemSavedPrice->getValue() ); |
||
157 | $this->assertEquals( $itemPrice->getCosts(), $itemSavedPrice->getCosts() ); |
||
158 | $this->assertEquals( $itemPrice->getRebate(), $itemSavedPrice->getRebate() ); |
||
159 | $this->assertEquals( $itemPrice->getTaxValue(), $itemSavedPrice->getTaxValue() ); |
||
160 | $this->assertEquals( $itemPrice->getCurrencyId(), $itemSavedPrice->getCurrencyId() ); |
||
161 | |||
162 | $this->assertEquals( $this->editor, $itemSaved->editor() ); |
||
163 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
||
164 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
||
165 | |||
166 | $this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
||
167 | $this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
||
168 | $this->assertEquals( $itemExp->getCustomerId(), $itemUpd->getCustomerId() ); |
||
169 | $this->assertEquals( $itemExp->locale()->getLanguageId(), $itemUpd->locale()->getLanguageId() ); |
||
170 | $this->assertEquals( $itemExp->getCustomerReference(), $itemUpd->getCustomerReference() ); |
||
171 | $this->assertEquals( $itemExp->getComment(), $itemUpd->getComment() ); |
||
172 | $this->assertEquals( $itemExp->getSiteCode(), $itemUpd->getSiteCode() ); |
||
173 | $this->assertEquals( $itemExpPrice->getValue(), $itemUpdPrice->getValue() ); |
||
174 | $this->assertEquals( $itemExpPrice->getCosts(), $itemUpdPrice->getCosts() ); |
||
175 | $this->assertEquals( $itemExpPrice->getRebate(), $itemUpdPrice->getRebate() ); |
||
176 | $this->assertEquals( $itemExpPrice->getTaxValue(), $itemUpdPrice->getTaxValue() ); |
||
177 | $this->assertEquals( $itemExpPrice->getCurrencyId(), $itemUpdPrice->getCurrencyId() ); |
||
178 | |||
179 | $this->assertEquals( $this->editor, $itemUpd->editor() ); |
||
180 | $this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
||
181 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
||
182 | |||
183 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
||
184 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
||
185 | |||
186 | $this->expectException( \Aimeos\MShop\Exception::class ); |
||
187 | $this->object->get( $itemSaved->getId() ); |
||
188 | } |
||
189 | |||
190 | |||
191 | public function testCreateSearch() |
||
192 | { |
||
193 | $this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $this->object->filter() ); |
||
194 | } |
||
195 | |||
196 | |||
197 | public function testCreateSearchDefault() |
||
198 | { |
||
199 | $search = $this->object->filter( true ); |
||
200 | |||
201 | $this->assertInstanceOf( \Aimeos\Base\Criteria\Iface::class, $search ); |
||
202 | $this->assertInstanceOf( \Aimeos\Base\Criteria\Expression\Combine\Iface::class, $search->getConditions() ); |
||
203 | |||
204 | $list = $search->getConditions()->getExpressions(); |
||
205 | $this->assertArrayHasKey( 0, $list ); |
||
206 | $this->assertInstanceOf( \Aimeos\Base\Criteria\Expression\Combine\Iface::class, $list[0] ); |
||
207 | } |
||
208 | |||
209 | |||
210 | public function testCreateSearchSite() |
||
214 | } |
||
215 | |||
216 | |||
217 | public function testSearchItems() |
||
218 | { |
||
219 | $siteid = $this->context->locale()->getSiteId(); |
||
220 | |||
221 | $total = 0; |
||
222 | $search = $this->object->filter(); |
||
223 | |||
224 | $expr = []; |
||
225 | $expr[] = $search->compare( '!=', 'order.base.id', null ); |
||
226 | $expr[] = $search->compare( '==', 'order.base.siteid', $siteid ); |
||
227 | $expr[] = $search->compare( '==', 'order.base.sitecode', 'unittest' ); |
||
228 | $expr[] = $search->compare( '>=', 'order.base.customerid', '' ); |
||
229 | $expr[] = $search->compare( '==', 'order.base.languageid', 'de' ); |
||
230 | $expr[] = $search->compare( '==', 'order.base.currencyid', 'EUR' ); |
||
231 | $expr[] = $search->compare( '==', 'order.base.price', '53.50' ); |
||
232 | $expr[] = $search->compare( '==', 'order.base.costs', '1.50' ); |
||
233 | $expr[] = $search->compare( '==', 'order.base.rebate', '14.50' ); |
||
234 | $expr[] = $search->compare( '==', 'order.base.taxvalue', '0.0000' ); |
||
235 | $expr[] = $search->compare( '~=', 'order.base.customerref', 'ABC-1234' ); |
||
236 | $expr[] = $search->compare( '~=', 'order.base.comment', 'This is a comment' ); |
||
237 | $expr[] = $search->compare( '>=', 'order.base.mtime', '1970-01-01 00:00:00' ); |
||
238 | $expr[] = $search->compare( '>=', 'order.base.ctime', '1970-01-01 00:00:00' ); |
||
239 | $expr[] = $search->compare( '==', 'order.base.editor', $this->editor ); |
||
240 | |||
241 | $expr[] = $search->compare( '!=', 'order.base.address.id', null ); |
||
242 | $expr[] = $search->compare( '==', 'order.base.address.siteid', $siteid ); |
||
243 | $expr[] = $search->compare( '!=', 'order.base.address.baseid', null ); |
||
244 | $expr[] = $search->compare( '==', 'order.base.address.type', 'payment' ); |
||
245 | $expr[] = $search->compare( '==', 'order.base.address.company', 'Example company' ); |
||
246 | $expr[] = $search->compare( '==', 'order.base.address.vatid', 'DE999999999' ); |
||
247 | $expr[] = $search->compare( '==', 'order.base.address.salutation', 'mr' ); |
||
248 | $expr[] = $search->compare( '==', 'order.base.address.title', '' ); |
||
249 | $expr[] = $search->compare( '==', 'order.base.address.firstname', 'Our' ); |
||
250 | $expr[] = $search->compare( '==', 'order.base.address.lastname', 'Unittest' ); |
||
251 | $expr[] = $search->compare( '==', 'order.base.address.address1', 'Durchschnitt' ); |
||
252 | $expr[] = $search->compare( '==', 'order.base.address.address2', '1' ); |
||
253 | $expr[] = $search->compare( '==', 'order.base.address.address3', '' ); |
||
254 | $expr[] = $search->compare( '==', 'order.base.address.postal', '20146' ); |
||
255 | $expr[] = $search->compare( '==', 'order.base.address.city', 'Hamburg' ); |
||
256 | $expr[] = $search->compare( '==', 'order.base.address.state', 'Hamburg' ); |
||
257 | $expr[] = $search->compare( '==', 'order.base.address.countryid', 'DE' ); |
||
258 | $expr[] = $search->compare( '==', 'order.base.address.languageid', 'de' ); |
||
259 | $expr[] = $search->compare( '==', 'order.base.address.telephone', '055544332211' ); |
||
260 | $expr[] = $search->compare( '==', 'order.base.address.email', '[email protected]' ); |
||
261 | $expr[] = $search->compare( '==', 'order.base.address.telefax', '055544332213' ); |
||
262 | $expr[] = $search->compare( '==', 'order.base.address.website', 'www.example.net' ); |
||
263 | $expr[] = $search->compare( '>=', 'order.base.address.mtime', '1970-01-01 00:00:00' ); |
||
264 | $expr[] = $search->compare( '>=', 'order.base.address.ctime', '1970-01-01 00:00:00' ); |
||
265 | $expr[] = $search->compare( '==', 'order.base.address.editor', $this->editor ); |
||
266 | |||
267 | $expr[] = $search->compare( '!=', 'order.base.coupon.id', null ); |
||
268 | $expr[] = $search->compare( '==', 'order.base.coupon.siteid', $siteid ); |
||
269 | $expr[] = $search->compare( '!=', 'order.base.coupon.baseid', null ); |
||
270 | $expr[] = $search->compare( '!=', 'order.base.coupon.productid', null ); |
||
271 | $expr[] = $search->compare( '==', 'order.base.coupon.code', 'OPQR' ); |
||
272 | $expr[] = $search->compare( '>=', 'order.base.coupon.mtime', '1970-01-01 00:00:00' ); |
||
273 | $expr[] = $search->compare( '>=', 'order.base.coupon.ctime', '1970-01-01 00:00:00' ); |
||
274 | $expr[] = $search->compare( '>=', 'order.base.coupon.editor', '' ); |
||
275 | |||
276 | $expr[] = $search->compare( '!=', 'order.base.product.id', null ); |
||
277 | $expr[] = $search->compare( '==', 'order.base.product.siteid', $siteid ); |
||
278 | $expr[] = $search->compare( '!=', 'order.base.product.baseid', null ); |
||
279 | $expr[] = $search->compare( '==', 'order.base.product.orderproductid', null ); |
||
280 | $expr[] = $search->compare( '>=', 'order.base.product.type', '' ); |
||
281 | $expr[] = $search->compare( '!=', 'order.base.product.productid', null ); |
||
282 | $expr[] = $search->compare( '==', 'order.base.product.prodcode', 'CNE' ); |
||
283 | $expr[] = $search->compare( '==', 'order.base.product.vendor', 'Test vendor' ); |
||
284 | $expr[] = $search->compare( '==', 'order.base.product.name', 'Cafe Noire Expresso' ); |
||
285 | $expr[] = $search->compare( '==', 'order.base.product.mediaurl', 'somewhere/thump1.jpg' ); |
||
286 | $expr[] = $search->compare( '==', 'order.base.product.quantity', 9 ); |
||
287 | $expr[] = $search->compare( '==', 'order.base.product.price', '4.50' ); |
||
288 | $expr[] = $search->compare( '==', 'order.base.product.costs', '0.00' ); |
||
289 | $expr[] = $search->compare( '==', 'order.base.product.rebate', '0.00' ); |
||
290 | $expr[] = $search->compare( '=~', 'order.base.product.taxrates', '{' ); |
||
291 | $expr[] = $search->compare( '==', 'order.base.product.taxvalue', '0.0000' ); |
||
292 | $expr[] = $search->compare( '==', 'order.base.product.flags', 0 ); |
||
293 | $expr[] = $search->compare( '==', 'order.base.product.position', 1 ); |
||
294 | $expr[] = $search->compare( '==', 'order.base.product.statuspayment', 5 ); |
||
295 | $expr[] = $search->compare( '==', 'order.base.product.statusdelivery', 1 ); |
||
296 | $expr[] = $search->compare( '>=', 'order.base.product.mtime', '1970-01-01 00:00:00' ); |
||
297 | $expr[] = $search->compare( '>=', 'order.base.product.ctime', '1970-01-01 00:00:00' ); |
||
298 | $expr[] = $search->compare( '==', 'order.base.product.editor', $this->editor ); |
||
299 | |||
300 | $expr[] = $search->compare( '!=', 'order.base.product.attribute.id', null ); |
||
301 | $expr[] = $search->compare( '==', 'order.base.product.attribute.siteid', $siteid ); |
||
302 | $expr[] = $search->compare( '!=', 'order.base.product.attribute.parentid', null ); |
||
303 | $expr[] = $search->compare( '==', 'order.base.product.attribute.code', 'width' ); |
||
304 | $expr[] = $search->compare( '==', 'order.base.product.attribute.value', '33' ); |
||
305 | $expr[] = $search->compare( '==', 'order.base.product.attribute.name', '33' ); |
||
306 | $expr[] = $search->compare( '==', 'order.base.product.attribute.quantity', 1 ); |
||
307 | $expr[] = $search->compare( '>=', 'order.base.product.attribute.mtime', '1970-01-01 00:00:00' ); |
||
308 | $expr[] = $search->compare( '>=', 'order.base.product.attribute.ctime', '1970-01-01 00:00:00' ); |
||
309 | $expr[] = $search->compare( '==', 'order.base.product.attribute.editor', $this->editor ); |
||
310 | |||
311 | $expr[] = $search->compare( '!=', 'order.base.service.id', null ); |
||
312 | $expr[] = $search->compare( '==', 'order.base.service.siteid', $siteid ); |
||
313 | $expr[] = $search->compare( '!=', 'order.base.service.baseid', null ); |
||
314 | $expr[] = $search->compare( '==', 'order.base.service.type', 'payment' ); |
||
315 | $expr[] = $search->compare( '!=', 'order.base.service.serviceid', null ); |
||
316 | $expr[] = $search->compare( '==', 'order.base.service.code', 'unitpaymentcode' ); |
||
317 | $expr[] = $search->compare( '==', 'order.base.service.name', 'unitpaymentcode' ); |
||
318 | $expr[] = $search->compare( '==', 'order.base.service.price', '0.00' ); |
||
319 | $expr[] = $search->compare( '==', 'order.base.service.costs', '0.00' ); |
||
320 | $expr[] = $search->compare( '==', 'order.base.service.rebate', '0.00' ); |
||
321 | $expr[] = $search->compare( '=~', 'order.base.service.taxrates', '{' ); |
||
322 | $expr[] = $search->compare( '==', 'order.base.service.taxvalue', '0.0000' ); |
||
323 | $expr[] = $search->compare( '>=', 'order.base.service.mtime', '1970-01-01 00:00:00' ); |
||
324 | $expr[] = $search->compare( '>=', 'order.base.service.ctime', '1970-01-01 00:00:00' ); |
||
325 | $expr[] = $search->compare( '==', 'order.base.service.editor', $this->editor ); |
||
326 | |||
327 | $expr[] = $search->compare( '!=', 'order.base.service.attribute.id', null ); |
||
328 | $expr[] = $search->compare( '==', 'order.base.service.attribute.siteid', $siteid ); |
||
329 | $expr[] = $search->compare( '!=', 'order.base.service.attribute.parentid', null ); |
||
330 | $expr[] = $search->compare( '==', 'order.base.service.attribute.code', 'NAME' ); |
||
331 | $expr[] = $search->compare( '==', 'order.base.service.attribute.value', '"CreditCard"' ); |
||
332 | $expr[] = $search->compare( '==', 'order.base.service.attribute.quantity', 1 ); |
||
333 | $expr[] = $search->compare( '>=', 'order.base.service.attribute.mtime', '1970-01-01 00:00:00' ); |
||
334 | $expr[] = $search->compare( '>=', 'order.base.service.attribute.ctime', '1970-01-01 00:00:00' ); |
||
335 | $expr[] = $search->compare( '==', 'order.base.service.attribute.editor', $this->editor ); |
||
336 | |||
337 | $search->setConditions( $search->and( $expr ) ); |
||
338 | $ref = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service']; |
||
339 | $result = $this->object->search( $search, $ref, $total ); |
||
340 | |||
341 | $this->assertEquals( 1, $total ); |
||
342 | $this->assertEquals( 1, $result->count() ); |
||
343 | |||
344 | $item = $result->first(); |
||
345 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Iface::class, $item ); |
||
346 | $this->assertEquals( 2, count( $item->getAddresses() ) ); |
||
347 | $this->assertEquals( 2, count( $item->getCoupons() ) ); |
||
348 | $this->assertEquals( 4, count( $item->getProducts() ) ); |
||
349 | $this->assertEquals( 2, count( $item->getServices() ) ); |
||
350 | } |
||
351 | |||
352 | |||
353 | public function testSearchItemsRef() |
||
354 | { |
||
355 | $search = $this->object->filter()->slice( 0, 1 ); |
||
356 | |||
357 | $search->setConditions( $search->compare( '!=', 'order.base.customerid', '' ) ); |
||
358 | $result = $this->object->search( $search, ['customer'] ); |
||
359 | |||
360 | $this->assertEquals( 1, count( $result ) ); |
||
361 | $this->assertNotNull( $result->first()->getCustomerItem() ); |
||
362 | } |
||
363 | |||
364 | |||
365 | public function testSearchItemsTotal() |
||
366 | { |
||
367 | $search = $this->object->filter(); |
||
368 | $conditions = array( |
||
369 | $search->compare( '>=', 'order.base.customerid', '' ), |
||
370 | $search->compare( '==', 'order.base.editor', $this->editor ) |
||
371 | ); |
||
372 | $search->setConditions( $search->and( $conditions ) ); |
||
373 | $search->slice( 0, 1 ); |
||
374 | $total = 0; |
||
375 | $items = $this->object->search( $search, [], $total ); |
||
376 | $this->assertEquals( 1, count( $items ) ); |
||
377 | $this->assertGreaterThanOrEqual( 4, $total ); |
||
378 | |||
379 | foreach( $items as $itemId => $item ) { |
||
380 | $this->assertEquals( $itemId, $item->getId() ); |
||
381 | } |
||
382 | } |
||
383 | |||
384 | |||
385 | public function testSearchItemsDefault() |
||
386 | { |
||
387 | $search = $this->object->filter( true ); |
||
388 | $items = $this->object->search( $search ); |
||
389 | |||
390 | $this->assertEquals( 0, count( $items ) ); |
||
391 | } |
||
392 | |||
393 | |||
394 | public function testGetSubManager() |
||
395 | { |
||
396 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'address' ) ); |
||
397 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'address', 'Standard' ) ); |
||
398 | |||
399 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'coupon' ) ); |
||
400 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'coupon', 'Standard' ) ); |
||
401 | |||
402 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'product' ) ); |
||
403 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'product', 'Standard' ) ); |
||
404 | |||
405 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'service' ) ); |
||
406 | $this->assertInstanceOf( \Aimeos\MShop\Common\Manager\Iface::class, $this->object->getSubManager( 'service', 'Standard' ) ); |
||
407 | |||
408 | $this->expectException( \Aimeos\MShop\Exception::class ); |
||
409 | $this->object->getSubManager( 'unknown' ); |
||
410 | } |
||
411 | |||
412 | |||
413 | public function testGetSubManagerInvalidName() |
||
414 | { |
||
415 | $this->expectException( \Aimeos\MShop\Exception::class ); |
||
416 | $this->object->getSubManager( 'address', 'unknown' ); |
||
417 | } |
||
418 | |||
419 | |||
420 | public function testLoad() |
||
421 | { |
||
422 | $item = $this->getOrderItem(); |
||
423 | $order = $this->object->load( $item->getId() ); |
||
424 | |||
425 | |||
426 | foreach( $order->getAddresses() as $addresses ) |
||
427 | { |
||
428 | foreach( $addresses as $address ) |
||
429 | { |
||
430 | $this->assertNotEquals( '', $address->getId() ); |
||
431 | $this->assertNotEquals( '', $address->getId() ); |
||
432 | $this->assertNotEquals( '', $address->getBaseId() ); |
||
433 | } |
||
434 | } |
||
435 | |||
436 | $this->assertEquals( 2, count( $order->getCoupons() ) ); |
||
437 | |||
438 | foreach( $order->getCoupons() as $code => $products ) |
||
439 | { |
||
440 | $this->assertNotEquals( '', $code ); |
||
441 | |||
442 | foreach( $products as $product ) { |
||
443 | $this->assertInstanceOf( \Aimeos\MShop\Order\Item\Base\Product\Iface::class, $product ); |
||
444 | } |
||
445 | } |
||
446 | |||
447 | foreach( $order->getProducts() as $product ) |
||
448 | { |
||
449 | $this->assertNotEquals( '', $product->getId() ); |
||
450 | $this->assertNotEquals( '', $product->getId() ); |
||
451 | $this->assertNotEquals( '', $product->getBaseId() ); |
||
452 | $this->assertGreaterThan( 0, $product->getPosition() ); |
||
453 | } |
||
454 | |||
455 | foreach( $order->getServices() as $list ) |
||
456 | { |
||
457 | foreach( $list as $service ) |
||
458 | { |
||
459 | $this->assertNotEquals( '', $service->getId() ); |
||
460 | $this->assertNotEquals( '', $service->getId() ); |
||
461 | $this->assertNotEquals( '', $service->getBaseId() ); |
||
462 | } |
||
463 | } |
||
464 | } |
||
465 | |||
466 | |||
467 | public function testLoadNone() |
||
468 | { |
||
469 | $item = $this->getOrderItem(); |
||
470 | $order = $this->object->load( $item->getId(), [] ); |
||
471 | |||
472 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
473 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
474 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
475 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
476 | } |
||
477 | |||
478 | |||
479 | public function testLoadAddress() |
||
480 | { |
||
481 | $item = $this->getOrderItem(); |
||
482 | $order = $this->object->load( $item->getId(), ['order/base/address'] ); |
||
483 | |||
484 | $this->assertGreaterThan( 0, count( $order->getAddresses() ) ); |
||
485 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
486 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
487 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
488 | } |
||
489 | |||
490 | |||
491 | public function testLoadProduct() |
||
492 | { |
||
493 | $item = $this->getOrderItem(); |
||
494 | $order = $this->object->load( $item->getId(), ['order/base/product'] ); |
||
495 | |||
496 | $this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
||
497 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
498 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
499 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
500 | } |
||
501 | |||
502 | |||
503 | public function testLoadCoupon() |
||
504 | { |
||
505 | $item = $this->getOrderItem(); |
||
506 | $order = $this->object->load( $item->getId(), ['order/base/coupon'] ); |
||
507 | |||
508 | $this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
||
509 | $this->assertGreaterThan( 0, count( $order->getCoupons() ) ); |
||
510 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
511 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
512 | } |
||
513 | |||
514 | |||
515 | public function testLoadService() |
||
516 | { |
||
517 | $item = $this->getOrderItem(); |
||
518 | $order = $this->object->load( $item->getId(), ['order/base/service'] ); |
||
519 | |||
520 | $this->assertGreaterThan( 0, count( $order->getServices() ) ); |
||
521 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
522 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
523 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
524 | } |
||
525 | |||
526 | |||
527 | public function testLoadFresh() |
||
528 | { |
||
529 | $item = $this->getOrderItem(); |
||
530 | $ref = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service']; |
||
531 | $order = $this->object->load( $item->getId(), $ref, true ); |
||
532 | |||
533 | |||
534 | $this->assertEquals( 2, count( $order->getCoupons() ) ); |
||
535 | |||
536 | foreach( $order->getAddresses() as $list ) |
||
537 | { |
||
538 | foreach( $list as $address ) |
||
539 | { |
||
540 | $this->assertEquals( null, $address->getId() ); |
||
541 | $this->assertEquals( null, $address->getBaseId() ); |
||
542 | } |
||
543 | } |
||
544 | |||
545 | foreach( $order->getProducts() as $product ) |
||
546 | { |
||
547 | $this->assertEquals( null, $product->getId() ); |
||
548 | $this->assertEquals( null, $product->getBaseId() ); |
||
549 | $this->assertEquals( null, $product->getPosition() ); |
||
550 | } |
||
551 | |||
552 | foreach( $order->getServices() as $list ) |
||
553 | { |
||
554 | foreach( $list as $service ) |
||
555 | { |
||
556 | $this->assertEquals( null, $service->getId() ); |
||
557 | $this->assertEquals( null, $service->getBaseId() ); |
||
558 | } |
||
559 | } |
||
560 | } |
||
561 | |||
562 | |||
563 | public function testLoadFreshNone() |
||
564 | { |
||
565 | $item = $this->getOrderItem(); |
||
566 | $order = $this->object->load( $item->getId(), [], true ); |
||
567 | |||
568 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
569 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
570 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
571 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
572 | } |
||
573 | |||
574 | |||
575 | public function testLoadFreshAddress() |
||
576 | { |
||
577 | $item = $this->getOrderItem(); |
||
578 | $order = $this->object->load( $item->getId(), ['order/base/address'], true ); |
||
579 | |||
580 | $this->assertGreaterThan( 0, count( $order->getAddresses() ) ); |
||
581 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
582 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
583 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
584 | } |
||
585 | |||
586 | |||
587 | public function testLoadFreshProduct() |
||
588 | { |
||
589 | $item = $this->getOrderItem(); |
||
590 | $order = $this->object->load( $item->getId(), ['order/base/product'], true ); |
||
591 | |||
592 | $this->assertGreaterThan( 0, count( $order->getProducts() ) ); |
||
593 | $this->assertEquals( [], $order->getCoupons()->toArray() ); |
||
594 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
595 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
596 | } |
||
597 | |||
598 | |||
599 | public function testLoadFreshCoupon() |
||
600 | { |
||
601 | $item = $this->getOrderItem(); |
||
602 | $order = $this->object->load( $item->getId(), ['order/base/coupon'], true ); |
||
603 | |||
604 | $this->assertEquals( [], $order->getAddresses()->toArray() ); |
||
605 | $this->assertEquals( 2, count( $order->getCoupons() ) ); |
||
606 | $this->assertEquals( [], $order->getProducts()->toArray() ); |
||
607 | $this->assertEquals( [], $order->getServices()->toArray() ); |
||
608 | } |
||
609 | |||
610 | |||
611 | public function testLoadFreshService() |
||
620 | } |
||
621 | |||
622 | |||
623 | public function testSave() |
||
624 | { |
||
625 | $item = $this->getOrderItem(); |
||
626 | $ref = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service']; |
||
627 | |||
628 | $basket = $this->object->load( $item->getId(), $ref, true ); |
||
629 | $this->object->save( $basket ); |
||
630 | |||
631 | $newBasketId = $basket->getId(); |
||
632 | |||
633 | $basket = $this->object->load( $newBasketId ); |
||
634 | $this->object->delete( $newBasketId ); |
||
635 | |||
636 | |||
637 | $this->assertEquals( $item->getCustomerId(), $basket->getCustomerId() ); |
||
638 | $this->assertEquals( $basket->locale()->getSiteId(), $basket->getSiteId() ); |
||
639 | |||
640 | $this->assertEquals( 1.50, $basket->getPrice()->getCosts() ); |
||
641 | |||
642 | $pos = 1; |
||
643 | $products = $basket->getProducts(); |
||
644 | $this->assertEquals( 3, count( $products ) ); |
||
645 | |||
646 | foreach( $products as $product ) |
||
647 | { |
||
648 | if( $product->getProductCode() == 'U:MD' ) { |
||
649 | continue; |
||
650 | } |
||
651 | $this->assertGreaterThanOrEqual( 2, count( $product->getAttributeItems() ) ); |
||
652 | $this->assertEquals( $pos++, $product->getPosition() ); |
||
653 | } |
||
654 | |||
655 | $this->assertEquals( 2, count( $basket->getAddresses() ) ); |
||
656 | |||
657 | $services = $basket->getServices(); |
||
658 | $this->assertEquals( 2, count( $services ) ); |
||
659 | |||
660 | $attributes = []; |
||
661 | foreach( $services as $list ) |
||
662 | { |
||
663 | foreach( $list as $service ) { |
||
664 | $attributes[$service->getCode()] = $service->getAttributeItems(); |
||
665 | } |
||
666 | } |
||
667 | |||
668 | $this->assertEquals( 9, count( $attributes['unitpaymentcode'] ) ); |
||
669 | $this->assertEquals( 0, count( $attributes['unitdeliverycode'] ) ); |
||
670 | |||
671 | $this->expectException( \Aimeos\MShop\Exception::class ); |
||
672 | $this->object->get( $newBasketId ); |
||
673 | } |
||
674 | |||
675 | |||
676 | public function testSaveExisting() |
||
677 | { |
||
678 | $item = $this->getOrderItem(); |
||
679 | $ref = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service']; |
||
680 | |||
681 | $basket = $this->object->load( $item->getId(), $ref, true ); |
||
682 | $this->object->save( $basket ); |
||
683 | $newBasketId = $basket->getId(); |
||
684 | $this->object->save( $basket ); |
||
685 | $newBasket = $this->object->load( $newBasketId ); |
||
686 | |||
687 | $this->object->delete( $newBasketId ); |
||
688 | |||
689 | foreach( $basket->getAddresses() as $type => $list ) |
||
690 | { |
||
691 | $this->assertTrue( map( $list )->getId()->equals( map( $newBasket->getAddress( $type ) )->getId() ) ); |
||
692 | } |
||
693 | |||
694 | $this->assertTrue( $basket->getProducts()->getId()->equals( $newBasket->getProducts()->getId() ) ); |
||
695 | |||
696 | foreach( $basket->getServices() as $type => $list ) |
||
697 | { |
||
698 | $this->assertTrue( map( $list )->getId()->equals( map( $newBasket->getService( $type ) )->getId() ) ); |
||
699 | } |
||
700 | } |
||
701 | |||
702 | |||
703 | public function testSaveBundles() |
||
704 | { |
||
705 | $search = $this->object->filter()->add( ['order.base.sitecode' => 'unittest', 'order.base.price' => 2400.00] ); |
||
706 | $item = $this->object->search( $search )->first( new \RuntimeException( 'No order found' ) ); |
||
707 | |||
708 | $ref = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service']; |
||
709 | $basket = $this->object->load( $item->getId(), $ref, true ); |
||
710 | $this->object->save( $basket ); |
||
711 | |||
712 | $newBasketId = $basket->getId(); |
||
713 | |||
714 | $basket = $this->object->load( $newBasketId ); |
||
715 | $this->object->delete( $newBasketId ); |
||
716 | |||
717 | $this->assertEquals( $item->getCustomerId(), $basket->getCustomerId() ); |
||
718 | $this->assertEquals( $basket->locale()->getSiteId(), $basket->getSiteId() ); |
||
719 | |||
720 | $pos = 1; |
||
721 | $products = $basket->getProducts(); |
||
722 | |||
723 | $this->assertEquals( 2, count( $products ) ); |
||
724 | foreach( $products as $product ) |
||
725 | { |
||
726 | $this->assertEquals( 2, count( $product->getProducts() ) ); |
||
727 | $this->assertEquals( $pos, $product->getPosition() ); |
||
728 | $pos += 3; // two sub-products in between |
||
729 | } |
||
730 | |||
731 | $this->expectException( \Aimeos\MShop\Exception::class ); |
||
732 | $this->object->get( $newBasketId ); |
||
733 | } |
||
734 | |||
735 | |||
736 | public function testSaveAddress() |
||
737 | { |
||
738 | $item = $this->getOrderItem(); |
||
739 | |||
740 | $basket = $this->object->load( $item->getId(), ['order/base/address'], true ); |
||
741 | $this->object->save( $basket ); |
||
742 | |||
743 | $newBasketId = $basket->getId(); |
||
744 | |||
745 | $ref = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service']; |
||
746 | $basket = $this->object->load( $newBasketId, $ref ); |
||
747 | $this->object->delete( $newBasketId ); |
||
748 | |||
749 | $this->assertGreaterThan( 0, count( $basket->getAddresses() ) ); |
||
750 | $this->assertEquals( [], $basket->getProducts()->toArray() ); |
||
751 | $this->assertEquals( [], $basket->getCoupons()->toArray() ); |
||
752 | $this->assertEquals( [], $basket->getServices()->toArray() ); |
||
753 | } |
||
754 | |||
755 | |||
756 | public function testSaveProduct() |
||
757 | { |
||
758 | $item = $this->getOrderItem(); |
||
759 | |||
760 | $basket = $this->object->load( $item->getId(), ['order/base/product'], true ); |
||
761 | $this->object->save( $basket ); |
||
762 | |||
763 | $newBasketId = $basket->getId(); |
||
764 | |||
765 | $ref = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service']; |
||
766 | $basket = $this->object->load( $newBasketId, $ref ); |
||
767 | $this->object->delete( $newBasketId ); |
||
768 | |||
769 | $this->assertGreaterThan( 0, count( $basket->getProducts() ) ); |
||
770 | $this->assertEquals( [], $basket->getAddresses()->toArray() ); |
||
771 | $this->assertEquals( [], $basket->getCoupons()->toArray() ); |
||
772 | $this->assertEquals( [], $basket->getServices()->toArray() ); |
||
773 | } |
||
774 | |||
775 | |||
776 | public function testSaveService() |
||
777 | { |
||
778 | $item = $this->getOrderItem(); |
||
779 | |||
780 | $basket = $this->object->load( $item->getId(), ['order/base/service'], true ); |
||
781 | $this->object->save( $basket ); |
||
782 | |||
783 | $newBasketId = $basket->getId(); |
||
784 | |||
785 | $ref = ['order/base/address', 'order/base/coupon', 'order/base/product', 'order/base/service']; |
||
786 | $basket = $this->object->load( $newBasketId, $ref ); |
||
787 | $this->object->delete( $newBasketId ); |
||
788 | |||
789 | $this->assertGreaterThan( 0, count( $basket->getServices() ) ); |
||
790 | $this->assertEquals( [], $basket->getProducts()->toArray() ); |
||
791 | $this->assertEquals( [], $basket->getAddresses()->toArray() ); |
||
792 | $this->assertEquals( [], $basket->getCoupons()->toArray() ); |
||
793 | } |
||
794 | |||
795 | |||
796 | public function testLoadSaveCoupons() |
||
822 | } |
||
823 | |||
824 | |||
825 | /** |
||
826 | * Returns an order base item |
||
827 | * |
||
828 | * @return \Aimeos\MShop\Order\Item\Base\Iface Order base item |
||
829 | * @throws \Exception If no found |
||
830 | */ |
||
831 | protected function getOrderItem() |
||
841 | } |
||
842 | } |
||
843 |