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

BasketLimitsTest::testCheckConfigBE()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 17
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
namespace Aimeos\MShop\Plugin\Provider\Order;
10
11
12
class BasketLimitsTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $products;
16
	private $order;
17
18
19
	protected function setUp()
20
	{
21
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperMShop::getContext() );
22
		$orderBaseManager = $orderManager->getSubManager( 'base' );
23
24
		$this->order = $orderBaseManager->createItem();
25
		$this->order->__sleep(); // remove event listeners
26
27
		$orderBaseProductManager = $orderBaseManager->getSubManager( 'product' );
28
		$search = $orderBaseProductManager->createSearch();
29
30
		$search->setConditions( $search->combine( '&&', array(
31
			$search->compare( '==', 'order.base.product.prodcode', array( 'CNE', 'CNC' ) ),
32
			$search->compare( '==', 'order.base.product.price', array( '600.00', '36.00' ) )
33
		) ) );
34
		$items = $orderBaseProductManager->searchItems( $search );
35
36
		if( count( $items ) < 2 ) {
37
			throw new \RuntimeException( 'Please fix the test data in your database.' );
38
		}
39
40
		foreach( $items as $item ) {
41
			$this->products[$item->getProductCode()] = $item;
42
		}
43
44
		$this->products['CNE']->setQuantity( 2 );
45
		$this->products['CNC']->setQuantity( 1 );
46
47
		$config = array(
48
			'min-value'=> array( 'EUR' => '75.00' ),
49
			'max-value'=> array( 'EUR' => '625.00' ),
50
			'min-products' => '2',
51
			'max-products' => 5
52
		);
53
54
		$pluginManager = \Aimeos\MShop\Plugin\Manager\Factory::createManager( \TestHelperMShop::getContext() );
55
		$plugin = $pluginManager->createItem();
56
		$plugin->setTypeId( 2 );
57
		$plugin->setProvider( 'BasketLimits' );
58
		$plugin->setConfig( $config );
59
		$plugin->setStatus( '1' );
60
61
		$this->object = new \Aimeos\MShop\Plugin\Provider\Order\BasketLimits( \TestHelperMShop::getContext(), $plugin );
62
	}
63
64
65
	protected function tearDown()
66
	{
67
		unset( $this->object );
68
		unset( $this->order );
69
	}
70
71
72
	public function testCheckConfigBE()
73
	{
74
		$attributes = array(
75
			'min-products' => '10',
76
			'max-products' => '100',
77
			'min-value' => ['EUR' => '100.00'],
78
			'max-value' => ['EUR' => '1000.00'],
79
		);
80
81
		$result = $this->object->checkConfigBE( $attributes );
82
83
		$this->assertEquals( 4, count( $result ) );
84
		$this->assertEquals( null, $result['min-products'] );
85
		$this->assertEquals( null, $result['max-products'] );
86
		$this->assertEquals( null, $result['min-value'] );
87
		$this->assertEquals( null, $result['max-value'] );
88
	}
89
90
91
	public function testGetConfigBE()
92
	{
93
		$list = $this->object->getConfigBE();
94
95
		$this->assertEquals( 4, count( $list ) );
96
		$this->assertArrayHasKey( 'min-products', $list );
97
		$this->assertArrayHasKey( 'max-products', $list );
98
		$this->assertArrayHasKey( 'min-value', $list );
99
		$this->assertArrayHasKey( 'max-value', $list );
100
101
		foreach( $list as $entry ) {
102
			$this->assertInstanceOf( '\Aimeos\MW\Criteria\Attribute\Iface', $entry );
103
		}
104
	}
105
106
107
	public function testRegister()
108
	{
109
		$this->object->register( $this->order );
110
	}
111
112
113
	public function testUpdate()
114
	{
115
		$this->products['CNE']->setQuantity( 4 );
116
		$this->order->addProduct( $this->products['CNE'] );
117
118
		$this->assertTrue( $this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT ) );
119
	}
120
121
122
	public function testUpdateMinProductsFails()
123
	{
124
		$this->order->addProduct( $this->products['CNC'] );
125
126
		$this->setExpectedException( '\\Aimeos\\MShop\\Plugin\\Provider\\Exception' );
127
		$this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT );
128
	}
129
130
131
	public function testUpdateMaxProductsFails()
132
	{
133
		$this->products['CNE']->setQuantity( 6 );
134
		$this->order->addProduct( $this->products['CNE'] );
135
136
		$this->setExpectedException( '\\Aimeos\\MShop\\Plugin\\Provider\\Exception' );
137
		$this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT );
138
	}
139
140
141
	public function testUpdateMinValueFails()
142
	{
143
		$this->order->addProduct( $this->products['CNE'] );
144
145
		$this->setExpectedException( '\\Aimeos\\MShop\\Plugin\\Provider\\Exception' );
146
		$this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT );
147
	}
148
149
150
	public function testUpdateMaxValueFails()
151
	{
152
		$this->products['CNC']->setQuantity( 2 );
153
		$this->order->addProduct( $this->products['CNC'] );
154
155
		$this->setExpectedException( '\\Aimeos\\MShop\\Plugin\\Provider\\Exception' );
156
		$this->object->update( $this->order, 'check.after', \Aimeos\MShop\Order\Item\Base\Base::PARTS_PRODUCT );
157
	}
158
}
159