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\Plugin\Provider\Order; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class ShippingTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $context; |
16
|
|
|
private $object; |
17
|
|
|
private $plugin; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$this->context = \TestHelperMShop::getContext(); |
23
|
|
|
|
24
|
|
|
$pluginManager = \Aimeos\MShop\Plugin\Manager\Factory::createManager( $this->context ); |
25
|
|
|
$this->plugin = $pluginManager->createItem(); |
26
|
|
|
$this->plugin->setTypeId( 2 ); |
27
|
|
|
$this->plugin->setStatus( '1' ); |
28
|
|
|
|
29
|
|
|
$this->object = new \Aimeos\MShop\Plugin\Provider\Order\Shipping( $this->context, $this->plugin ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
protected function tearDown() |
34
|
|
|
{ |
35
|
|
|
unset( $this->object, $this->plugin, $this->context ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function testCheckConfigBE() |
40
|
|
|
{ |
41
|
|
|
$attributes = array( |
42
|
|
|
'threshold' => ['EUR' => '50.00'], |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
46
|
|
|
|
47
|
|
|
$this->assertEquals( 1, count( $result ) ); |
48
|
|
|
$this->assertEquals( null, $result['threshold'] ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
public function testGetConfigBE() |
53
|
|
|
{ |
54
|
|
|
$list = $this->object->getConfigBE(); |
55
|
|
|
|
56
|
|
|
$this->assertEquals( 1, count( $list ) ); |
57
|
|
|
$this->assertArrayHasKey( 'threshold', $list ); |
58
|
|
|
|
59
|
|
|
foreach( $list as $entry ) { |
60
|
|
|
$this->assertInstanceOf( '\Aimeos\MW\Criteria\Attribute\Iface', $entry ); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testRegister() |
66
|
|
|
{ |
67
|
|
|
$order = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' )->createItem(); |
68
|
|
|
|
69
|
|
|
$this->object->register( $order ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
public function testUpdate() |
74
|
|
|
{ |
75
|
|
|
$context = \TestHelperMShop::getContext(); |
76
|
|
|
|
77
|
|
|
$this->plugin->setProvider( 'Shipping' ); |
78
|
|
|
$this->plugin->setConfig( array( 'threshold' => array( 'EUR' => '34.00' ) ) ); |
79
|
|
|
|
80
|
|
|
$orderBaseManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
81
|
|
|
$orderBaseProductManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' ); |
82
|
|
|
|
83
|
|
|
$manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $context ); |
84
|
|
|
$search = $manager->createSearch(); |
85
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', array( 'CNE', 'CNC', 'IJKL' ) ) ); |
86
|
|
|
$pResults = $manager->searchItems( $search, array( 'price' ) ); |
87
|
|
|
|
88
|
|
|
if( count( $pResults ) !== 3 ) { |
89
|
|
|
throw new \RuntimeException( 'Wrong number of products' ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$products = []; |
93
|
|
|
foreach( $pResults as $prod ) { |
94
|
|
|
$products[$prod->getCode()] = $prod; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
if( ( $price = current( $products['IJKL']->getRefItems( 'price' ) ) ) === false ) { |
98
|
|
|
throw new \RuntimeException( 'No price item found' ); |
99
|
|
|
} |
100
|
|
|
$price->setValue( 10.00 ); |
101
|
|
|
|
102
|
|
|
$product = $orderBaseProductManager->createItem(); |
103
|
|
|
$product->copyFrom( $products['CNE'] ); |
104
|
|
|
$product->setPrice( $price ); |
105
|
|
|
|
106
|
|
|
$product2 = $orderBaseProductManager->createItem(); |
107
|
|
|
$product2->copyFrom( $products['CNC'] ); |
108
|
|
|
$product2->setPrice( $price ); |
109
|
|
|
|
110
|
|
|
$product3 = $orderBaseProductManager->createItem(); |
111
|
|
|
$product3->copyFrom( $products['IJKL'] ); |
112
|
|
|
$product3->setPrice( $price ); |
113
|
|
|
|
114
|
|
|
$orderBaseServiceManager = $orderBaseManager->getSubManager( 'service' ); |
115
|
|
|
|
116
|
|
|
$serviceSearch = $orderBaseServiceManager->createSearch(); |
117
|
|
|
$exp = array( |
118
|
|
|
$serviceSearch->compare( '==', 'order.base.service.type', 'delivery' ), |
119
|
|
|
$serviceSearch->compare( '==', 'order.base.service.costs', '5.00' ) |
120
|
|
|
); |
121
|
|
|
$serviceSearch->setConditions( $serviceSearch->combine( '&&', $exp ) ); |
122
|
|
|
$results = $orderBaseServiceManager->searchItems( $serviceSearch ); |
123
|
|
|
|
124
|
|
|
if( ( $delivery = reset( $results ) ) === false ) { |
125
|
|
|
throw new \RuntimeException( 'No order base item found' ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$order = $orderBaseManager->createItem(); |
129
|
|
|
$order->__sleep(); // remove event listeners |
130
|
|
|
|
131
|
|
|
$order->setService( $delivery, 'delivery' ); |
132
|
|
|
$order->addProduct( $product ); |
133
|
|
|
$order->addProduct( $product2 ); |
134
|
|
|
$order->addProduct( $product3 ); |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
$this->assertEquals( 5.00, $order->getPrice()->getCosts() ); |
138
|
|
|
$this->object->update( $order, 'addProduct' ); |
139
|
|
|
|
140
|
|
|
$order->addProduct( $product ); |
141
|
|
|
$this->object->update( $order, 'addProduct' ); |
142
|
|
|
|
143
|
|
|
$this->assertEquals( 0.00, $order->getPrice()->getCosts() ); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|