1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Coupon\Provider\Decorator; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class RequiredTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $orderBase; |
17
|
|
|
private $couponItem; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$orderProducts = []; |
23
|
|
|
$context = \TestHelperMShop::getContext(); |
24
|
|
|
$this->couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager( $context )->createItem(); |
25
|
|
|
|
26
|
|
|
$provider = new \Aimeos\MShop\Coupon\Provider\Example( $context, $this->couponItem, 'abcd' ); |
27
|
|
|
$this->object = new \Aimeos\MShop\Coupon\Provider\Decorator\Required( $provider, $context, $this->couponItem, 'abcd'); |
28
|
|
|
$this->object->setObject( $this->object ); |
29
|
|
|
|
30
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( $context ); |
31
|
|
|
$orderBaseManager = $orderManager->getSubManager( 'base' ); |
32
|
|
|
$orderProductManager = $orderBaseManager->getSubManager( 'product' ); |
33
|
|
|
|
34
|
|
|
$productManager = \Aimeos\MShop\Product\Manager\Factory::createManager( $context ); |
35
|
|
|
$search = $productManager->createSearch(); |
36
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', array( 'CNC' ) ) ); |
37
|
|
|
$products = $productManager->searchItems( $search ); |
38
|
|
|
|
39
|
|
|
$priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager( $context ); |
40
|
|
|
$price = $priceManager->createItem(); |
41
|
|
|
$price->setValue( 321 ); |
42
|
|
|
|
43
|
|
|
foreach( $products as $product ) |
44
|
|
|
{ |
45
|
|
|
$orderProduct = $orderProductManager->createItem(); |
46
|
|
|
$orderProduct->copyFrom( $product ); |
47
|
|
|
$orderProducts[$product->getCode()] = $orderProduct; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$orderProducts['CNC']->setPrice( $price ); |
51
|
|
|
|
52
|
|
|
$this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard( $priceManager->createItem(), $context->getLocale() ); |
53
|
|
|
$this->orderBase->addProduct( $orderProducts['CNC'] ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
protected function tearDown() |
58
|
|
|
{ |
59
|
|
|
unset( $this->object ); |
60
|
|
|
unset( $this->orderBase ); |
61
|
|
|
unset( $this->couponItem ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testGetConfigBE() |
66
|
|
|
{ |
67
|
|
|
$result = $this->object->getConfigBE(); |
68
|
|
|
|
69
|
|
|
$this->assertArrayHasKey( 'required.productcode', $result ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
public function testCheckConfigBE() |
74
|
|
|
{ |
75
|
|
|
$attributes = ['required.productcode' => 'test']; |
76
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
77
|
|
|
|
78
|
|
|
$this->assertEquals( 1, count( $result ) ); |
79
|
|
|
$this->assertInternalType( 'null', $result['required.productcode'] ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
public function testCheckConfigBEFailure() |
84
|
|
|
{ |
85
|
|
|
$result = $this->object->checkConfigBE( [] ); |
86
|
|
|
|
87
|
|
|
$this->assertEquals( 1, count( $result ) ); |
88
|
|
|
$this->assertInternalType( 'string', $result['required.productcode'] ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function testIsAvailable() |
93
|
|
|
{ |
94
|
|
|
$this->assertTrue( $this->object->isAvailable( $this->orderBase ) ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
public function testIsAvailableWithProduct() |
99
|
|
|
{ |
100
|
|
|
$this->couponItem->setConfig( array( 'required.productcode' => 'CNC' ) ); |
101
|
|
|
|
102
|
|
|
$this->assertTrue( $this->object->isAvailable( $this->orderBase ) ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function testIsAvailableWithoutProduct() |
107
|
|
|
{ |
108
|
|
|
$this->couponItem->setConfig( array( 'required.productcode' => 'CNE' ) ); |
109
|
|
|
|
110
|
|
|
$this->assertFalse( $this->object->isAvailable( $this->orderBase ) ); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|