Completed
Push — master ( fbc717...7baaae )
by Aimeos
09:41
created

ServicesAvailableTest::testCheckConfigBE()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2016
7
 */
8
9
10
namespace Aimeos\MShop\Plugin\Provider\Order;
11
12
13
class ServicesAvailableTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $order;
17
	private $plugin;
18
	private $service;
19
20
21
	protected function setUp()
22
	{
23
		$context = \TestHelperMShop::getContext();
24
25
		$pluginManager = \Aimeos\MShop\Plugin\Manager\Factory::createManager( $context );
26
		$this->plugin = $pluginManager->createItem();
27
		$this->plugin->setProvider( 'ServicesAvailable' );
28
		$this->plugin->setStatus( 1 );
29
30
		$orderBaseManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' );
31
		$orderBaseServiceManager = $orderBaseManager->getSubManager( 'service' );
32
33
		$this->service = $orderBaseServiceManager->createItem();
34
		$this->order = $orderBaseManager->createItem();
35
		$this->order->__sleep(); // remove event listeners
36
37
		$this->object = new \Aimeos\MShop\Plugin\Provider\Order\ServicesAvailable( $context, $this->plugin );
38
	}
39
40
41
	protected function tearDown()
42
	{
43
		unset( $this->plugin, $this->service, $this->order, $this->object );
44
	}
45
46
47
	public function testCheckConfigBE()
48
	{
49
		$attributes = array(
50
			'payment' => '1',
51
			'delivery' => '0',
52
		);
53
54
		$result = $this->object->checkConfigBE( $attributes );
55
56
		$this->assertEquals( 2, count( $result ) );
57
		$this->assertEquals( null, $result['payment'] );
58
		$this->assertEquals( null, $result['delivery'] );
59
	}
60
61
62
	public function testGetConfigBE()
63
	{
64
		$list = $this->object->getConfigBE();
65
66
		$this->assertEquals( 2, count( $list ) );
67
		$this->assertArrayHasKey( 'payment', $list );
68
		$this->assertArrayHasKey( 'delivery', $list );
69
70
		foreach( $list as $entry ) {
71
			$this->assertInstanceOf( '\Aimeos\MW\Criteria\Attribute\Iface', $entry );
72
		}
73
	}
74
75
76
	public function testRegister()
77
	{
78
		$this->object->register( $this->order );
79
	}
80
81
82
	public function testUpdateNone()
83
	{
84
		// \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE not set, so update shall not be executed
85
		$this->assertTrue( $this->object->update( $this->order, 'check.after' ) );
86
	}
87
88
89
	public function testUpdateEmptyConfig()
90
	{
91
		$this->assertTrue( $this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE ) );
92
93
		$this->order->setService( $this->service, 'payment' );
94
		$this->order->setService( $this->service, 'delivery' );
95
96
		$this->assertTrue( $this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE ) );
97
98
	}
99
100
101
	public function testUpdateNoServices()
102
	{
103
		$this->plugin->setConfig( array(
104
				'delivery' => false,
105
				'payment' => false
106
		) );
107
108
		$this->assertTrue( $this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE ) );
109
110
		$this->plugin->setConfig( array(
111
				'delivery' => null,
112
				'payment' => null
113
		) );
114
115
		$this->assertTrue( $this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE ) );
116
117
		$this->plugin->setConfig( array(
118
				'delivery' => true,
119
				'payment' => true
120
		) );
121
122
		$this->setExpectedException( '\\Aimeos\\MShop\\Plugin\\Provider\\Exception' );
123
		$this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE );
124
	}
125
126
127
	public function testUpdateWithServices()
128
	{
129
		$this->order->setService( $this->service, 'payment' );
130
		$this->order->setService( $this->service, 'delivery' );
131
132
		$this->plugin->setConfig( array(
133
				'delivery' => null,
134
				'payment' => null
135
		) );
136
137
		$this->assertTrue( $this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE ) );
138
139
		$this->plugin->setConfig( array(
140
				'delivery' => true,
141
				'payment' => true
142
		) );
143
144
		$this->assertTrue( $this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE ) );
145
146
		$this->plugin->setConfig( array(
147
				'delivery' => false,
148
				'payment' => false
149
		) );
150
151
		$this->setExpectedException( '\\Aimeos\\MShop\\Plugin\\Provider\\Exception' );
152
		$this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_SERVICE );
153
	}
154
}