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\Service\Provider\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class TimeTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
private $object; |
15
|
|
|
private $basket; |
16
|
|
|
private $context; |
17
|
|
|
private $servItem; |
18
|
|
|
private $mockProvider; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->context = \TestHelperMShop::getContext(); |
24
|
|
|
|
25
|
|
|
$servManager = \Aimeos\MShop\Factory::createManager( $this->context, 'service' ); |
26
|
|
|
$this->servItem = $servManager->createItem(); |
27
|
|
|
|
28
|
|
|
$this->mockProvider = $this->getMockBuilder( '\\Aimeos\\MShop\\Service\\Provider\\Decorator\\Time' ) |
29
|
|
|
->disableOriginalConstructor()->getMock(); |
30
|
|
|
|
31
|
|
|
$this->basket = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context ) |
32
|
|
|
->getSubManager( 'base' )->createItem(); |
33
|
|
|
|
34
|
|
|
$this->object = new \Aimeos\MShop\Service\Provider\Decorator\Time( $this->mockProvider, $this->context, $this->servItem ); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
protected function tearDown() |
39
|
|
|
{ |
40
|
|
|
unset( $this->object, $this->basket, $this->mockProvider, $this->servItem, $this->context ); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
public function testGetConfigBE() |
45
|
|
|
{ |
46
|
|
|
$this->mockProvider->expects( $this->once() ) |
47
|
|
|
->method( 'getConfigBE' ) |
48
|
|
|
->will( $this->returnValue( [] ) ); |
49
|
|
|
|
50
|
|
|
$result = $this->object->getConfigBE(); |
51
|
|
|
|
52
|
|
|
$this->assertArrayHasKey( 'time.start', $result ); |
53
|
|
|
$this->assertArrayHasKey( 'time.end', $result ); |
54
|
|
|
$this->assertArrayHasKey( 'time.weekdays', $result ); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
public function testCheckConfigBE() |
59
|
|
|
{ |
60
|
|
|
$this->mockProvider->expects( $this->once() ) |
61
|
|
|
->method( 'checkConfigBE' ) |
62
|
|
|
->will( $this->returnValue( [] ) ); |
63
|
|
|
|
64
|
|
|
$attributes = array( |
65
|
|
|
'time.start' => '00:00', |
66
|
|
|
'time.end' => '23:59', |
67
|
|
|
'time.weekdays' => '1,2,3,4,5,6,7', |
68
|
|
|
); |
69
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
70
|
|
|
|
71
|
|
|
$this->assertEquals( 3, count( $result ) ); |
72
|
|
|
$this->assertInternalType( 'null', $result['time.start'] ); |
73
|
|
|
$this->assertInternalType( 'null', $result['time.end'] ); |
74
|
|
|
$this->assertInternalType( 'null', $result['time.weekdays'] ); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
public function testCheckConfigBENoConfig() |
79
|
|
|
{ |
80
|
|
|
$this->mockProvider->expects( $this->once() ) |
81
|
|
|
->method( 'checkConfigBE' ) |
82
|
|
|
->will( $this->returnValue( [] ) ); |
83
|
|
|
|
84
|
|
|
$result = $this->object->checkConfigBE( [] ); |
85
|
|
|
|
86
|
|
|
$this->assertEquals( 3, count( $result ) ); |
87
|
|
|
$this->assertInternalType( 'null', $result['time.start'] ); |
88
|
|
|
$this->assertInternalType( 'null', $result['time.end'] ); |
89
|
|
|
$this->assertInternalType( 'null', $result['time.weekdays'] ); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
public function testCheckConfigBEFailure() |
94
|
|
|
{ |
95
|
|
|
$this->mockProvider->expects( $this->once() ) |
96
|
|
|
->method( 'checkConfigBE' ) |
97
|
|
|
->will( $this->returnValue( [] ) ); |
98
|
|
|
|
99
|
|
|
$attributes = array( |
100
|
|
|
'time.start' => [], |
101
|
|
|
'time.end' => 1, |
102
|
|
|
'time.weekdays' => new \stdClass(), |
103
|
|
|
); |
104
|
|
|
$result = $this->object->checkConfigBE( $attributes ); |
105
|
|
|
|
106
|
|
|
$this->assertEquals( 3, count( $result ) ); |
107
|
|
|
$this->assertInternalType( 'string', $result['time.start'] ); |
108
|
|
|
$this->assertInternalType( 'string', $result['time.end'] ); |
109
|
|
|
$this->assertInternalType( 'string', $result['time.weekdays'] ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
|
113
|
|
|
public function testGetConfigFE() |
114
|
|
|
{ |
115
|
|
|
$orderManager = \Aimeos\MShop\Order\Manager\Factory::createManager( \TestHelperMShop::getContext() ); |
116
|
|
|
$orderBaseManager = $orderManager->getSubManager( 'base' ); |
117
|
|
|
$search = $orderManager->createSearch(); |
118
|
|
|
$expr = array( |
119
|
|
|
$search->compare( '==', 'order.type', \Aimeos\MShop\Order\Item\Base::TYPE_WEB ), |
120
|
|
|
$search->compare( '==', 'order.statuspayment', \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED ) |
121
|
|
|
); |
122
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
123
|
|
|
$orderItems = $orderManager->searchItems( $search ); |
124
|
|
|
|
125
|
|
|
if( ( $order = reset( $orderItems ) ) === false ) { |
126
|
|
|
throw new \RuntimeException( sprintf( 'No Order found with statuspayment "%1$s" and type "%2$s"', \Aimeos\MShop\Order\Item\Base::PAY_AUTHORIZED, \Aimeos\MShop\Order\Item\Base::TYPE_WEB ) ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
$this->mockProvider->expects( $this->once() )->method( 'getConfigFE' )->will( $this->returnValue( [] ) ); |
131
|
|
|
|
132
|
|
|
$basket = $orderBaseManager->load( $order->getBaseId(), \Aimeos\MShop\Order\Manager\Base\Base::PARTS_SERVICE ); |
133
|
|
|
$config = $this->object->getConfigFE( $basket ); |
134
|
|
|
|
135
|
|
|
$this->assertRegExp( '/[0-2][0-9]:[0-5][0-9]/', $config['time.hourminute']->getDefault() ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
public function testCheckConfigFE() |
140
|
|
|
{ |
141
|
|
|
$this->mockProvider->expects( $this->once() ) |
142
|
|
|
->method( 'checkConfigFE' ) |
143
|
|
|
->will( $this->returnValue( [] ) ); |
144
|
|
|
|
145
|
|
|
$config = array( 'time.hourminute' => '12:00' ); |
146
|
|
|
$expected = array( 'time.hourminute' => null ); |
147
|
|
|
|
148
|
|
|
$result = $this->object->checkConfigFE( $config ); |
149
|
|
|
|
150
|
|
|
$this->assertEquals( $expected, $result ); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
public function testCheckConfigFEshort() |
155
|
|
|
{ |
156
|
|
|
$this->mockProvider->expects( $this->once() ) |
157
|
|
|
->method( 'checkConfigFE' ) |
158
|
|
|
->will( $this->returnValue( [] ) ); |
159
|
|
|
|
160
|
|
|
$config = array( 'time.hourminute' => '9:00' ); |
161
|
|
|
$expected = array( 'time.hourminute' => null ); |
162
|
|
|
|
163
|
|
|
$result = $this->object->checkConfigFE( $config ); |
164
|
|
|
|
165
|
|
|
$this->assertEquals( $expected, $result ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
public function testCheckConfigFEwrongType() |
170
|
|
|
{ |
171
|
|
|
$this->mockProvider->expects( $this->once() ) |
172
|
|
|
->method( 'checkConfigFE' ) |
173
|
|
|
->will( $this->returnValue( [] ) ); |
174
|
|
|
|
175
|
|
|
$config = array( 'time.hourminute' => 0 ); |
176
|
|
|
$result = $this->object->checkConfigFE( $config ); |
177
|
|
|
|
178
|
|
|
$this->assertArrayHasKey( 'time.hourminute', $result ); |
179
|
|
|
$this->assertFalse( $result['time.hourminute'] === null ); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
public function testCheckConfigFEbefore() |
184
|
|
|
{ |
185
|
|
|
$this->mockProvider->expects( $this->once() ) |
186
|
|
|
->method( 'checkConfigFE' ) |
187
|
|
|
->will( $this->returnValue( [] ) ); |
188
|
|
|
|
189
|
|
|
$this->servItem->setConfig( ['time.start' => '10:00'] ); |
190
|
|
|
|
191
|
|
|
$config = array( 'time.hourminute' => '09:00' ); |
192
|
|
|
$result = $this->object->checkConfigFE( $config ); |
193
|
|
|
|
194
|
|
|
$this->assertArrayHasKey( 'time.hourminute', $result ); |
195
|
|
|
$this->assertFalse( $result['time.hourminute'] === null ); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
public function testCheckConfigFEafter() |
200
|
|
|
{ |
201
|
|
|
$this->mockProvider->expects( $this->once() ) |
202
|
|
|
->method( 'checkConfigFE' ) |
203
|
|
|
->will( $this->returnValue( [] ) ); |
204
|
|
|
|
205
|
|
|
$this->servItem->setConfig( ['time.end' => '18:00'] ); |
206
|
|
|
|
207
|
|
|
$config = array( 'time.hourminute' => '19:00' ); |
208
|
|
|
$result = $this->object->checkConfigFE( $config ); |
209
|
|
|
|
210
|
|
|
$this->assertArrayHasKey( 'time.hourminute', $result ); |
211
|
|
|
$this->assertFalse( $result['time.hourminute'] === null ); |
212
|
|
|
} |
213
|
|
|
} |