Completed
Push — master ( a13539...bd1b6d )
by Aimeos
04:27
created

StandardTest::testSaveException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
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-2020
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Locale\Site;
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() : void
20
	{
21
		$this->view = \TestHelperJqadm::getView();
22
		$this->context = \TestHelperJqadm::getContext();
23
24
		$helper = new \Aimeos\MW\View\Helper\Access\Standard( $this->view, ['super'] );
25
		$this->view->addHelper( 'access', $helper );
26
27
		$this->object = new \Aimeos\Admin\JQAdm\Locale\Site\Standard( $this->context );
28
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
29
		$this->object->setAimeos( \TestHelperJqadm::getAimeos() );
30
		$this->object->setView( $this->view );
31
	}
32
33
34
	protected function tearDown() : void
35
	{
36
		unset( $this->object, $this->view, $this->context );
37
	}
38
39
40
	public function testCreate()
41
	{
42
		$this->assertStringContainsString( 'item-locale-site', $this->object->create() );
43
	}
44
45
46
	public function testCreateException()
47
	{
48
		$object = $this->getClientMock( 'getSubClients' );
49
50
		$object->expects( $this->once() )->method( 'getSubClients' )
51
			->will( $this->throwException( new \RuntimeException() ) );
52
53
		$object->create();
54
	}
55
56
57
	public function testCopy()
58
	{
59
		$manager = \Aimeos\MShop::create( $this->context, 'locale/site' );
60
61
		$param = ['site' => 'unittest', 'id' => $manager->findItem( 'unittest' )->getId()];
62
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
63
		$this->view->addHelper( 'param', $helper );
64
65
		$result = $this->object->copy();
66
67
		$this->assertStringContainsString( 'unittest', $result );
68
	}
69
70
71
	public function testCopyException()
72
	{
73
		$object = $this->getClientMock( 'getSubClients' );
74
75
		$object->expects( $this->once() )->method( 'getSubClients' )
76
			->will( $this->throwException( new \RuntimeException() ) );
77
78
		$object->copy();
79
	}
80
81
82
	public function testDelete()
83
	{
84
		$this->assertNull( $this->getClientMock( ['nextAction'], false )->delete() );
85
	}
86
87
88
	public function testDeleteException()
89
	{
90
		$object = $this->getClientMock( ['getSubClients', 'search'] );
91
92
		$object->expects( $this->once() )->method( 'getSubClients' )
93
			->will( $this->throwException( new \RuntimeException() ) );
94
		$object->expects( $this->once() )->method( 'search' );
95
96
		$object->delete();
97
	}
98
99
100
	public function testGet()
101
	{
102
		$manager = \Aimeos\MShop::create( $this->context, 'locale/site' );
103
104
		$param = ['site' => 'unittest', 'id' => $manager->findItem( 'unittest' )->getId()];
105
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
106
		$this->view->addHelper( 'param', $helper );
107
108
		$result = $this->object->get();
109
110
		$this->assertStringContainsString( 'unittest', $result );
111
	}
112
113
114
	public function testGetException()
115
	{
116
		$object = $this->getClientMock( 'getSubClients' );
117
118
		$object->expects( $this->once() )->method( 'getSubClients' )
119
			->will( $this->throwException( new \RuntimeException() ) );
120
121
		$object->get();
122
	}
123
124
125
	public function testGetViewException()
126
	{
127
		$object = new \Aimeos\Admin\JQAdm\Locale\Site\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

127
		$object = /** @scrutinizer ignore-call */ new \Aimeos\Admin\JQAdm\Locale\Site\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...
128
129
		$this->expectException( \Aimeos\Admin\JQAdm\Exception::class );
130
		$object->getView();
131
	}
132
133
134
	public function testSave()
135
	{
136
		$manager = \Aimeos\MShop::create( $this->context, 'locale/site' );
137
138
		$param = array(
139
			'site' => 'unittest',
140
			'item' => array(
141
				'locale.site.id' => '',
142
				'locale.site.status' => '1',
143
				'locale.site.code' => 'jqadm@test',
144
				'locale.site.label' => 'jqadm test',
145
				'config' => [[
146
					'key' => 'test',
147
					'val' => 'value',
148
				]],
149
			),
150
		);
151
152
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
153
		$this->view->addHelper( 'param', $helper );
154
155
		$this->object->save();
156
157
		$item = $manager->findItem( 'jqadm@test' );
158
		$manager->deleteItem( $item->getId() );
159
160
		$this->assertEquals( ['test' => 'value'], $item->getConfig() );
161
	}
162
163
164
	public function testSaveException()
165
	{
166
		$object = $this->getClientMock( 'fromArray' );
167
168
		$object->expects( $this->once() )->method( 'fromArray' )
169
			->will( $this->throwException( new \RuntimeException() ) );
170
171
		$object->save();
172
	}
173
174
175
	public function testSearch()
176
	{
177
		$param = array(
178
			'site' => 'unittest', 'lang' => 'de',
179
			'filter' => array(
180
				'key' => array( 0 => 'locale.site.code' ),
181
				'op' => array( 0 => '==' ),
182
				'val' => array( 0 => 'unittest' ),
183
			),
184
			'sort' => array( '-locale.site.id' ),
185
		);
186
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
187
		$this->view->addHelper( 'param', $helper );
188
189
		$result = $this->object->search();
190
191
		$this->assertStringContainsString( '>unittest<', $result );
192
	}
193
194
195
	public function testSearchException()
196
	{
197
		$object = $this->getClientMock( 'initCriteria' );
198
199
		$object->expects( $this->once() )->method( 'initCriteria' )
200
			->will( $this->throwException( new \RuntimeException() ) );
201
202
		$object->search();
203
	}
204
205
206
	public function testGetSubClientInvalid()
207
	{
208
		$this->expectException( \Aimeos\Admin\JQAdm\Exception::class );
209
		$this->object->getSubClient( '$unknown$' );
210
	}
211
212
213
	public function testGetSubClientUnknown()
214
	{
215
		$this->expectException( \Aimeos\Admin\JQAdm\Exception::class );
216
		$this->object->getSubClient( 'unknown' );
217
	}
218
219
220
	public function getClientMock( $methods, $real = true )
221
	{
222
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Locale\Site\Standard::class )
223
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
224
			->setMethods( (array) $methods )
225
			->getMock();
226
227
		$object->setAimeos( \TestHelperJqadm::getAimeos() );
228
		$object->setView( $this->getViewNoRender( $real ) );
229
230
		return $object;
231
	}
232
233
234
	protected function getViewNoRender( $real = true )
235
	{
236
		$view = $this->getMockBuilder( \Aimeos\MW\View\Standard::class )
237
			->setConstructorArgs( array( [] ) )
238
			->setMethods( array( 'render' ) )
239
			->getMock();
240
241
		$manager = \Aimeos\MShop::create( $this->context, 'locale/site' );
242
243
		$param = ['site' => 'unittest', 'id' => $real ? $manager->findItem( 'unittest' )->getId() : -1];
244
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
245
		$view->addHelper( 'param', $helper );
246
247
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $this->context->getConfig() );
248
		$view->addHelper( 'config', $helper );
249
250
		$helper = new \Aimeos\MW\View\Helper\Access\Standard( $this->view, ['super'] );
251
		$view->addHelper( 'access', $helper );
252
253
		return $view;
254
	}
255
256
}
257