StandardTest::getViewNoRender()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 13
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 20
rs 9.8333
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2025
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 = \TestHelper::view();
22
		$this->context = \TestHelper::context();
23
24
		$helper = new \Aimeos\Base\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( \TestHelper::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->find( 'unittest' )->getId()];
62
		$helper = new \Aimeos\Base\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( ['redirect'], 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->find( 'unittest' )->getId()];
105
		$helper = new \Aimeos\Base\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 testSave()
126
	{
127
		$param = array(
128
			'site' => 'unittest',
129
			'item' => array(
130
				'locale.site.id' => '',
131
				'locale.site.status' => '1',
132
				'locale.site.code' => 'jqadm@test',
133
				'locale.site.label' => 'jqadm test',
134
				'config' => [[
135
					'key' => 'test',
136
					'val' => 'value',
137
				]],
138
			),
139
		);
140
141
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
142
		$this->view->addHelper( 'param', $helper );
143
144
		$this->object->save();
145
146
		$manager = \Aimeos\MShop::create( $this->context, 'locale/site' );
147
		$item = $manager->find( 'jqadm@test' );
148
		$manager->delete( $item->getId() );
149
150
		$this->assertEquals( ['test' => 'value'], $item->getConfig() );
151
	}
152
153
154
	public function testSaveException()
155
	{
156
		$object = $this->getClientMock( 'fromArray' );
157
158
		$object->expects( $this->once() )->method( 'fromArray' )
159
			->will( $this->throwException( new \RuntimeException() ) );
160
161
		$object->save();
162
	}
163
164
165
	public function testSearch()
166
	{
167
		$param = array(
168
			'site' => 'unittest', 'locale' => 'de',
169
			'filter' => array(
170
				'key' => array( 0 => 'locale.site.code' ),
171
				'op' => array( 0 => '==' ),
172
				'val' => array( 0 => 'unittest' ),
173
			),
174
			'sort' => array( '-locale.site.id' ),
175
		);
176
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
177
		$this->view->addHelper( 'param', $helper );
178
179
		$result = $this->object->search();
180
181
		$this->assertStringContainsString( '>unittest<', $result );
182
	}
183
184
185
	public function testSearchException()
186
	{
187
		$object = $this->getClientMock( 'initCriteria' );
188
189
		$object->expects( $this->once() )->method( 'initCriteria' )
190
			->will( $this->throwException( new \RuntimeException() ) );
191
192
		$object->search();
193
	}
194
195
196
	public function testGetSubClientInvalid()
197
	{
198
		$this->expectException( \LogicException::class );
199
		$this->object->getSubClient( '$unknown$' );
200
	}
201
202
203
	public function testGetSubClientUnknown()
204
	{
205
		$this->expectException( \LogicException::class );
206
		$this->object->getSubClient( 'unknown' );
207
	}
208
209
210
	public function getClientMock( $methods, $real = true )
211
	{
212
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Locale\Site\Standard::class )
213
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
214
			->onlyMethods( (array) $methods )
215
			->getMock();
216
217
		$object->setAimeos( \TestHelper::getAimeos() );
218
		$object->setView( $this->getViewNoRender( $real ) );
219
220
		return $object;
221
	}
222
223
224
	protected function getViewNoRender( $real = true )
225
	{
226
		$view = $this->getMockBuilder( \Aimeos\Base\View\Standard::class )
227
			->setConstructorArgs( array( [] ) )
228
			->onlyMethods( array( 'render' ) )
229
			->getMock();
230
231
		$manager = \Aimeos\MShop::create( $this->context, 'locale/site' );
232
233
		$param = ['site' => 'unittest', 'id' => $real ? $manager->find( 'unittest' )->getId() : -1];
234
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $view, $param );
235
		$view->addHelper( 'param', $helper );
236
237
		$helper = new \Aimeos\Base\View\Helper\Config\Standard( $view, $this->context->config() );
238
		$view->addHelper( 'config', $helper );
239
240
		$helper = new \Aimeos\Base\View\Helper\Access\Standard( $this->view, ['super'] );
241
		$view->addHelper( 'access', $helper );
242
243
		return $view;
244
	}
245
246
}
247