Completed
Push — master ( 207311...06e599 )
by Aimeos
09:29
created

BasketValuesTest::testGetConfigBE()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 9.4285
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\Decorator;
11
12
13
class BasketValuesTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $orderBase;
17
	private $couponItem;
18
19
20
	protected function setUp()
21
	{
22
		$orderProducts = [];
23
		$context = \TestHelperMShop::getContext();
24
25
		$couponManager = \Aimeos\MShop\Coupon\Manager\Factory::createManager( $context );
26
		$this->couponItem = $couponManager->createItem();
27
28
		$provider = new \Aimeos\MShop\Coupon\Provider\Example( $context, $this->couponItem, 'abcd' );
29
		$this->object = new \Aimeos\MShop\Coupon\Provider\Decorator\BasketValues( $provider, $context, $this->couponItem, 'abcd' );
30
		$this->object->setObject( $this->object );
31
32
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( $context );
33
		$orderBaseManager = $orderManager->getSubManager( 'base' );
34
		$orderProductManager = $orderBaseManager->getSubManager( 'product' );
35
36
		$productManager = \Aimeos\MShop\Product\Manager\Factory::createManager( $context );
37
		$search = $productManager->createSearch();
38
		$search->setConditions( $search->compare( '==', 'product.code', array( 'CNC' ) ) );
39
		$products = $productManager->searchItems( $search );
40
41
		$priceManager = \Aimeos\MShop\Price\Manager\Factory::createManager( $context );
42
		$price = $priceManager->createItem();
43
		$price->setValue( 321 );
44
45
		foreach( $products as $product )
46
		{
47
			$orderProduct = $orderProductManager->createItem();
48
			$orderProduct->copyFrom( $product );
49
			$orderProducts[$product->getCode()] = $orderProduct;
50
		}
51
52
		$orderProducts['CNC']->setPrice( $price );
53
54
		$this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard( $priceManager->createItem(), $context->getLocale() );
55
		$this->orderBase->addProduct( $orderProducts['CNC'] );
56
	}
57
58
59
	protected function tearDown()
60
	{
61
		unset( $this->object );
62
		unset( $this->orderBase );
63
		unset( $this->couponItem );
64
	}
65
66
67
	public function testGetConfigBE()
68
	{
69
		$result = $this->object->getConfigBE();
70
71
		$this->assertArrayHasKey( 'basketvalues.total-value-min', $result );
72
		$this->assertArrayHasKey( 'basketvalues.total-value-max', $result );
73
	}
74
75
76
	public function testCheckConfigBE()
77
	{
78
		$attributes = ['basketvalues.total-value-min' => '1.5', 'basketvalues.total-value-max' => '10'];
79
		$result = $this->object->checkConfigBE( $attributes );
80
81
		$this->assertEquals( 2, count( $result ) );
82
		$this->assertInternalType( 'null', $result['basketvalues.total-value-min'] );
83
		$this->assertInternalType( 'null', $result['basketvalues.total-value-max'] );
84
	}
85
86
87
	public function testCheckConfigBEFailure()
88
	{
89
		$result = $this->object->checkConfigBE( [] );
90
91
		$this->assertEquals( 2, count( $result ) );
92
		$this->assertInternalType( 'string', $result['basketvalues.total-value-min'] );
93
		$this->assertInternalType( 'string', $result['basketvalues.total-value-max'] );
94
	}
95
96
97
	public function testIsAvailable()
98
	{
99
		$config = array(
100
			'basketvalues.total-value-min' => array( 'EUR' =>  320 ),
101
			'basketvalues.total-value-max' => array( 'EUR' => 1000 ),
102
		);
103
104
		$this->couponItem->setConfig( $config );
105
		$result = $this->object->isAvailable( $this->orderBase );
106
107
		$this->assertTrue( $result );
108
	}
109
110
	// min value higher than order price
111
	public function testIsAvailableTestMinValue()
112
	{
113
		$config = array(
114
			'basketvalues.total-value-min' => array( 'EUR' =>  700 ),
115
			'basketvalues.total-value-max' => array( 'EUR' => 1000 ),
116
		);
117
118
		$this->couponItem->setConfig( $config );
119
		$result = $this->object->isAvailable( $this->orderBase );
120
121
		$this->assertFalse( $result );
122
	}
123
124
	// order price higher than max price
125
	public function testIsAvailableTestMaxValue()
126
	{
127
		$config = array(
128
			'basketvalues.total-value-min' => array( 'EUR' =>  50 ),
129
			'basketvalues.total-value-max' => array( 'EUR' => 320 ),
130
		);
131
132
		$this->couponItem->setConfig( $config );
133
		$result = $this->object->isAvailable( $this->orderBase );
134
135
		$this->assertFalse( $result );
136
	}
137
138
}
139