1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2020 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Service\Provider\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class FreeTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $context; |
16
|
|
|
private $servItem; |
17
|
|
|
private $mockProvider; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
protected function setUp() : void |
21
|
|
|
{ |
22
|
|
|
$this->context = \TestHelperMShop::getContext(); |
23
|
|
|
|
24
|
|
|
$servManager = \Aimeos\MShop\Service\Manager\Factory::create( $this->context ); |
25
|
|
|
$this->servItem = $servManager->createItem(); |
26
|
|
|
|
27
|
|
|
$this->mockProvider = $this->getMockBuilder( \Aimeos\MShop\Service\Provider\Decorator\Example::class ) |
28
|
|
|
->disableOriginalConstructor()->getMock(); |
29
|
|
|
|
30
|
|
|
$this->object = new \Aimeos\MShop\Service\Provider\Decorator\Free( $this->mockProvider, $this->context, $this->servItem ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
protected function tearDown() : void |
35
|
|
|
{ |
36
|
|
|
\Aimeos\MShop\Order\Manager\Factory::injectManager( '\Aimeos\MShop\Order\Manager\StandardMock', null ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function testGetConfigBE() |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$this->mockProvider->expects( $this->once() )->method( 'getConfigBE' )->will( $this->returnValue( [] ) ); |
43
|
|
|
|
44
|
|
|
$result = $this->object->getConfigBE(); |
45
|
|
|
|
46
|
|
|
$this->assertArrayHasKey( 'free.show', $result ); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
public function testCheckConfigBEOK() |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$this->mockProvider->expects( $this->once() ) |
53
|
|
|
->method( 'checkConfigBE' ) |
54
|
|
|
->will( $this->returnValue( [] ) ); |
55
|
|
|
|
56
|
|
|
$attributes = array( 'free.show' => '1' ); |
57
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
58
|
|
|
|
59
|
|
|
$this->assertEquals( 1, count( $result ) ); |
60
|
|
|
$this->assertNull( $result['free.show'] ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testCheckConfigBEFailure() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$this->mockProvider->expects( $this->once() ) |
67
|
|
|
->method( 'checkConfigBE' ) |
68
|
|
|
->will( $this->returnValue( [] ) ); |
69
|
|
|
|
70
|
|
|
$attributes = array( 'free.show' => [] ); |
71
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
72
|
|
|
|
73
|
|
|
$this->assertEquals( 1, count( $result ) ); |
74
|
|
|
$this->assertIsString( $result['free.show'] ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testIsAvailable() |
79
|
|
|
{ |
80
|
|
|
$this->servItem->setConfig( array( 'free.show' => '1' ) ); |
81
|
|
|
$basket = \Aimeos\MShop::create( $this->context, 'order/base' )->createItem()->off(); |
82
|
|
|
|
83
|
|
|
$this->mockProvider->expects( $this->once() )->method( 'isAvailable' )->will( $this->returnValue( true ) ); |
84
|
|
|
|
85
|
|
|
$this->assertTrue( $this->object->isAvailable( $basket ) ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testIsAvailableNotZero() |
90
|
|
|
{ |
91
|
|
|
$this->servItem->setConfig( array( 'free.show' => '1' ) ); |
92
|
|
|
$basket = \Aimeos\MShop::create( $this->context, 'order/base' )->createItem()->off(); |
93
|
|
|
$basket->getPrice()->setValue( '0.01' ); |
94
|
|
|
|
95
|
|
|
$this->mockProvider->expects( $this->once() )->method( 'isAvailable' )->will( $this->returnValue( true ) ); |
96
|
|
|
|
97
|
|
|
$this->assertTrue( $this->object->isAvailable( $basket ) ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function testIsNotAvailableHidden() |
102
|
|
|
{ |
103
|
|
|
$this->servItem->setConfig( array( 'free.show' => '0' ) ); |
104
|
|
|
$basket = \Aimeos\MShop::create( $this->context, 'order/base' )->createItem()->off(); |
105
|
|
|
|
106
|
|
|
$this->assertFalse( $this->object->isAvailable( $basket ) ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
public function testIsAvailableHiddenNotZero() |
111
|
|
|
{ |
112
|
|
|
$this->servItem->setConfig( array( 'free.show' => '0' ) ); |
113
|
|
|
$basket = \Aimeos\MShop::create( $this->context, 'order/base' )->createItem()->off(); |
114
|
|
|
$basket->getPrice()->setValue( '0.01' ); |
115
|
|
|
|
116
|
|
|
$this->mockProvider->expects( $this->once() )->method( 'isAvailable' )->will( $this->returnValue( true ) ); |
117
|
|
|
|
118
|
|
|
$this->assertTrue( $this->object->isAvailable( $basket ) ); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
This check looks for method names that are not written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes
databaseConnectionSeeker
.