Completed
Push — master ( 91b879...2259ec )
by Aimeos
08:36
created

OnceTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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 OnceTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $context;
15
	private $orderBase;
16
	private $couponItem;
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelperMShop::getContext();
22
		$this->couponItem = \Aimeos\MShop\Factory::createManager( $this->context, 'coupon' )->createItem();
23
24
		$orderBaseManager = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base' );
25
		$search = $orderBaseManager->createSearch();
26
		$search->setConditions( $search->compare( '==', 'order.base.price', '4800.00' ) );
27
		$baskets = $orderBaseManager->searchItems( $search );
28
29
		if( ( $basket = reset( $baskets ) ) === false ) {
30
			throw new \RuntimeException( 'No order base with price "4800.00" found' );
31
		}
32
33
		$this->orderBase = $orderBaseManager->load( $basket->getId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_ADDRESS );
34
	}
35
36
37
	protected function tearDown()
38
	{
39
		unset( $this->context, $this->orderBase, $this->couponItem );
40
	}
41
42
43
	public function testIsAvailable()
44
	{
45
		$provider = new \Aimeos\MShop\Coupon\Provider\Example( $this->context, $this->couponItem, 'ABCD' );
46
		$object = new \Aimeos\MShop\Coupon\Provider\Decorator\Once( $provider, $this->context, $this->couponItem, 'ABCD');
47
		$object->setObject( $object );
48
49
		$this->assertTrue( $object->isAvailable( $this->orderBase ) );
50
	}
51
52
53
	public function testIsAvailableExisting()
54
	{
55
		$provider = new \Aimeos\MShop\Coupon\Provider\Example( $this->context, $this->couponItem, 'OPQR' );
56
		$object = new \Aimeos\MShop\Coupon\Provider\Decorator\Once( $provider, $this->context, $this->couponItem, 'OPQR');
57
		$object->setObject( $object );
58
59
		$this->assertFalse( $object->isAvailable( $this->orderBase ) );
60
	}
61
}
62