Passed
Push — master ( 154e9f...c95a25 )
by Aimeos
03:44
created

StandardTest::testDeleteJqadmException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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\Language;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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\Language\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
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, ['id' => 'de'] );
68
		$this->view->addHelper( 'param', $helper );
69
70
		$result = $this->object->copy();
71
72
		$this->assertContains( 'German', $result );
73
	}
74
75
76
	public function testCopyException()
77
	{
78
		$object = $this->getClientMock( 'getSubClients' );
79
80
		$object->expects( $this->once() )->method( 'getSubClients' )
81
			->will( $this->throwException( new \RuntimeException() ) );
82
83
		$object->copy();
84
	}
85
86
87
	public function testCopyMShopException()
88
	{
89
		$object = $this->getClientMock( 'getSubClients' );
90
91
		$object->expects( $this->once() )->method( 'getSubClients' )
92
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
93
94
		$object->copy();
95
	}
96
97
98
	public function testDelete()
99
	{
100
		$this->assertNull( $this->getClientMock( 'getSubClients' )->delete() );
101
	}
102
103
104
	public function testDeleteJqadmException()
105
	{
106
		$object = $this->getClientMock( ['getSubClients', 'search'] );
107
108
		$object->expects( $this->once() )->method( 'search' );
109
110
		$object->delete();
111
	}
112
113
114
	public function testDeleteException()
115
	{
116
		$object = $this->getClientMock( ['getSubClients', 'search'] );
117
118
		$object->expects( $this->once() )->method( 'getSubClients' )
119
			->will( $this->throwException( new \RuntimeException() ) );
120
		$object->expects( $this->once() )->method( 'search' );
121
122
		$object->delete();
123
	}
124
125
126
	public function testDeleteMShopException()
127
	{
128
		$object = $this->getClientMock( ['getSubClients', 'search'] );
129
130
		$object->expects( $this->once() )->method( 'getSubClients' )
131
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
132
		$object->expects( $this->once() )->method( 'search' );
133
134
		$object->delete();
135
	}
136
137
138
	public function testGet()
139
	{
140
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, ['id' => 'de'] );
141
		$this->view->addHelper( 'param', $helper );
142
143
		$result = $this->object->get();
144
145
		$this->assertContains( 'de', $result );
146
	}
147
148
149
	public function testGetException()
150
	{
151
		$object = $this->getClientMock( 'getSubClients' );
152
153
		$object->expects( $this->once() )->method( 'getSubClients' )
154
			->will( $this->throwException( new \RuntimeException() ) );
155
156
		$object->get();
157
	}
158
159
160
	public function testGetMShopException()
161
	{
162
		$object = $this->getClientMock( 'getSubClients' );
163
164
		$object->expects( $this->once() )->method( 'getSubClients' )
165
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
166
167
		$object->get();
168
	}
169
170
171
	public function testGetViewException()
172
	{
173
		$object = new \Aimeos\Admin\JQAdm\Locale\Language\Standard( $this->context, [] );
0 ignored issues
show
Unused Code introduced by
The call to Aimeos\Admin\JQAdm\Local...Standard::__construct() has too many arguments starting with array(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

173
		$object = /** @scrutinizer ignore-call */ new \Aimeos\Admin\JQAdm\Locale\Language\Standard( $this->context, [] );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
174
175
		$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class );
176
		$object->getView();
177
	}
178
179
180
	public function testSave()
181
	{
182
		$manager = \Aimeos\MShop::create( $this->context, 'locale/language' );
183
184
		$param = array(
185
			'item' => array(
186
				'locale.language.id' => '',
187
				'locale.language.status' => '1',
188
				'locale.language.code' => 'xx',
189
				'locale.language.label' => 'jqadm test',
190
			),
191
		);
192
193
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
194
		$this->view->addHelper( 'param', $helper );
195
196
		$this->object->save();
197
198
		$item = $manager->findItem( 'xx' );
199
		$manager->deleteItem( $item->getId() );
200
201
		$this->assertEquals( 'jqadm test', $item->getLabel() );
202
	}
203
204
205
	public function testSaveException()
206
	{
207
		$object = $this->getClientMock( 'fromArray' );
208
209
		$object->expects( $this->once() )->method( 'fromArray' )
210
			->will( $this->throwException( new \RuntimeException() ) );
211
212
		$object->save();
213
	}
214
215
216
	public function testSaveMShopException()
217
	{
218
		$object = $this->getClientMock( 'fromArray' );
219
220
		$object->expects( $this->once() )->method( 'fromArray' )
221
			->will( $this->throwException( new \RuntimeException() ) );
222
223
		$object->save();
224
	}
225
226
227
	public function testSaveJQAdmException()
228
	{
229
		$object = $this->getClientMock( 'fromArray' );
230
231
		$object->expects( $this->once() )->method( 'fromArray' )
232
			->will( $this->throwException( new \RuntimeException() ) );
233
234
		$object->save();
235
	}
236
237
238
	public function testSearch()
239
	{
240
		$param = array(
241
			'lang' => 'de',
242
			'filter' => array(
243
				'key' => array( 0 => 'locale.language.code' ),
244
				'op' => array( 0 => '==' ),
245
				'val' => array( 0 => 'de' ),
246
			),
247
			'sort' => array( '-locale.language.id' ),
248
		);
249
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
250
		$this->view->addHelper( 'param', $helper );
251
252
		$result = $this->object->search();
253
254
		$this->assertContains( '>de<', $result );
255
	}
256
257
258
	public function testSearchException()
259
	{
260
		$object = $this->getClientMock( 'initCriteria' );
261
262
		$object->expects( $this->once() )->method( 'initCriteria' )
263
			->will( $this->throwException( new \RuntimeException() ) );
264
265
		$object->search();
266
	}
267
268
269
	public function testSearchMShopException()
270
	{
271
		$object = $this->getClientMock( 'initCriteria' );
272
273
		$object->expects( $this->once() )->method( 'initCriteria' )
274
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
275
276
		$object->search();
277
	}
278
279
280
	public function testGetSubClientInvalid()
281
	{
282
		$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class );
283
		$this->object->getSubClient( '$unknown$' );
284
	}
285
286
287
	public function testGetSubClientUnknown()
288
	{
289
		$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class );
290
		$this->object->getSubClient( 'unknown' );
291
	}
292
293
294
	public function getClientMock( $methods )
295
	{
296
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Locale\Language\Standard::class )
297
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
298
			->setMethods( (array) $methods )
299
			->getMock();
300
301
		$object->setAimeos( \TestHelperJqadm::getAimeos() );
302
		$object->setView( $this->getViewNoRender() );
303
304
		return $object;
305
	}
306
307
308
	protected function getViewNoRender()
309
	{
310
		$view = $this->getMockBuilder( \Aimeos\MW\View\Standard::class )
311
			->setConstructorArgs( array( [] ) )
312
			->setMethods( array( 'render', 'config' ) )
313
			->getMock();
314
315
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, ['id' => 'de'] );
316
		$view->addHelper( 'param', $helper );
317
318
		$helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, [] );
319
		$view->addHelper( 'access', $helper );
320
321
		return $view;
322
	}
323
324
}
325