Passed
Push — master ( 37560e...165d83 )
by Aimeos
03:08
created

StandardTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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-2022
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Locale\Currency;
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
		$this->context = \TestHelper::context();
23
24
		$this->object = new \Aimeos\Admin\JQAdm\Locale\Currency\Standard( $this->context );
25
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
26
		$this->object->setAimeos( \TestHelper::getAimeos() );
27
		$this->object->setView( $this->view );
28
	}
29
30
31
	protected function tearDown() : void
32
	{
33
		unset( $this->object, $this->view, $this->context );
34
	}
35
36
37
	public function testBatch()
38
	{
39
		$param = array(
40
			'site' => 'unittest',
41
			'item' => array(
42
				'locale.currency.status' => -1,
43
			),
44
			'id' => [-1, -2]
45
		);
46
47
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
48
		$this->view->addHelper( 'param', $helper );
49
50
		$result = $this->object->batch();
51
52
		$this->assertEmpty( $this->view->get( 'errors' ) );
53
		$this->assertNull( $result );
54
	}
55
56
57
	public function testCreate()
58
	{
59
		$result = $this->object->create();
60
61
		$this->assertStringContainsString( 'currency', $result );
62
		$this->assertEmpty( $this->view->get( 'errors' ) );
63
	}
64
65
66
	public function testCreateException()
67
	{
68
		$object = $this->getClientMock( 'getSubClients' );
69
70
		$object->expects( $this->once() )->method( 'getSubClients' )
71
			->will( $this->throwException( new \RuntimeException() ) );
72
73
		$object->create();
74
	}
75
76
77
	public function testCopy()
78
	{
79
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, ['id' => 'EUR'] );
80
		$this->view->addHelper( 'param', $helper );
81
82
		$result = $this->object->copy();
83
84
		$this->assertStringContainsString( 'Euro', $result );
85
	}
86
87
88
	public function testCopyException()
89
	{
90
		$object = $this->getClientMock( 'getSubClients' );
91
92
		$object->expects( $this->once() )->method( 'getSubClients' )
93
			->will( $this->throwException( new \RuntimeException() ) );
94
95
		$object->copy();
96
	}
97
98
99
	public function testDelete()
100
	{
101
		$this->assertNull( $this->getClientMock( ['redirect'], false )->delete() );
102
	}
103
104
105
	public function testDeleteException()
106
	{
107
		$object = $this->getClientMock( ['getSubClients', 'search'] );
108
109
		$object->expects( $this->once() )->method( 'getSubClients' )
110
			->will( $this->throwException( new \RuntimeException() ) );
111
		$object->expects( $this->once() )->method( 'search' );
112
113
		$object->delete();
114
	}
115
116
117
	public function testGet()
118
	{
119
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, ['id' => 'EUR'] );
120
		$this->view->addHelper( 'param', $helper );
121
122
		$result = $this->object->get();
123
124
		$this->assertStringContainsString( 'EUR', $result );
125
	}
126
127
128
	public function testGetException()
129
	{
130
		$object = $this->getClientMock( 'getSubClients' );
131
132
		$object->expects( $this->once() )->method( 'getSubClients' )
133
			->will( $this->throwException( new \RuntimeException() ) );
134
135
		$object->get();
136
	}
137
138
139
	public function testSave()
140
	{
141
		$manager = \Aimeos\MShop::create( $this->context, 'locale/currency' );
142
143
		$param = array(
144
			'item' => array(
145
				'locale.currency.id' => '',
146
				'locale.currency.status' => '1',
147
				'locale.currency.code' => 'XXX',
148
				'locale.currency.label' => 'jqadm test',
149
			),
150
		);
151
152
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
153
		$this->view->addHelper( 'param', $helper );
154
155
		$this->object->save();
156
157
		$item = $manager->find( 'XXX' );
158
		$manager->delete( $item->getId() );
159
160
		$this->assertEquals( 'jqadm test', $item->getLabel() );
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
			'locale' => 'de',
179
			'filter' => array(
180
				'key' => array( 0 => 'locale.currency.code' ),
181
				'op' => array( 0 => '==' ),
182
				'val' => array( 0 => 'EUR' ),
183
			),
184
			'sort' => array( '-locale.currency.id' ),
185
		);
186
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
187
		$this->view->addHelper( 'param', $helper );
188
189
		$result = $this->object->search();
190
191
		$this->assertStringContainsString( '>EUR<', $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\Currency\Standard::class )
223
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
224
			->setMethods( (array) $methods )
225
			->getMock();
226
227
		$object->setAimeos( \TestHelper::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\Base\View\Standard::class )
237
			->setConstructorArgs( array( [] ) )
238
			->setMethods( array( 'render' ) )
239
			->getMock();
240
241
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, ['id' => $real ? 'EUR' : 'XXX'] );
242
		$view->addHelper( 'param', $helper );
243
244
		$helper = new \Aimeos\Base\View\Helper\Config\Standard( $view, $this->context->config() );
245
		$view->addHelper( 'config', $helper );
246
247
		$helper = new \Aimeos\Base\View\Helper\Access\Standard( $view, [] );
248
		$view->addHelper( 'access', $helper );
249
250
		return $view;
251
	}
252
253
}
254