Passed
Push — master ( d073b5...91750f )
by Aimeos
04:41
created

StandardTest   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 287
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 127
dl 0
loc 287
rs 10
c 1
b 0
f 0
wmc 23

22 Methods

Rating   Name   Duplication   Size   Complexity  
A testSaveException() 0 8 1
A testCopyException() 0 8 1
A testGet() 0 11 1
A testSave() 0 23 1
A tearDown() 0 3 1
A testSearch() 0 17 1
A getClientMock() 0 11 1
A testDelete() 0 3 1
A testCreateException() 0 8 1
A testGetSubClientDecoratorInvalid() 0 6 1
A getViewNoRender() 0 24 2
A testBatch() 0 17 1
A testImport() 0 12 1
A setUp() 0 15 1
A testGetException() 0 8 1
A testGetSubClientUnknown() 0 4 1
A testSearchException() 0 8 1
A testGetSubClientInvalid() 0 4 1
A testGetSubClient() 0 4 1
A testCreate() 0 6 1
A testCopy() 0 11 1
A testDeleteException() 0 6 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2025
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Customer;
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 = \TestHelper::view();
22
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
23
		$request->expects( $this->any() )->method( 'getUploadedFiles' )->willReturn( [] );
24
25
		$helper = new \Aimeos\Base\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' );
26
		$this->view->addHelper( 'request', $helper );
27
28
		$this->context = \TestHelper::context();
29
30
		$this->object = new \Aimeos\Admin\JQAdm\Customer\Standard( $this->context );
31
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
32
		$this->object->setAimeos( \TestHelper::getAimeos() );
33
		$this->object->setView( $this->view );
34
	}
35
36
37
	protected function tearDown() : void
38
	{
39
		unset( $this->object, $this->view, $this->context );
40
	}
41
42
43
	public function testBatch()
44
	{
45
		$param = array(
46
			'site' => 'unittest',
47
			'item' => array(
48
				'customer.status' => -1,
49
			),
50
			'id' => [-1, -2]
51
		);
52
53
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
54
		$this->view->addHelper( 'param', $helper );
55
56
		$result = $this->object->batch();
57
58
		$this->assertEmpty( $this->view->get( 'errors' ) );
59
		$this->assertNull( $result );
60
	}
61
62
63
	public function testCreate()
64
	{
65
		$result = $this->object->create();
66
67
		$this->assertStringContainsString( 'customer', $result );
68
		$this->assertEmpty( $this->view->get( 'errors' ) );
69
	}
70
71
72
	public function testCreateException()
73
	{
74
		$object = $this->getClientMock( 'getSubClients' );
75
76
		$object->expects( $this->once() )->method( 'getSubClients' )
77
			->will( $this->throwException( new \RuntimeException() ) );
78
79
		$object->create();
80
	}
81
82
83
	public function testCopy()
84
	{
85
		$manager = \Aimeos\MShop::create( $this->context, 'customer' );
86
87
		$param = ['site' => 'unittest', 'id' => $manager->find( '[email protected]' )->getId()];
88
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
89
		$this->view->addHelper( 'param', $helper );
90
91
		$result = $this->object->copy();
92
93
		$this->assertStringContainsString( 'Example company', $result );
94
	}
95
96
97
	public function testCopyException()
98
	{
99
		$object = $this->getClientMock( 'getSubClients' );
100
101
		$object->expects( $this->once() )->method( 'getSubClients' )
102
			->will( $this->throwException( new \RuntimeException() ) );
103
104
		$object->copy();
105
	}
106
107
108
	public function testDelete()
109
	{
110
		$this->assertEquals( '', $this->getClientMock( ['redirect'], false )->delete() );
111
	}
112
113
114
	public function testDeleteException()
115
	{
116
		$object = $this->getClientMock( ['search'] );
117
		$object->expects( $this->once() )->method( 'search' );
118
119
		$object->delete();
120
	}
121
122
123
	public function testGet()
124
	{
125
		$manager = \Aimeos\MShop::create( $this->context, 'customer' );
126
127
		$param = ['site' => 'unittest', 'id' => $manager->find( '[email protected]' )->getId()];
128
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
129
		$this->view->addHelper( 'param', $helper );
130
131
		$result = $this->object->get();
132
133
		$this->assertStringContainsString( 'unitCustomer001', $result );
134
	}
135
136
137
	public function testGetException()
138
	{
139
		$object = $this->getClientMock( 'getSubClients' );
140
141
		$object->expects( $this->once() )->method( 'getSubClients' )
142
			->will( $this->throwException( new \RuntimeException() ) );
143
144
		$object->get();
145
	}
146
147
148
	public function testImport()
