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
|
|
|
|