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\Coupon\Provider\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class SupplierTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
private $orderBase; |
17
|
|
|
private $couponItem; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$orderProducts = []; |
23
|
|
|
$this->context = \TestHelperMShop::getContext(); |
24
|
|
|
$this->couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager( $this->context )->createItem(); |
25
|
|
|
|
26
|
|
|
$provider = new \Aimeos\MShop\Coupon\Provider\Example( $this->context, $this->couponItem, 'abcd' ); |
27
|
|
|
$this->object = new \Aimeos\MShop\Coupon\Provider\Decorator\Supplier( $provider, $this->context, $this->couponItem, 'abcd'); |
28
|
|
|
$this->object->setObject( $this->object ); |
29
|
|
|
|
30
|
|
|
$priceManager = \Aimeos\MShop\Factory::createManager( $this->context, 'price' ); |
31
|
|
|
$serviceManager = \Aimeos\MShop\Factory::createManager( $this->context, 'service' ); |
32
|
|
|
$service = $serviceManager->findItem( 'unitcode' ); |
33
|
|
|
|
34
|
|
|
$orderServiceAttrManager = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base/service/attribute' ); |
35
|
|
|
$orderServiceAttr = $orderServiceAttrManager->createItem(); |
36
|
|
|
$orderServiceAttr->setCode( 'supplier.code' ); |
37
|
|
|
$orderServiceAttr->setType( 'delivery' ); |
38
|
|
|
$orderServiceAttr->setValue( 'berlin' ); |
39
|
|
|
|
40
|
|
|
$orderServiceManager = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base/service' ); |
41
|
|
|
$orderService = $orderServiceManager->createItem(); |
42
|
|
|
$orderService->copyFrom( $service ); |
43
|
|
|
$orderService->setAttributes( [$orderServiceAttr] ); |
44
|
|
|
|
45
|
|
|
$this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard( $priceManager->createItem(), $this->context->getLocale() ); |
46
|
|
|
$this->orderBase->setService( $orderService, \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
protected function tearDown() |
51
|
|
|
{ |
52
|
|
|
unset( $this->object ); |
53
|
|
|
unset( $this->orderBase ); |
54
|
|
|
unset( $this->couponItem ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function testGetConfigBE() |
59
|
|
|
{ |
60
|
|
|
$result = $this->object->getConfigBE(); |
61
|
|
|
|
62
|
|
|
$this->assertArrayHasKey( 'supplier.code', $result ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function testCheckConfigBE() |
67
|
|
|
{ |
68
|
|
|
$attributes = ['supplier.code' => 'test']; |
69
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
70
|
|
|
|
71
|
|
|
$this->assertEquals( 1, count( $result ) ); |
72
|
|
|
$this->assertInternalType( 'null', $result['supplier.code'] ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testCheckConfigBEFailure() |
77
|
|
|
{ |
78
|
|
|
$result = $this->object->checkConfigBE( [] ); |
79
|
|
|
|
80
|
|
|
$this->assertEquals( 1, count( $result ) ); |
81
|
|
|
$this->assertInternalType( 'string', $result['supplier.code'] ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testIsAvailable() |
86
|
|
|
{ |
87
|
|
|
$this->couponItem->setConfig( array( 'supplier.code' => 'berlin' ) ); |
88
|
|
|
|
89
|
|
|
$this->assertTrue( $this->object->isAvailable( $this->orderBase ) ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testIsAvailableWrongSupplier() |
94
|
|
|
{ |
95
|
|
|
$this->couponItem->setConfig( array( 'supplier.code' => 'hamburg' ) ); |
96
|
|
|
|
97
|
|
|
$this->assertFalse( $this->object->isAvailable( $this->orderBase ) ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testIsAvailableNoSupplier() |
102
|
|
|
{ |
103
|
|
|
$this->assertFalse( $this->object->isAvailable( $this->orderBase ) ); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|