1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Admin\JQAdm\Type\Price; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $object; |
16
|
|
|
private $view; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->view = \TestHelperJqadm::getView(); |
22
|
|
|
$this->context = \TestHelperJqadm::getContext(); |
23
|
|
|
|
24
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Type\Price\Standard( $this->context ); |
25
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context ); |
26
|
|
|
$this->object->setAimeos( \TestHelperJqadm::getAimeos() ); |
27
|
|
|
$this->object->setView( $this->view ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
protected function tearDown() |
32
|
|
|
{ |
33
|
|
|
unset( $this->object, $this->view, $this->context ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testCreate() |
38
|
|
|
{ |
39
|
|
|
$this->object->create(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function testCreateException() |
44
|
|
|
{ |
45
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
46
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
47
|
|
|
->setMethods( array( 'getSubClients' ) ) |
48
|
|
|
->getMock(); |
49
|
|
|
|
50
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
51
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
52
|
|
|
|
53
|
|
|
$object->setView( $this->getViewNoRender() ); |
54
|
|
|
|
55
|
|
|
$object->create(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function testCreateMShopException() |
60
|
|
|
{ |
61
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
62
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
63
|
|
|
->setMethods( array( 'getSubClients' ) ) |
64
|
|
|
->getMock(); |
65
|
|
|
|
66
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
67
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
68
|
|
|
|
69
|
|
|
$object->setView( $this->getViewNoRender() ); |
70
|
|
|
|
71
|
|
|
$object->create(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testCopy() |
76
|
|
|
{ |
77
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'price/type' ); |
78
|
|
|
|
79
|
|
|
$param = ['type' => 'unittest', 'id' => $manager->findItem( 'default', [], 'product' )->getId()]; |
80
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
81
|
|
|
$this->view->addHelper( 'param', $helper ); |
82
|
|
|
|
83
|
|
|
$result = $this->object->copy(); |
84
|
|
|
|
85
|
|
|
$this->assertContains( 'default', $result ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
public function testCopyException() |
90
|
|
|
{ |
91
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
92
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
93
|
|
|
->setMethods( array( 'getSubClients' ) ) |
94
|
|
|
->getMock(); |
95
|
|
|
|
96
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
97
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
98
|
|
|
|
99
|
|
|
$object->setView( $this->getViewNoRender() ); |
100
|
|
|
|
101
|
|
|
$object->copy(); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function testCopyMShopException() |
106
|
|
|
{ |
107
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
108
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
109
|
|
|
->setMethods( array( 'getSubClients' ) ) |
110
|
|
|
->getMock(); |
111
|
|
|
|
112
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
113
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
114
|
|
|
|
115
|
|
|
$object->setView( $this->getViewNoRender() ); |
116
|
|
|
|
117
|
|
|
$object->copy(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
public function testDelete() |
122
|
|
|
{ |
123
|
|
|
$this->assertNull( $this->getClientMock( 'getSubClients' )->delete() ); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function testDeleteJqadmException() |
128
|
|
|
{ |
129
|
|
|
$object = $this->getClientMock( ['getSubClients', 'search'] ); |
130
|
|
|
|
131
|
|
|
$object->expects( $this->once() )->method( 'search' ); |
132
|
|
|
|
133
|
|
|
$object->delete(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
public function testDeleteException() |
138
|
|
|
{ |
139
|
|
|
$object = $this->getClientMock( ['getSubClients', 'search'] ); |
140
|
|
|
|
141
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
142
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
143
|
|
|
$object->expects( $this->once() )->method( 'search' ); |
144
|
|
|
|
145
|
|
|
$object->delete(); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
|
149
|
|
|
public function testDeleteMShopException() |
150
|
|
|
{ |
151
|
|
|
$object = $this->getClientMock( ['getSubClients', 'search'] ); |
152
|
|
|
|
153
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
154
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
155
|
|
|
$object->expects( $this->once() )->method( 'search' ); |
156
|
|
|
|
157
|
|
|
$object->delete(); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
|
161
|
|
|
public function testGet() |
162
|
|
|
{ |
163
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'price/type' ); |
164
|
|
|
|
165
|
|
|
$param = ['type' => 'unittest', 'id' => $manager->findItem( 'default', [], 'product' )->getId()]; |
166
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
167
|
|
|
$this->view->addHelper( 'param', $helper ); |
168
|
|
|
|
169
|
|
|
$result = $this->object->get(); |
170
|
|
|
|
171
|
|
|
$this->assertContains( 'default', $result ); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
|
175
|
|
|
public function testGetException() |
176
|
|
|
{ |
177
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
178
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
179
|
|
|
->setMethods( array( 'getSubClients' ) ) |
180
|
|
|
->getMock(); |
181
|
|
|
|
182
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
183
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
184
|
|
|
|
185
|
|
|
$object->setView( $this->getViewNoRender() ); |
186
|
|
|
|
187
|
|
|
$object->get(); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
public function testGetMShopException() |
192
|
|
|
{ |
193
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
194
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
195
|
|
|
->setMethods( array( 'getSubClients' ) ) |
196
|
|
|
->getMock(); |
197
|
|
|
|
198
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
199
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
200
|
|
|
|
201
|
|
|
$object->setView( $this->getViewNoRender() ); |
202
|
|
|
|
203
|
|
|
$object->get(); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
public function testGetViewException() |
208
|
|
|
{ |
209
|
|
|
$object = new \Aimeos\Admin\JQAdm\Type\Price\Standard( $this->context, [] ); |
|
|
|
|
210
|
|
|
|
211
|
|
|
$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class ); |
212
|
|
|
$object->getView(); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
|
216
|
|
|
public function testSave() |
217
|
|
|
{ |
218
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'price/type' ); |
219
|
|
|
|
220
|
|
|
$param = array( |
221
|
|
|
'type' => 'unittest', |
222
|
|
|
'item' => array( |
223
|
|
|
'price.type.id' => '', |
224
|
|
|
'price.type.status' => '1', |
225
|
|
|
'price.type.domain' => 'price', |
226
|
|
|
'price.type.code' => 'jqadm@test', |
227
|
|
|
'price.type.label' => 'jqadm test', |
228
|
|
|
), |
229
|
|
|
); |
230
|
|
|
|
231
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
232
|
|
|
$this->view->addHelper( 'param', $helper ); |
233
|
|
|
|
234
|
|
|
$this->object->save(); |
235
|
|
|
|
236
|
|
|
$manager->deleteItem( $manager->findItem( 'jqadm@test', [], 'price' )->getId() ); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
|
240
|
|
|
public function testSaveException() |
241
|
|
|
{ |
242
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
243
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
244
|
|
|
->setMethods( array( 'fromArray' ) ) |
245
|
|
|
->getMock(); |
246
|
|
|
|
247
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
248
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
249
|
|
|
|
250
|
|
|
$object->setView( $this->getViewNoRender() ); |
251
|
|
|
|
252
|
|
|
$object->save(); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
|
256
|
|
|
public function testSaveMShopException() |
257
|
|
|
{ |
258
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
259
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
260
|
|
|
->setMethods( array( 'fromArray' ) ) |
261
|
|
|
->getMock(); |
262
|
|
|
|
263
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
264
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
265
|
|
|
|
266
|
|
|
$object->setView( $this->getViewNoRender() ); |
267
|
|
|
|
268
|
|
|
$object->save(); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
|
272
|
|
|
public function testSaveJQAdmException() |
273
|
|
|
{ |
274
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
275
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
276
|
|
|
->setMethods( array( 'fromArray' ) ) |
277
|
|
|
->getMock(); |
278
|
|
|
|
279
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
280
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
281
|
|
|
|
282
|
|
|
$object->setView( $this->getViewNoRender() ); |
283
|
|
|
|
284
|
|
|
$object->save(); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
|
288
|
|
|
public function testSearch() |
289
|
|
|
{ |
290
|
|
|
$param = array( |
291
|
|
|
'type' => 'unittest', 'lang' => 'de', |
292
|
|
|
'filter' => array( |
293
|
|
|
'key' => array( 0 => 'price.type.code' ), |
294
|
|
|
'op' => array( 0 => '==' ), |
295
|
|
|
'val' => array( 0 => 'default' ), |
296
|
|
|
), |
297
|
|
|
'sort' => array( '-price.type.id' ), |
298
|
|
|
); |
299
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
300
|
|
|
$this->view->addHelper( 'param', $helper ); |
301
|
|
|
|
302
|
|
|
$result = $this->object->search(); |
303
|
|
|
|
304
|
|
|
$this->assertContains( '>default<', $result ); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
|
308
|
|
|
public function testSearchException() |
309
|
|
|
{ |
310
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
311
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
312
|
|
|
->setMethods( array( 'initCriteria' ) ) |
313
|
|
|
->getMock(); |
314
|
|
|
|
315
|
|
|
$object->expects( $this->once() )->method( 'initCriteria' ) |
316
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
317
|
|
|
|
318
|
|
|
$object->setView( $this->getViewNoRender() ); |
319
|
|
|
|
320
|
|
|
$object->search(); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
|
324
|
|
|
public function testSearchMShopException() |
325
|
|
|
{ |
326
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
327
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
328
|
|
|
->setMethods( array( 'initCriteria' ) ) |
329
|
|
|
->getMock(); |
330
|
|
|
|
331
|
|
|
$object->expects( $this->once() )->method( 'initCriteria' ) |
332
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
333
|
|
|
|
334
|
|
|
$object->setView( $this->getViewNoRender() ); |
335
|
|
|
|
336
|
|
|
$object->search(); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
|
340
|
|
|
public function testGetSubClientInvalid() |
341
|
|
|
{ |
342
|
|
|
$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class ); |
343
|
|
|
$this->object->getSubClient( '$unknown$' ); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
|
347
|
|
|
public function testGetSubClientUnknown() |
348
|
|
|
{ |
349
|
|
|
$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class ); |
350
|
|
|
$this->object->getSubClient( 'unknown' ); |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
|
354
|
|
|
public function getClientMock( $methods ) |
355
|
|
|
{ |
356
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Type\Price\Standard::class ) |
357
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
358
|
|
|
->setMethods( (array) $methods ) |
359
|
|
|
->getMock(); |
360
|
|
|
|
361
|
|
|
$object->setAimeos( \TestHelperJqadm::getAimeos() ); |
362
|
|
|
$object->setView( $this->getViewNoRender() ); |
363
|
|
|
|
364
|
|
|
return $object; |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
|
368
|
|
|
protected function getViewNoRender() |
369
|
|
|
{ |
370
|
|
|
$view = $this->getMockBuilder( \Aimeos\MW\View\Standard::class ) |
371
|
|
|
->setConstructorArgs( array( [] ) ) |
372
|
|
|
->setMethods( array( 'render', 'config' ) ) |
373
|
|
|
->getMock(); |
374
|
|
|
|
375
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'price/type' ); |
376
|
|
|
|
377
|
|
|
$param = ['type' => 'unittest', 'id' => $manager->findItem( 'default', [], 'product' )->getId()]; |
378
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
379
|
|
|
$view->addHelper( 'param', $helper ); |
380
|
|
|
|
381
|
|
|
$helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, [] ); |
382
|
|
|
$view->addHelper( 'access', $helper ); |
383
|
|
|
|
384
|
|
|
return $view; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
} |
388
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths