1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2013 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2017 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Service\Provider; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $context; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelperMShop::getContext(); |
22
|
|
|
$serviceItem = \Aimeos\MShop\Service\Manager\Factory::createManager( $this->context )->createItem(); |
23
|
|
|
|
24
|
|
|
$this->object = new TestBase( $this->context, $serviceItem ); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
protected function tearDown() |
29
|
|
|
{ |
30
|
|
|
unset( $this->object ); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
public function testCalcDateLimit() |
35
|
|
|
{ |
36
|
|
|
$this->assertEquals( '2013-10-15', $this->object->calcDateLimitPublic( 1382100000, 3 ) ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
public function testCalcDateLimitWeekdays() |
41
|
|
|
{ |
42
|
|
|
$this->assertEquals( '2013-10-18', $this->object->calcDateLimitPublic( 1382186400, 0, true ) ); |
43
|
|
|
$this->assertEquals( '2013-10-18', $this->object->calcDateLimitPublic( 1382272800, 0, true ) ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
public function testCalcDateLimitHolidays() |
48
|
|
|
{ |
49
|
|
|
$this->assertEquals( '2013-10-16', $this->object->calcDateLimitPublic( 1382100000, 0, false, '2013-10-17, 2013-10-18' ) ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
public function testCheckConfigBE() |
54
|
|
|
{ |
55
|
|
|
$this->assertEquals( [], $this->object->checkConfigBE( [] ) ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function testGetConfigValue() |
60
|
|
|
{ |
61
|
|
|
$this->object->injectGlobalConfigBE( array( 'payment.url-success' => 'https://url.to/ok' ) ); |
62
|
|
|
$this->assertEquals( 'https://url.to/ok', $this->object->getConfigValuePublic( array( 'payment.url-success' ) ) ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
public function testQuery() |
67
|
|
|
{ |
68
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->createItem(); |
69
|
|
|
|
70
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Service\\Exception' ); |
71
|
|
|
$this->object->query( $item ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testUpdateAsync() |
76
|
|
|
{ |
77
|
|
|
$this->assertFalse( $this->object->updateAsync() ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
public function testUpdatePush() |
82
|
|
|
{ |
83
|
|
|
$request = $this->getMockBuilder( '\Psr\Http\Message\ServerRequestInterface' )->getMock(); |
84
|
|
|
$response = $this->getMockBuilder( '\Psr\Http\Message\ResponseInterface' )->getMock(); |
85
|
|
|
|
86
|
|
|
$response->expects( $this->once() )->method( 'withStatus' )->will( $this->returnValue( $response ) ); |
87
|
|
|
|
88
|
|
|
$result = $this->object->updatePush( $request, $response ); |
89
|
|
|
|
90
|
|
|
$this->assertInstanceOf( '\Psr\Http\Message\ResponseInterface', $result ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
public function testUpdateSync() |
95
|
|
|
{ |
96
|
|
|
$response = null; $header = []; |
97
|
|
|
$result = $this->object->updateSync( [], 'body', $response, $header ); |
98
|
|
|
|
99
|
|
|
$this->assertEquals( null, $result ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
public function testCheckConfigBoolean() |
104
|
|
|
{ |
105
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
106
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
107
|
|
|
$method->setAccessible( true ); |
108
|
|
|
|
109
|
|
|
$args = array( array( 'key' => array( 'type' => 'boolean', 'required' => true ) ), array( 'key' => '0' ) ); |
110
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
111
|
|
|
|
112
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
public function testCheckConfigBooleanInvalid() |
117
|
|
|
{ |
118
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
119
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
120
|
|
|
$method->setAccessible( true ); |
121
|
|
|
|
122
|
|
|
$args = array( array( 'key' => array( 'type' => 'boolean', 'required' => true ) ), array( 'key' => 'a' ) ); |
123
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
124
|
|
|
|
125
|
|
|
$this->assertEquals( array( 'key' => 'Not a true/false value' ), $result ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
public function testCheckConfigString() |
130
|
|
|
{ |
131
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
132
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
133
|
|
|
$method->setAccessible( true ); |
134
|
|
|
|
135
|
|
|
$args = array( array( 'key' => array( 'type' => 'string', 'required' => true ) ), array( 'key' => 'abc' ) ); |
136
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
137
|
|
|
|
138
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
public function testCheckConfigStringInvalid() |
143
|
|
|
{ |
144
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
145
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
146
|
|
|
$method->setAccessible( true ); |
147
|
|
|
|
148
|
|
|
$args = array( array( 'key' => array( 'type' => 'string', 'required' => true ) ), array( 'key' => new \stdClass() ) ); |
149
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
150
|
|
|
|
151
|
|
|
$this->assertEquals( array( 'key' => 'Not a string' ), $result ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
public function testCheckConfigInteger() |
156
|
|
|
{ |
157
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
158
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
159
|
|
|
$method->setAccessible( true ); |
160
|
|
|
|
161
|
|
|
$args = array( array( 'key' => array( 'type' => 'integer', 'required' => true ) ), array( 'key' => '123' ) ); |
162
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
163
|
|
|
|
164
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
|
168
|
|
|
public function testCheckConfigIntegerInvalid() |
169
|
|
|
{ |
170
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
171
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
172
|
|
|
$method->setAccessible( true ); |
173
|
|
|
|
174
|
|
|
$args = array( array( 'key' => array( 'type' => 'integer', 'required' => true ) ), array( 'key' => 'abc' ) ); |
175
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
176
|
|
|
|
177
|
|
|
$this->assertEquals( array( 'key' => 'Not an integer number' ), $result ); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
public function testCheckConfigNumber() |
182
|
|
|
{ |
183
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
184
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
185
|
|
|
$method->setAccessible( true ); |
186
|
|
|
|
187
|
|
|
$args = array( array( 'key' => array( 'type' => 'number', 'required' => true ) ), array( 'key' => '10.25' ) ); |
188
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
189
|
|
|
|
190
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
public function testCheckConfigNumberInvalid() |
195
|
|
|
{ |
196
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
197
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
198
|
|
|
$method->setAccessible( true ); |
199
|
|
|
|
200
|
|
|
$args = array( array( 'key' => array( 'type' => 'number', 'required' => true ) ), array( 'key' => 'abc' ) ); |
201
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
202
|
|
|
|
203
|
|
|
$this->assertEquals( array( 'key' => 'Not a number' ), $result ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
public function testCheckConfigDate() |
208
|
|
|
{ |
209
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
210
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
211
|
|
|
$method->setAccessible( true ); |
212
|
|
|
|
213
|
|
|
$args = array( array( 'key' => array( 'type' => 'date', 'required' => true ) ), array( 'key' => '2000-01-01' ) ); |
214
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
215
|
|
|
|
216
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
public function testCheckConfigDateInvalid() |
221
|
|
|
{ |
222
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
223
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
224
|
|
|
$method->setAccessible( true ); |
225
|
|
|
|
226
|
|
|
$args = array( array( 'key' => array( 'type' => 'date', 'required' => true ) ), array( 'key' => '01/01/2000' ) ); |
227
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
228
|
|
|
|
229
|
|
|
$this->assertEquals( array( 'key' => 'Not a date' ), $result ); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
|
233
|
|
|
public function testCheckConfigDatetime() |
234
|
|
|
{ |
235
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
236
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
237
|
|
|
$method->setAccessible( true ); |
238
|
|
|
|
239
|
|
|
$args = array( array( 'key' => array( 'type' => 'datetime', 'required' => true ) ), array( 'key' => '2000-01-01 00:00:00' ) ); |
240
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
241
|
|
|
|
242
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
|
246
|
|
|
public function testCheckConfigDatetimeInvalid() |
247
|
|
|
{ |
248
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
249
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
250
|
|
|
$method->setAccessible( true ); |
251
|
|
|
|
252
|
|
|
$args = array( array( 'key' => array( 'type' => 'datetime', 'required' => true ) ), array( 'key' => '01/01/2000' ) ); |
253
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
254
|
|
|
|
255
|
|
|
$this->assertEquals( array( 'key' => 'Not a date and time' ), $result ); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
public function testCheckConfigSelectList() |
260
|
|
|
{ |
261
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
262
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
263
|
|
|
$method->setAccessible( true ); |
264
|
|
|
|
265
|
|
|
$args = [['key' => ['type' => 'select', 'required' => true, 'default' => ['test' => 'val']]], ['key' => 'test']]; |
266
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
267
|
|
|
|
268
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
|
272
|
|
|
public function testCheckConfigSelectInvalid() |
273
|
|
|
{ |
274
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
275
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
276
|
|
|
$method->setAccessible( true ); |
277
|
|
|
|
278
|
|
|
$args = array( array( 'key' => array( 'type' => 'select', 'required' => true, 'default' => array( 'test' ) ) ), array( 'key' => 'test2' ) ); |
279
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
280
|
|
|
|
281
|
|
|
$this->assertEquals( array( 'key' => 'Not a listed value' ), $result ); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
|
285
|
|
|
public function testCheckConfigMap() |
286
|
|
|
{ |
287
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
288
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
289
|
|
|
$method->setAccessible( true ); |
290
|
|
|
|
291
|
|
|
$args = array( array( 'key' => array( 'type' => 'map', 'required' => true ) ), array( 'key' => array( 'a' => 'test' ) ) ); |
292
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
293
|
|
|
|
294
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
|
298
|
|
|
public function testCheckConfigMapInvalid() |
299
|
|
|
{ |
300
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
301
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
302
|
|
|
$method->setAccessible( true ); |
303
|
|
|
|
304
|
|
|
$args = array( array( 'key' => array( 'type' => 'map', 'required' => true ) ), array( 'key' => 'test' ) ); |
305
|
|
|
$result = $method->invokeArgs( $this->object, $args ); |
306
|
|
|
|
307
|
|
|
$this->assertEquals( array( 'key' => 'Not a key/value map' ), $result ); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
|
311
|
|
|
public function testCheckConfigInvalid() |
312
|
|
|
{ |
313
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
314
|
|
|
$method = $class->getMethod( 'checkConfig' ); |
315
|
|
|
$method->setAccessible( true ); |
316
|
|
|
|
317
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Service\Exception' ); |
318
|
|
|
|
319
|
|
|
$args = array( array( 'key' => array( 'type' => 'invalid', 'required' => true ) ), array( 'key' => 'abc' ) ); |
320
|
|
|
$method->invokeArgs( $this->object, $args ); |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
|
325
|
|
|
class TestBase extends \Aimeos\MShop\Service\Provider\Base |
|
|
|
|
326
|
|
|
{ |
327
|
|
|
public function calcDateLimitPublic( $ts, $days = 0, $bd = false, $hd = '' ) |
328
|
|
|
{ |
329
|
|
|
return $this->calcDateLimit( $ts, $days, $bd, $hd ); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
public function getConfigValuePublic( array $keys ) |
333
|
|
|
{ |
334
|
|
|
return $this->getConfigValue( $keys ); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
public function setConfigFE( \Aimeos\MShop\Order\Item\Base\Service\Iface $orderServiceItem, array $attributes ) |
338
|
|
|
{ |
339
|
|
|
} |
340
|
|
|
} |
341
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.