1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2021 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Coupon\Provider\Decorator; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class BasketTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $orderBase; |
17
|
|
|
private $couponItem; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() : void |
21
|
|
|
{ |
22
|
|
|
$orderProducts = []; |
23
|
|
|
$context = \TestHelperMShop::getContext(); |
24
|
|
|
|
25
|
|
|
$couponManager = \Aimeos\MShop\Coupon\Manager\Factory::create( $context ); |
26
|
|
|
$this->couponItem = $couponManager->create(); |
27
|
|
|
|
28
|
|
|
$provider = new \Aimeos\MShop\Coupon\Provider\Example( $context, $this->couponItem, 'abcd' ); |
29
|
|
|
$this->object = new \Aimeos\MShop\Coupon\Provider\Decorator\Basket( $provider, $context, $this->couponItem, 'abcd' ); |
30
|
|
|
$this->object->setObject( $this->object ); |
31
|
|
|
|
32
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::create( $context ); |
33
|
|
|
$orderBaseManager = $orderManager->getSubManager( 'base' ); |
34
|
|
|
$orderProductManager = $orderBaseManager->getSubManager( 'product' ); |
35
|
|
|
|
36
|
|
|
$productManager = \Aimeos\MShop\Product\Manager\Factory::create( $context ); |
37
|
|
|
$search = $productManager->filter(); |
38
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', array( 'CNC' ) ) ); |
39
|
|
|
$products = $productManager->search( $search )->toArray(); |
40
|
|
|
|
41
|
|
|
$priceManager = \Aimeos\MShop\Price\Manager\Factory::create( $context ); |
42
|
|
|
$price = $priceManager->create(); |
43
|
|
|
$price->setValue( 321 ); |
44
|
|
|
|
45
|
|
|
foreach( $products as $product ) |
46
|
|
|
{ |
47
|
|
|
$orderProduct = $orderProductManager->create(); |
48
|
|
|
$orderProduct->copyFrom( $product ); |
49
|
|
|
$orderProducts[$product->getCode()] = $orderProduct; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$orderProducts['CNC']->setPrice( $price ); |
53
|
|
|
|
54
|
|
|
$this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard( $priceManager->create(), $context->getLocale() ); |
55
|
|
|
$this->orderBase->addProduct( $orderProducts['CNC'] ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
protected function tearDown() : void |
60
|
|
|
{ |
61
|
|
|
unset( $this->object ); |
62
|
|
|
unset( $this->orderBase ); |
63
|
|
|
unset( $this->couponItem ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
public function testGetConfigBE() |
68
|
|
|
{ |
69
|
|
|
$result = $this->object->getConfigBE(); |
70
|
|
|
|
71
|
|
|
$this->assertArrayHasKey( 'basketvalues.total-value-min', $result ); |
72
|
|
|
$this->assertArrayHasKey( 'basketvalues.total-value-max', $result ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testCheckConfigBE() |
77
|
|
|
{ |
78
|
|
|
$attributes = [ |
79
|
|
|
'basketvalues.total-value-min' => ['EUR' => '10.5'], |
80
|
|
|
'basketvalues.total-value-max' => ['EUR' => '100'], |
81
|
|
|
]; |
82
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
83
|
|
|
|
84
|
|
|
$this->assertEquals( 2, count( $result ) ); |
85
|
|
|
$this->assertNull( $result['basketvalues.total-value-min'] ); |
86
|
|
|
$this->assertNull( $result['basketvalues.total-value-max'] ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testCheckConfigBEFailure() |
91
|
|
|
{ |
92
|
|
|
$result = $this->object->checkConfigBE( ['basketvalues.total-value-min' => '10.5'] ); |
93
|
|
|
|
94
|
|
|
$this->assertEquals( 2, count( $result ) ); |
95
|
|
|
$this->assertIsString( $result['basketvalues.total-value-min'] ); |
96
|
|
|
$this->assertNull( $result['basketvalues.total-value-max'] ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
public function testIsAvailable() |
101
|
|
|
{ |
102
|
|
|
$config = array( |
103
|
|
|
'basketvalues.total-value-min' => array( 'EUR' => 320 ), |
104
|
|
|
'basketvalues.total-value-max' => array( 'EUR' => 1000 ), |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$this->couponItem->setConfig( $config ); |
108
|
|
|
$result = $this->object->isAvailable( $this->orderBase ); |
109
|
|
|
|
110
|
|
|
$this->assertTrue( $result ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
// min value higher than order price |
114
|
|
|
public function testIsAvailableTestMinValue() |
115
|
|
|
{ |
116
|
|
|
$config = array( |
117
|
|
|
'basketvalues.total-value-min' => array( 'EUR' => 700 ), |
118
|
|
|
'basketvalues.total-value-max' => array( 'EUR' => 1000 ), |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$this->couponItem->setConfig( $config ); |
122
|
|
|
$result = $this->object->isAvailable( $this->orderBase ); |
123
|
|
|
|
124
|
|
|
$this->assertFalse( $result ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
// order price higher than max price |
128
|
|
|
public function testIsAvailableTestMaxValue() |
129
|
|
|
{ |
130
|
|
|
$config = array( |
131
|
|
|
'basketvalues.total-value-min' => array( 'EUR' => 50 ), |
132
|
|
|
'basketvalues.total-value-max' => array( 'EUR' => 320 ), |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
$this->couponItem->setConfig( $config ); |
136
|
|
|
$result = $this->object->isAvailable( $this->orderBase ); |
137
|
|
|
|
138
|
|
|
$this->assertFalse( $result ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
} |
142
|
|
|
|