1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Plugin\Provider\Order; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class ProductFreeOptionsTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $object; |
16
|
|
|
private $plugin; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelperMShop::getContext(); |
22
|
|
|
|
23
|
|
|
$pluginManager = \Aimeos\MShop\Plugin\Manager\Factory::createManager( $this->context ); |
24
|
|
|
$this->plugin = $pluginManager->createItem(); |
25
|
|
|
$this->plugin->setProvider( 'ProductFreeOption' ); |
26
|
|
|
|
27
|
|
|
$this->object = new \Aimeos\MShop\Plugin\Provider\Order\ProductFreeOptions( $this->context, $this->plugin ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
protected function tearDown() |
32
|
|
|
{ |
33
|
|
|
unset( $this->context, $this->object, $this->plugin ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testRegister() |
38
|
|
|
{ |
39
|
|
|
$basket = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' )->createItem(); |
40
|
|
|
|
41
|
|
|
$this->object->register( $basket ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
public function testUpdate() |
46
|
|
|
{ |
47
|
|
|
$prodManager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' ); |
48
|
|
|
$attrManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
49
|
|
|
|
50
|
|
|
$basket = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' )->createItem(); |
51
|
|
|
$product = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base/product' )->createItem(); |
52
|
|
|
$attribute = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base/product/attribute' )->createItem(); |
53
|
|
|
|
54
|
|
|
$attribute->setQuantity( 2 ); |
55
|
|
|
$attribute->setCode( 'size' ); |
56
|
|
|
$attribute->setType( 'config' ); |
57
|
|
|
$attribute->setAttributeId( $attrManager->findItem( 'xs', [], 'product', 'size')->getId() ); |
58
|
|
|
|
59
|
|
|
$product->setAttributeItem( $attribute ); |
60
|
|
|
$product->setProductId( $prodManager->findItem( 'CNE' )->getId() ); |
61
|
|
|
|
62
|
|
|
$this->object->update( $basket, 'addProduct.after', $product ); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( '30.95', $product->getPrice()->getValue() ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testAddPrices() |
69
|
|
|
{ |
70
|
|
|
$price = \Aimeos\MShop\Factory::createManager( $this->context, 'price' )->createItem(); |
71
|
|
|
$price->setValue( '10.00' ); |
72
|
|
|
|
73
|
|
|
$attrManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
74
|
|
|
$attrItem = $attrManager->findItem( 'xs', ['price'], 'product', 'size' ); |
75
|
|
|
|
76
|
|
|
$quantities = [$attrItem->getId() => 2]; |
77
|
|
|
$attrItems = [$attrItem->getId() => $attrItem]; |
78
|
|
|
|
79
|
|
|
$price = $this->access( 'addPrices' )->invokeArgs( $this->object, [$price, $attrItems, $quantities, 1] ); |
80
|
|
|
|
81
|
|
|
$this->assertEquals( '22.95', $price->getValue() ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testSortByPrice() |
86
|
|
|
{ |
87
|
|
|
$price = \Aimeos\MShop\Factory::createManager( $this->context, 'price' )->createItem(); |
88
|
|
|
|
89
|
|
|
$attrManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
90
|
|
|
$attrItem = $attrManager->findItem( 'xs', ['price'], 'product', 'size' ); |
91
|
|
|
|
92
|
|
|
$quantities = [1 => 2]; |
93
|
|
|
$attrItems = [1 => $attrItem]; |
94
|
|
|
|
95
|
|
|
$items = $this->access( 'sortByPrice' )->invokeArgs( $this->object, [$attrItems, $quantities] ); |
96
|
|
|
|
97
|
|
|
$this->assertEquals( [1], array_keys( $items ) ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testSortByPriceFirstNoPrice() |
102
|
|
|
{ |
103
|
|
|
$price = \Aimeos\MShop\Factory::createManager( $this->context, 'price' )->createItem(); |
104
|
|
|
|
105
|
|
|
$attrManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
106
|
|
|
$attrItem1 = $attrManager->findItem( 'xs', ['price'], 'product', 'size' ); |
107
|
|
|
$attrItem2 = $attrManager->findItem( 's', [], 'product', 'size' ); |
108
|
|
|
|
109
|
|
|
$quantities = [1 => 1, 2 => 1]; |
110
|
|
|
$attrItems = [1 => $attrItem2, 2 => $attrItem1]; |
111
|
|
|
|
112
|
|
|
$items = $this->access( 'sortByPrice' )->invokeArgs( $this->object, [$attrItems, $quantities] ); |
113
|
|
|
|
114
|
|
|
$this->assertEquals( [2, 1], array_keys( $items ) ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testSortByPriceSecondNoPrice() |
119
|
|
|
{ |
120
|
|
|
$price = \Aimeos\MShop\Factory::createManager( $this->context, 'price' )->createItem(); |
121
|
|
|
|
122
|
|
|
$attrManager = \Aimeos\MShop\Factory::createManager( $this->context, 'attribute' ); |
123
|
|
|
$attrItem1 = $attrManager->findItem( 'xs', ['price'], 'product', 'size' ); |
124
|
|
|
$attrItem2 = $attrManager->findItem( 's', [], 'product', 'size' ); |
125
|
|
|
|
126
|
|
|
$quantities = [1 => 1, 2 => 1]; |
127
|
|
|
$attrItems = [1 => $attrItem1, 2 => $attrItem2]; |
128
|
|
|
|
129
|
|
|
$items = $this->access( 'sortByPrice' )->invokeArgs( $this->object, [$attrItems, $quantities] ); |
130
|
|
|
|
131
|
|
|
$this->assertEquals( [1, 2], array_keys( $items ) ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
protected function access( $name ) |
136
|
|
|
{ |
137
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Plugin\Provider\Order\ProductFreeOptions' ); |
138
|
|
|
$method = $class->getMethod( $name ); |
139
|
|
|
$method->setAccessible( true ); |
140
|
|
|
|
141
|
|
|
return $method; |
142
|
|
|
} |
143
|
|
|
} |