1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Coupon\Provider; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class PresentTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $orderBase; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$context = \TestHelperMShop::getContext(); |
22
|
|
|
|
23
|
|
|
$priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager( $context ); |
24
|
|
|
$couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager( $context )->createItem(); |
25
|
|
|
$couponItem->setConfig( array( 'present.productcode' => 'U:PD', 'present.quantity' => '1' ) ); |
26
|
|
|
|
27
|
|
|
// Don't create order base item by createItem() as this would already register the plugins |
28
|
|
|
$this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard( $priceManager->createItem(), $context->getLocale() ); |
29
|
|
|
$this->object = new \Aimeos\MShop\Coupon\Provider\Present( $context, $couponItem, 'zyxw' ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
protected function tearDown() |
34
|
|
|
{ |
35
|
|
|
unset( $this->object ); |
36
|
|
|
unset( $this->orderBase ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function testAddCoupon() |
41
|
|
|
{ |
42
|
|
|
$this->object->addCoupon( $this->orderBase ); |
43
|
|
|
|
44
|
|
|
$coupons = $this->orderBase->getCoupons(); |
45
|
|
|
$products = $this->orderBase->getProducts(); |
46
|
|
|
|
47
|
|
|
if( !isset( $coupons['zyxw'][0] ) ) { |
48
|
|
|
throw new \RuntimeException( 'Missing coupon product' ); |
49
|
|
|
} |
50
|
|
|
$product = $coupons['zyxw'][0]; |
51
|
|
|
|
52
|
|
|
$this->assertEquals( 1, count( $products ) ); |
53
|
|
|
$this->assertEquals( 1, count( $coupons['zyxw'] ) ); |
54
|
|
|
$this->assertEquals( 'U:PD', $product->getProductCode() ); |
55
|
|
|
$this->assertNotEquals( '', $product->getProductId() ); |
56
|
|
|
$this->assertEquals( '', $product->getSupplierCode() ); |
57
|
|
|
$this->assertEquals( '', $product->getMediaUrl() ); |
58
|
|
|
$this->assertEquals( 'Geschenk Nachlass', $product->getName() ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testDeleteCoupon() |
63
|
|
|
{ |
64
|
|
|
$this->object->addCoupon( $this->orderBase ); |
65
|
|
|
$this->object->deleteCoupon( $this->orderBase ); |
66
|
|
|
|
67
|
|
|
$coupons = $this->orderBase->getCoupons(); |
68
|
|
|
$products = $this->orderBase->getProducts(); |
69
|
|
|
|
70
|
|
|
$this->assertEquals( 0, count( $products ) ); |
71
|
|
|
$this->assertArrayNotHasKey( 'zyxw', $coupons ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testAddCouponInvalidConfig() |
76
|
|
|
{ |
77
|
|
|
$context = \TestHelperMShop::getContext(); |
78
|
|
|
$couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager( \TestHelperMShop::getContext() )->createItem(); |
79
|
|
|
|
80
|
|
|
$object = new \Aimeos\MShop\Coupon\Provider\Present( $context, $couponItem, 'zyxw' ); |
81
|
|
|
|
82
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Coupon\\Exception' ); |
83
|
|
|
$object->addCoupon( $this->orderBase ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
public function testGetConfigBE() |
88
|
|
|
{ |
89
|
|
|
$result = $this->object->getConfigBE(); |
90
|
|
|
|
91
|
|
|
$this->assertArrayHasKey( 'present.productcode', $result ); |
92
|
|
|
$this->assertArrayHasKey( 'present.quantity', $result ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function testCheckConfigBE() |
97
|
|
|
{ |
98
|
|
|
$attributes = ['present.productcode' => 'test', 'present.quantity' => 5]; |
99
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
100
|
|
|
|
101
|
|
|
$this->assertEquals( 2, count( $result ) ); |
102
|
|
|
$this->assertInternalType( 'null', $result['present.productcode'] ); |
103
|
|
|
$this->assertInternalType( 'null', $result['present.quantity'] ); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
|
107
|
|
|
public function testCheckConfigBEFailure() |
108
|
|
|
{ |
109
|
|
|
$result = $this->object->checkConfigBE( [] ); |
110
|
|
|
|
111
|
|
|
$this->assertEquals( 2, count( $result ) ); |
112
|
|
|
$this->assertInternalType( 'string', $result['present.productcode'] ); |
113
|
|
|
$this->assertInternalType( 'string', $result['present.quantity'] ); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
public function testIsAvailable() |
118
|
|
|
{ |
119
|
|
|
$this->assertTrue( $this->object->isAvailable( $this->orderBase ) ); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|