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\Locale; |
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\Locale\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->getClientMock( 'getSubClients' ); |
46
|
|
|
|
47
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
48
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
49
|
|
|
|
50
|
|
|
$object->create(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testCreateMShopException() |
55
|
|
|
{ |
56
|
|
|
$object = $this->getClientMock( 'getSubClients' ); |
57
|
|
|
|
58
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
59
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
60
|
|
|
|
61
|
|
|
$object->create(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testCopy() |
66
|
|
|
{ |
67
|
|
|
$param = ['site' => 'unittest', 'id' => $this->getItem( 'de', 'EUR' )->getId()]; |
68
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
69
|
|
|
$this->view->addHelper( 'param', $helper ); |
70
|
|
|
|
71
|
|
|
$result = $this->object->copy(); |
72
|
|
|
|
73
|
|
|
$this->assertContains( 'EUR', $result ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
public function testCopyException() |
78
|
|
|
{ |
79
|
|
|
$object = $this->getClientMock( 'getSubClients' ); |
80
|
|
|
|
81
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
82
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
83
|
|
|
|
84
|
|
|
$object->copy(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
public function testCopyMShopException() |
89
|
|
|
{ |
90
|
|
|
$object = $this->getClientMock( 'getSubClients' ); |
91
|
|
|
|
92
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
93
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
94
|
|
|
|
95
|
|
|
$object->copy(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function testDelete() |
100
|
|
|
{ |
101
|
|
|
$this->assertNull( $this->getClientMock( 'getSubClients' )->delete() ); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
105
|
|
|
public function testDeleteJqadmException() |
106
|
|
|
{ |
107
|
|
|
$object = $this->getClientMock( ['getSubClients', 'search'] ); |
108
|
|
|
|
109
|
|
|
$object->expects( $this->once() )->method( 'search' ); |
110
|
|
|
|
111
|
|
|
$object->delete(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
|
115
|
|
|
public function testDeleteException() |
116
|
|
|
{ |
117
|
|
|
$object = $this->getClientMock( ['getSubClients', 'search'] ); |
118
|
|
|
|
119
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
120
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
121
|
|
|
$object->expects( $this->once() )->method( 'search' ); |
122
|
|
|
|
123
|
|
|
$object->delete(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function testDeleteMShopException() |
128
|
|
|
{ |
129
|
|
|
$object = $this->getClientMock( ['getSubClients', 'search'] ); |
130
|
|
|
|
131
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
132
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
133
|
|
|
$object->expects( $this->once() )->method( 'search' ); |
134
|
|
|
|
135
|
|
|
$object->delete(); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
public function testGet() |
140
|
|
|
{ |
141
|
|
|
$param = ['site' => 'unittest', 'id' => $this->getItem( 'de', 'EUR' )->getId()]; |
142
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
143
|
|
|
$this->view->addHelper( 'param', $helper ); |
144
|
|
|
|
145
|
|
|
$result = $this->object->get(); |
146
|
|
|
|
147
|
|
|
$this->assertContains( 'EUR', $result ); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
public function testGetException() |
152
|
|
|
{ |
153
|
|
|
$object = $this->getClientMock( 'getSubClients' ); |
154
|
|
|
|
155
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
156
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
157
|
|
|
|
158
|
|
|
$object->get(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
public function testGetMShopException() |
163
|
|
|
{ |
164
|
|
|
$object = $this->getClientMock( 'getSubClients' ); |
165
|
|
|
|
166
|
|
|
$object->expects( $this->once() )->method( 'getSubClients' ) |
167
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
168
|
|
|
|
169
|
|
|
$object->get(); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function testGetViewException() |
174
|
|
|
{ |
175
|
|
|
$object = new \Aimeos\Admin\JQAdm\Locale\Standard( $this->context, [] ); |
|
|
|
|
176
|
|
|
|
177
|
|
|
$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class ); |
178
|
|
|
$object->getView(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
public function testSave() |
183
|
|
|
{ |
184
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'locale' ); |
185
|
|
|
|
186
|
|
|
$param = array( |
187
|
|
|
'site' => 'unittest', |
188
|
|
|
'item' => array( |
189
|
|
|
'locale.id' => '', |
190
|
|
|
'locale.status' => '1', |
191
|
|
|
'locale.languageid' => 'da', |
192
|
|
|
'locale.currencyid' => 'DKK', |
193
|
|
|
'locale.position' => '0', |
194
|
|
|
), |
195
|
|
|
); |
196
|
|
|
|
197
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
198
|
|
|
$this->view->addHelper( 'param', $helper ); |
199
|
|
|
|
200
|
|
|
$this->object->save(); |
201
|
|
|
|
202
|
|
|
$manager->deleteItem( $this->getItem( 'da', 'DKK' )->getId() ); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
public function testSaveException() |
207
|
|
|
{ |
208
|
|
|
$object = $this->getClientMock( 'fromArray' ); |
209
|
|
|
|
210
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
211
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
212
|
|
|
|
213
|
|
|
$object->save(); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
|
217
|
|
|
public function testSaveMShopException() |
218
|
|
|
{ |
219
|
|
|
$object = $this->getClientMock( 'fromArray' ); |
220
|
|
|
|
221
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
222
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
223
|
|
|
|
224
|
|
|
$object->save(); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
|
228
|
|
|
public function testSaveJQAdmException() |
229
|
|
|
{ |
230
|
|
|
$object = $this->getClientMock( 'fromArray' ); |
231
|
|
|
|
232
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
233
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
234
|
|
|
|
235
|
|
|
$object->save(); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
|
239
|
|
|
public function testSearch() |
240
|
|
|
{ |
241
|
|
|
$param = array( |
242
|
|
|
'site' => 'unittest', 'lang' => 'de', |
243
|
|
|
'filter' => array( |
244
|
|
|
'key' => array( 0 => 'locale.languageid' ), |
245
|
|
|
'op' => array( 0 => '==' ), |
246
|
|
|
'val' => array( 0 => 'de' ), |
247
|
|
|
), |
248
|
|
|
'sort' => array( 'locale.position', '-locale.id' ), |
249
|
|
|
); |
250
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param ); |
251
|
|
|
$this->view->addHelper( 'param', $helper ); |
252
|
|
|
|
253
|
|
|
$result = $this->object->search(); |
254
|
|
|
|
255
|
|
|
$this->assertContains( '>EUR<', $result ); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
|
259
|
|
|
public function testSearchException() |
260
|
|
|
{ |
261
|
|
|
$object = $this->getClientMock( 'initCriteria' ); |
262
|
|
|
|
263
|
|
|
$object->expects( $this->once() )->method( 'initCriteria' ) |
264
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
265
|
|
|
|
266
|
|
|
$object->search(); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
public function testSearchMShopException() |
271
|
|
|
{ |
272
|
|
|
$object = $this->getClientMock( 'initCriteria' ); |
273
|
|
|
|
274
|
|
|
$object->expects( $this->once() )->method( 'initCriteria' ) |
275
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
276
|
|
|
|
277
|
|
|
$object->search(); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
|
281
|
|
|
public function testGetSubClientInvalid() |
282
|
|
|
{ |
283
|
|
|
$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class ); |
284
|
|
|
$this->object->getSubClient( '$unknown$' ); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
|
288
|
|
|
public function testGetSubClientUnknown() |
289
|
|
|
{ |
290
|
|
|
$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class ); |
291
|
|
|
$this->object->getSubClient( 'unknown' ); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
|
295
|
|
|
public function getClientMock( $methods ) |
296
|
|
|
{ |
297
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Locale\Standard::class ) |
298
|
|
|
->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) ) |
299
|
|
|
->setMethods( (array) $methods ) |
300
|
|
|
->getMock(); |
301
|
|
|
|
302
|
|
|
$object->setAimeos( \TestHelperJqadm::getAimeos() ); |
303
|
|
|
$object->setView( $this->getViewNoRender() ); |
304
|
|
|
|
305
|
|
|
return $object; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
|
309
|
|
|
protected function getViewNoRender() |
310
|
|
|
{ |
311
|
|
|
$view = $this->getMockBuilder( \Aimeos\MW\View\Standard::class ) |
312
|
|
|
->setConstructorArgs( array( [] ) ) |
313
|
|
|
->setMethods( array( 'render', 'config' ) ) |
314
|
|
|
->getMock(); |
315
|
|
|
|
316
|
|
|
$param = ['site' => 'unittest', 'id' => $this->getItem()->getId()]; |
317
|
|
|
$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param ); |
318
|
|
|
$view->addHelper( 'param', $helper ); |
319
|
|
|
|
320
|
|
|
$helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, [] ); |
321
|
|
|
$view->addHelper( 'access', $helper ); |
322
|
|
|
|
323
|
|
|
return $view; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
|
327
|
|
|
protected function getItem( $langid = null, $currid = null ) |
328
|
|
|
{ |
329
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'locale' ); |
330
|
|
|
|
331
|
|
|
$search = $manager->createSearch(); |
332
|
|
|
$search->setSlice( 0, 1 ); |
333
|
|
|
|
334
|
|
|
$expr = []; |
335
|
|
|
|
336
|
|
|
if( $langid ) { |
337
|
|
|
$expr[] = $search->compare( '==', 'locale.languageid', $langid ); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
if( $currid ) { |
341
|
|
|
$expr[] = $search->compare( '==', 'locale.currencyid', $currid ); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
$search->setConditions( $search->combine( '&&', $expr ) ); |
345
|
|
|
|
346
|
|
|
$items = $manager->searchItems( $search ); |
347
|
|
|
|
348
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
349
|
|
|
throw new \Exception( sprintf( 'No locale found' ) ); |
350
|
|
|
} |
351
|
|
|
|
352
|
|
|
return $item; |
353
|
|
|
} |
354
|
|
|
} |
355
|
|
|
|
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