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-2018 |
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 = $this->getMockBuilder( '\Aimeos\MShop\Service\Provider\Base' ) |
25
|
|
|
->setConstructorArgs( [$this->context, $serviceItem] ) |
26
|
|
|
->setMethods( null ) |
27
|
|
|
->getMock(); |
28
|
|
|
|
29
|
|
|
\Aimeos\MShop\Factory::setCache( true ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
protected function tearDown() |
34
|
|
|
{ |
35
|
|
|
\Aimeos\MShop\Factory::setCache( false ); |
36
|
|
|
|
37
|
|
|
unset( $this->object ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
public function testCalcDateLimit() |
42
|
|
|
{ |
43
|
|
|
$this->assertEquals( '2013-10-15', $this->access( 'calcDateLimit' )->invokeArgs( $this->object, [1382100000, 3] ) ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
public function testCalcDateLimitWeekdays() |
48
|
|
|
{ |
49
|
|
|
$this->assertEquals( '2013-10-18', $this->access( 'calcDateLimit' )->invokeArgs( $this->object, [1382186400, 0, true] ) ); |
50
|
|
|
$this->assertEquals( '2013-10-18', $this->access( 'calcDateLimit' )->invokeArgs( $this->object, [1382272800, 0, true] ) ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testCalcDateLimitHolidays() |
55
|
|
|
{ |
56
|
|
|
$result = $this->access( 'calcDateLimit' )->invokeArgs( $this->object, [1382100000, 0, false, '2013-10-17, 2013-10-18'] ); |
57
|
|
|
$this->assertEquals( '2013-10-16', $result ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testCheckConfigBE() |
62
|
|
|
{ |
63
|
|
|
$this->assertEquals( [], $this->object->checkConfigBE( [] ) ); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
public function testGetConfigValue() |
68
|
|
|
{ |
69
|
|
|
$this->object->injectGlobalConfigBE( ['payment.url-success' => 'https://url.to/ok'] ); |
70
|
|
|
$result = $this->access( 'getConfigValue' )->invokeArgs( $this->object, ['payment.url-success'] ); |
71
|
|
|
|
72
|
|
|
$this->assertEquals( 'https://url.to/ok', $result ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testQuery() |
77
|
|
|
{ |
78
|
|
|
$item = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->createItem(); |
79
|
|
|
|
80
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Service\\Exception' ); |
81
|
|
|
$this->object->query( $item ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testUpdateAsync() |
86
|
|
|
{ |
87
|
|
|
$this->assertFalse( $this->object->updateAsync() ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function testUpdatePush() |
92
|
|
|
{ |
93
|
|
|
$request = $this->getMockBuilder( '\Psr\Http\Message\ServerRequestInterface' )->getMock(); |
94
|
|
|
$response = $this->getMockBuilder( '\Psr\Http\Message\ResponseInterface' )->getMock(); |
95
|
|
|
|
96
|
|
|
$response->expects( $this->once() )->method( 'withStatus' )->will( $this->returnValue( $response ) ); |
97
|
|
|
|
98
|
|
|
$result = $this->object->updatePush( $request, $response ); |
99
|
|
|
|
100
|
|
|
$this->assertInstanceOf( '\Psr\Http\Message\ResponseInterface', $result ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
public function testUpdateSync() |
105
|
|
|
{ |
106
|
|
|
$orderItem = \Aimeos\MShop\Order\Manager\Factory::createManager( $this->context )->createItem(); |
107
|
|
|
$request = $this->getMockBuilder( '\Psr\Http\Message\ServerRequestInterface' )->getMock(); |
108
|
|
|
|
109
|
|
|
$result = $this->object->updateSync( $request, $orderItem ); |
110
|
|
|
|
111
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Order\Item\Iface', $result ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function testCheckConfigBoolean() |
116
|
|
|
{ |
117
|
|
|
$args = array( array( 'key' => array( 'type' => 'boolean', 'required' => true ) ), array( 'key' => '0' ) ); |
118
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
119
|
|
|
|
120
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
public function testCheckConfigBooleanInvalid() |
125
|
|
|
{ |
126
|
|
|
$args = array( array( 'key' => array( 'type' => 'boolean', 'required' => true ) ), array( 'key' => 'a' ) ); |
127
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
128
|
|
|
|
129
|
|
|
$this->assertEquals( array( 'key' => 'Not a true/false value' ), $result ); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
public function testCheckConfigString() |
134
|
|
|
{ |
135
|
|
|
$args = array( array( 'key' => array( 'type' => 'string', 'required' => true ) ), array( 'key' => 'abc' ) ); |
136
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
137
|
|
|
|
138
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
public function testCheckConfigStringInvalid() |
143
|
|
|
{ |
144
|
|
|
$args = array( array( 'key' => array( 'type' => 'string', 'required' => true ) ), array( 'key' => new \stdClass() ) ); |
145
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
146
|
|
|
|
147
|
|
|
$this->assertEquals( array( 'key' => 'Not a string' ), $result ); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
public function testCheckConfigInteger() |
152
|
|
|
{ |
153
|
|
|
$args = array( array( 'key' => array( 'type' => 'integer', 'required' => true ) ), array( 'key' => '123' ) ); |
154
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
155
|
|
|
|
156
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
public function testCheckConfigIntegerInvalid() |
161
|
|
|
{ |
162
|
|
|
$args = array( array( 'key' => array( 'type' => 'integer', 'required' => true ) ), array( 'key' => 'abc' ) ); |
163
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
164
|
|
|
|
165
|
|
|
$this->assertEquals( array( 'key' => 'Not an integer number' ), $result ); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
|
169
|
|
|
public function testCheckConfigNumber() |
170
|
|
|
{ |
171
|
|
|
$args = array( array( 'key' => array( 'type' => 'number', 'required' => true ) ), array( 'key' => '10.25' ) ); |
172
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
173
|
|
|
|
174
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
public function testCheckConfigNumberInvalid() |
179
|
|
|
{ |
180
|
|
|
$args = array( array( 'key' => array( 'type' => 'number', 'required' => true ) ), array( 'key' => 'abc' ) ); |
181
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
182
|
|
|
|
183
|
|
|
$this->assertEquals( array( 'key' => 'Not a number' ), $result ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
public function testCheckConfigDate() |
188
|
|
|
{ |
189
|
|
|
$args = array( array( 'key' => array( 'type' => 'date', 'required' => true ) ), array( 'key' => '2000-01-01' ) ); |
190
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
191
|
|
|
|
192
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
|
196
|
|
|
public function testCheckConfigDateInvalid() |
197
|
|
|
{ |
198
|
|
|
$args = array( array( 'key' => array( 'type' => 'date', 'required' => true ) ), array( 'key' => '01/01/2000' ) ); |
199
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
200
|
|
|
|
201
|
|
|
$this->assertEquals( array( 'key' => 'Not a date' ), $result ); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
public function testCheckConfigDatetime() |
206
|
|
|
{ |
207
|
|
|
$args = array( array( 'key' => array( 'type' => 'datetime', 'required' => true ) ), array( 'key' => '2000-01-01 00:00:00' ) ); |
208
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
209
|
|
|
|
210
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
|
214
|
|
|
public function testCheckConfigDatetimeInvalid() |
215
|
|
|
{ |
216
|
|
|
$args = array( array( 'key' => array( 'type' => 'datetime', 'required' => true ) ), array( 'key' => '01/01/2000' ) ); |
217
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
218
|
|
|
|
219
|
|
|
$this->assertEquals( array( 'key' => 'Not a date and time' ), $result ); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
|
223
|
|
|
public function testCheckConfigSelectList() |
224
|
|
|
{ |
225
|
|
|
$args = [['key' => ['type' => 'select', 'required' => true, 'default' => ['test' => 'val']]], ['key' => 'test']]; |
226
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
227
|
|
|
|
228
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
|
232
|
|
|
public function testCheckConfigSelectInvalid() |
233
|
|
|
{ |
234
|
|
|
$args = array( array( 'key' => array( 'type' => 'select', 'required' => true, 'default' => array( 'test' ) ) ), array( 'key' => 'test2' ) ); |
235
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
236
|
|
|
|
237
|
|
|
$this->assertEquals( array( 'key' => 'Not a listed value' ), $result ); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
|
241
|
|
|
public function testCheckConfigMap() |
242
|
|
|
{ |
243
|
|
|
$args = array( array( 'key' => array( 'type' => 'map', 'required' => true ) ), array( 'key' => array( 'a' => 'test' ) ) ); |
244
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
245
|
|
|
|
246
|
|
|
$this->assertEquals( array( 'key' => null ), $result ); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
|
250
|
|
|
public function testCheckConfigMapInvalid() |
251
|
|
|
{ |
252
|
|
|
$args = array( array( 'key' => array( 'type' => 'map', 'required' => true ) ), array( 'key' => 'test' ) ); |
253
|
|
|
$result = $this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
254
|
|
|
|
255
|
|
|
$this->assertEquals( array( 'key' => 'Not a key/value map' ), $result ); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
public function testCheckConfigInvalid() |
260
|
|
|
{ |
261
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Service\Exception' ); |
262
|
|
|
|
263
|
|
|
$args = array( array( 'key' => array( 'type' => 'invalid', 'required' => true ) ), array( 'key' => 'abc' ) ); |
264
|
|
|
$this->access( 'checkConfig' )->invokeArgs( $this->object, $args ); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
|
268
|
|
|
public function testGetCustomerData() |
269
|
|
|
{ |
270
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' ); |
271
|
|
|
$customerId = $manager->findItem( 'UTC001' )->getId(); |
272
|
|
|
|
273
|
|
|
$this->assertNull( $this->access( 'getCustomerData' )->invokeArgs( $this->object, ['token', $customerId, 2] ) ); |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
|
277
|
|
|
public function testSetCustomerData() |
278
|
|
|
{ |
279
|
|
|
$stub = $this->getMockBuilder( '\Aimeos\MShop\Customer\Manager\Lists\Standard' ) |
280
|
|
|
->setConstructorArgs( [$this->context] ) |
281
|
|
|
->setMethods( ['saveItem'] ) |
282
|
|
|
->getMock(); |
283
|
|
|
|
284
|
|
|
\Aimeos\MShop\Factory::injectManager( $this->context, 'customer/lists', $stub ); |
285
|
|
|
|
286
|
|
|
$stub->expects( $this->once() )->method( 'saveItem' ); |
287
|
|
|
|
288
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' ); |
289
|
|
|
$customerId = $manager->findItem( 'UTC001' )->getId(); |
290
|
|
|
|
291
|
|
|
$this->access( 'setCustomerData' )->invokeArgs( $this->object, ['token', $customerId, 2, 'abcd'] ); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
|
295
|
|
|
protected function access( $name ) |
296
|
|
|
{ |
297
|
|
|
$class = new \ReflectionClass( '\Aimeos\MShop\Service\Provider\Base' ); |
298
|
|
|
$method = $class->getMethod( $name ); |
299
|
|
|
$method->setAccessible( true ); |
300
|
|
|
|
301
|
|
|
return $method; |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
|