149
	{
150
		$param = array(
151
			'site' => 'unittest',
152
		);
153
154
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
155
		$this->view->addHelper( 'param', $helper );
156
157
		$result = $this->object->import();
158
159
		$this->assertNull( $result );
160
	}
161
162
163
	public function testSave()
164
	{
165
		$manager = \Aimeos\MShop::create( $this->context, 'customer' );
166
167
		$param = array(
168
			'site' => 'unittest',
169
			'item' => array(
170
				'customer.id' => '',
171
				'customer.email' => '[email protected]',
172
				'customer.firstname' => 'test',
173
				'customer.lastname' => 'label',
174
			),
175
		);
176
177
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
178
		$this->view->addHelper( 'param', $helper );
179
180
		$result = $this->object->save();
181
182
		$manager->delete( $manager->find( '[email protected]' )->getId() );
183
184
		$this->assertEmpty( $this->view->get( 'errors' ) );
185
		$this->assertNull( $result );
186
	}
187
188
189
	public function testSaveException()
190
	{
191
		$object = $this->getClientMock( 'fromArray' );
192
193
		$object->expects( $this->once() )->method( 'fromArray' )
194
			->will( $this->throwException( new \RuntimeException() ) );
195
196
		$object->save();
197
	}
198
199
200
	public function testSearch()
201
	{
202
		$param = array(
203
			'site' => 'unittest', 'locale' => 'de',
204
			'filter' => array(
205
				'key' => array( 0 => 'customer.code' ),
206
				'op' => array( 0 => '==' ),
207
				'val' => array( 0 => '[email protected]' ),
208
			),
209
			'sort' => array( 'customer.label', '-customer.id' ),
210
		);
211
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
212
		$this->view->addHelper( 'param', $helper );
213
214
		$result = $this->object->search();
215
216
		$this->assertStringContainsString( '>[email protected]<', $result );
217
	}
218
219
220
	public function testSearchException()
221
	{
222
		$object = $this->getClientMock( 'initCriteria' );
223
224
		$object->expects( $this->once() )->method( 'initCriteria' )
225
			->will( $this->throwException( new \RuntimeException() ) );
226
227
		$object->search();
228
	}
229
230
231
	public function testGetSubClient()
232
	{
233
		$result = $this->object->getSubClient( 'address' );
234
		$this->assertInstanceOf( \Aimeos\Admin\JQAdm\Iface::class, $result );
235
	}
236
237
238
	public function testGetSubClientInvalid()
239
	{
240
		$this->expectException( \LogicException::class );
241
		$this->object->getSubClient( '$unknown$' );
242
	}
243
244
245
	public function testGetSubClientUnknown()
246
	{
247
		$this->expectException( \LogicException::class );
248
		$this->object->getSubClient( 'unknown' );
249
	}
250
251
252
	public function testGetSubClientDecoratorInvalid()
253
	{
254
		$this->context->config()->set( 'admin/jqadm/customer/product/decorators/global', array( 'Invalid' ) );
255
256
		$this->expectException( \LogicException::class );
257
		$this->object->getSubClient( 'product' );
258
	}
259
260
261
	public function getClientMock( $methods, $real = true )
262
	{
263
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Customer\Standard::class )
264
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
265
			->onlyMethods( (array) $methods )
266
			->getMock();
267
268
		$object->setAimeos( \TestHelper::getAimeos() );
269
		$object->setView( $this->getViewNoRender( $real ) );
270
271
		return $object;
272
	}
273
274
275
	protected function getViewNoRender( $real = true )
276
	{
277
		$view = $this->getMockBuilder( \Aimeos\Base\View\Standard::class )
278
			->setConstructorArgs( array( [] ) )
279
			->onlyMethods( array( 'render' ) )
280
			->getMock();
281
282
		$manager = \Aimeos\MShop::create( $this->context, 'customer' );
283
284
		$trans = new \Aimeos\Base\Translation\None( 'de_DE' );
285
		$helper = new \Aimeos\Base\View\Helper\Translate\Standard( $view, $trans );
286
		$view->addHelper( 'translate', $helper );
287
288
		$param = ['site' => 'unittest', 'id' => $real ? $manager->find( '[email protected]' )->getId() : -1];
289
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $view, $param );
290
		$view->addHelper( 'param', $helper );
291
292
		$helper = new \Aimeos\Base\View\Helper\Config\Standard( $view, $this->context->config() );
293
		$view->addHelper( 'config', $helper );
294
295
		$helper = new \Aimeos\Base\View\Helper\Access\Standard( $view, [] );
296
		$view->addHelper( 'access', $helper );
297
298
		return $view;
299
	}
300
}
301