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 CategoryTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
private $orderBase; |
17
|
|
|
private $couponItem; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$orderProducts = []; |
23
|
|
|
$this->context = \TestHelperMShop::getContext(); |
24
|
|
|
$this->couponItem = \Aimeos\MShop\Coupon\Manager\Factory::createManager( $this->context )->createItem(); |
25
|
|
|
|
26
|
|
|
$provider = new \Aimeos\MShop\Coupon\Provider\Example( $this->context, $this->couponItem, 'abcd' ); |
27
|
|
|
$this->object = new \Aimeos\MShop\Coupon\Provider\Decorator\Category( $provider, $this->context, $this->couponItem, 'abcd'); |
28
|
|
|
$this->object->setObject( $this->object ); |
29
|
|
|
|
30
|
|
|
$priceManager = \Aimeos\MShop\Factory::createManager( $this->context, 'price' ); |
31
|
|
|
$productManager = \Aimeos\MShop\Factory::createManager( $this->context, 'product' ); |
32
|
|
|
$product = $productManager->findItem( 'CNC' ); |
33
|
|
|
|
34
|
|
|
$orderProductManager = \Aimeos\MShop\Factory::createManager( $this->context, 'order/base/product' ); |
35
|
|
|
$orderProduct = $orderProductManager->createItem(); |
36
|
|
|
$orderProduct->copyFrom( $product ); |
37
|
|
|
|
38
|
|
|
$this->orderBase = new \Aimeos\MShop\Order\Item\Base\Standard( $priceManager->createItem(), $this->context->getLocale() ); |
39
|
|
|
$this->orderBase->addProduct( $orderProduct ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
protected function tearDown() |
44
|
|
|
{ |
45
|
|
|
unset( $this->object ); |
46
|
|
|
unset( $this->orderBase ); |
47
|
|
|
unset( $this->couponItem ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testGetConfigBE() |
52
|
|
|
{ |
53
|
|
|
$result = $this->object->getConfigBE(); |
54
|
|
|
|
55
|
|
|
$this->assertArrayHasKey( 'category.catid', $result ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function testCheckConfigBE() |
60
|
|
|
{ |
61
|
|
|
$attributes = ['category.catid' => '123']; |
62
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( 1, count( $result ) ); |
65
|
|
|
$this->assertInternalType( 'null', $result['category.catid'] ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
public function testCheckConfigBEFailure() |
70
|
|
|
{ |
71
|
|
|
$result = $this->object->checkConfigBE( [] ); |
72
|
|
|
|
73
|
|
|
$this->assertEquals( 1, count( $result ) ); |
74
|
|
|
$this->assertInternalType( 'string', $result['category.catid'] ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testIsAvailable() |
79
|
|
|
{ |
80
|
|
|
$this->assertTrue( $this->object->isAvailable( $this->orderBase ) ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
public function testIsAvailableWithProduct() |
85
|
|
|
{ |
86
|
|
|
$this->couponItem->setConfig( array( 'category.catid' => $this->getCategory()->getId() ) ); |
87
|
|
|
|
88
|
|
|
$this->assertTrue( $this->object->isAvailable( $this->orderBase ) ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function testIsAvailableWithoutProduct() |
93
|
|
|
{ |
94
|
|
|
$this->couponItem->setConfig( array( 'category.catid' => $this->getCategory( 'tea' )->getId() ) ); |
95
|
|
|
|
96
|
|
|
$this->assertFalse( $this->object->isAvailable( $this->orderBase ) ); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
protected function getCategory( $code = 'cafe' ) |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'catalog' ); |
103
|
|
|
return $manager->findItem( $code ); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.