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 FreeShippingTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $orderBase; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$context = \TestHelperMShop::getContext(); |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
$couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager( $context )->createItem(); |
25
|
|
|
$couponItem->setConfig( array( 'freeshipping.productcode' => 'U:SD' ) ); |
26
|
|
|
|
27
|
|
|
$this->object = new \Aimeos\MShop\Coupon\Provider\FreeShipping( $context, $couponItem, 'zyxw' ); |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
$delPrice = \Aimeos\MShop\Price\Manager\Factory::createManager( $context )->createItem(); |
31
|
|
|
$delPrice->setCosts( '5.00' ); |
32
|
|
|
$delPrice->setCurrencyId( 'EUR' ); |
33
|
|
|
|
34
|
|
|
$priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager( $context ); |
35
|
|
|
$manager = \Aimeos\MShop\Order\Manager\Factory::createManager( $context ) |
36
|
|
|
->getSubManager( 'base' )->getSubManager( 'service' ); |
37
|
|
|
|
38
|
|
|
$delivery = $manager->createItem(); |
39
|
|
|
$delivery->setCode( 'test' ); |
40
|
|
|
$delivery->setType( 'delivery' ); |
41
|
|
|
$delivery->setPrice( $delPrice ); |
42
|
|
|
|
43
|
|
|
// Don't create order base item by createItem() as this would already register the plugins |
44
|
|
|
$this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard( $priceManager->createItem(), $context->getLocale() ); |
45
|
|
|
$this->orderBase->setService( $delivery, 'delivery' ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
protected function tearDown() |
50
|
|
|
{ |
51
|
|
|
unset( $this->object ); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testAddCoupon() |
56
|
|
|
{ |
57
|
|
|
$this->object->addCoupon( $this->orderBase ); |
58
|
|
|
$coupons = $this->orderBase->getCoupons(); |
59
|
|
|
|
60
|
|
|
if( ( $product = reset( $coupons['zyxw'] ) ) === false ) { |
61
|
|
|
throw new \RuntimeException( 'No coupon available' ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// Test if service delivery item is available |
65
|
|
|
$this->orderBase->getService( 'delivery' ); |
66
|
|
|
|
67
|
|
|
$this->assertEquals( 1, count( $this->orderBase->getProducts() ) ); |
68
|
|
|
$this->assertEquals( '-5.00', $product->getPrice()->getCosts() ); |
69
|
|
|
$this->assertEquals( '5.00', $product->getPrice()->getRebate() ); |
70
|
|
|
$this->assertEquals( 'U:SD', $product->getProductCode() ); |
71
|
|
|
$this->assertNotEquals( '', $product->getProductId() ); |
72
|
|
|
$this->assertEquals( '', $product->getSupplierCode() ); |
73
|
|
|
$this->assertEquals( '', $product->getMediaUrl() ); |
74
|
|
|
$this->assertEquals( 'Versandkosten Nachlass', $product->getName() ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testDeleteCoupon() |
79
|
|
|
{ |
80
|
|
|
$this->object->addCoupon( $this->orderBase ); |
81
|
|
|
$this->object->deleteCoupon( $this->orderBase ); |
82
|
|
|
|
83
|
|
|
$products = $this->orderBase->getProducts(); |
84
|
|
|
$coupons = $this->orderBase->getCoupons(); |
85
|
|
|
|
86
|
|
|
$this->assertEquals( 0, count( $products ) ); |
87
|
|
|
$this->assertArrayNotHasKey( 'zyxw', $coupons ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testAddCouponInvalidConfig() |
92
|
|
|
{ |
93
|
|
|
$context = \TestHelperMShop::getContext(); |
94
|
|
|
|
95
|
|
|
$couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager( \TestHelperMShop::getContext() )->createItem(); |
96
|
|
|
$object = new \Aimeos\MShop\Coupon\Provider\FreeShipping( $context, $couponItem, 'zyxw' ); |
97
|
|
|
|
98
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Coupon\\Exception' ); |
99
|
|
|
$object->addCoupon( $this->orderBase ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
public function testGetConfigBE() |
104
|
|
|
{ |
105
|
|
|
$result = $this->object->getConfigBE(); |
106
|
|
|
|
107
|
|
|
$this->assertArrayHasKey( 'freeshipping.productcode', $result ); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
public function testCheckConfigBE() |
112
|
|
|
{ |
113
|
|
|
$attributes = ['freeshipping.productcode' => 'test']; |
114
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
115
|
|
|
|
116
|
|
|
$this->assertEquals( 1, count( $result ) ); |
117
|
|
|
$this->assertInternalType( 'null', $result['freeshipping.productcode'] ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
public function testCheckConfigBEFailure() |
122
|
|
|
{ |
123
|
|
|
$result = $this->object->checkConfigBE( [] ); |
124
|
|
|
|
125
|
|
|
$this->assertEquals( 1, count( $result ) ); |
126
|
|
|
$this->assertInternalType( 'string', $result['freeshipping.productcode'] ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
public function testIsAvailable() |
131
|
|
|
{ |
132
|
|
|
$this->assertTrue( $this->object->isAvailable( $this->orderBase ) ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
} |
136
|
|
|
|