StandardTest::testGetSubClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
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), 2021-2025
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Cms;
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\Cms\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 testCreate()
44
	{
45
		$result = $this->object->create();
46
47
		$this->assertStringContainsString( 'cms', $result );
48
		$this->assertEmpty( $this->view->get( 'errors' ) );
49
	}
50
51
52
	public function testCreateException()
53
	{
54
		$object = $this->getClientMock( 'getSubClients' );
55
56
		$object->expects( $this->once() )->method( 'getSubClients' )
57
			->will( $this->throwException( new \RuntimeException() ) );
58
59
		$object->create();
60
	}
61
62
63
	public function testCopy()
64
	{
65
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
66
67
		$param = ['site' => 'unittest', 'id' => $manager->find( '/contact' )->getId()];
0 ignored issues
show
Bug introduced by
The method find() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Order\Manag...rvice\Transaction\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Type\Manager\Iface or Aimeos\MShop\Order\Manager\Service\Iface or Aimeos\MShop\Review\Manager\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Address\Iface or Aimeos\MShop\Order\Manager\Product\Attribute\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Order\Manager\Coupon\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Order\Manager\Service\Attribute\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Rule\Manager\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Basket\Manager\Iface or Aimeos\MShop\Stock\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Cms\Manager\Lists\Iface or Aimeos\MShop\Locale\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Product\Iface or Aimeos\MShop\Price\Manager\Property\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Property\Type\Iface or Aimeos\MShop\Cms\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Property\Type\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Property\Type\Iface or Aimeos\MShop\Rule\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Product\Manager\Property\Type\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Stock\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Media\Manager\Property\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

67
		$param = ['site' => 'unittest', 'id' => $manager->/** @scrutinizer ignore-call */ find( '/contact' )->getId()];
Loading history...
68
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
69
		$this->view->addHelper( 'param', $helper );
70
71
		$result = $this->object->copy();
72
73
		$this->assertStringContainsString( '/contact_copy', $result );
74
	}
75
76
77
	public function testCopyException()
78
	{
79
		$object = $this->getClientMock( 'getSubClients' );
80
81
		$object->expects( $this->once() )->method( 'getSubClients' )
82
			->will( $this->throwException( new \RuntimeException() ) );
83
84
		$object->copy();
85
	}
86
87
88
	public function testDelete()
89
	{
90
		$this->assertNull( $this->getClientMock( ['redirect'], false )->delete() );
91
	}
92
93
94
	public function testDeleteException()
95
	{
96
		$object = $this->getClientMock( ['getSubClients', 'search'] );
97
98
		$object->expects( $this->once() )->method( 'getSubClients' )
99
			->will( $this->throwException( new \RuntimeException() ) );
100
		$object->expects( $this->once() )->method( 'search' );
101
102
		$object->delete();
103
	}
104
105
106
	public function testGet()
107
	{
108
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
109
110
		$param = ['site' => 'unittest', 'id' => $manager->find( '/contact' )->getId()];
111
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
112
		$this->view->addHelper( 'param', $helper );
113
114
		$result = $this->object->get();
115
116
		$this->assertStringContainsString( '/contact', $result );
117
	}
118
119
120
	public function testGetException()
121
	{
122
		$object = $this->getClientMock( 'getSubClients' );
123
124
		$object->expects( $this->once() )->method( 'getSubClients' )
125
			->will( $this->throwException( new \RuntimeException() ) );
126
127
		$object->get();
128
	}
129
130
131
	public function testSave()
132
	{
133
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
134
135
		$param = array(
136
			'site' => 'unittest',
137
			'item' => array(
138
				'cms.id' => '',
139
				'cms.url' => '/contact-jqadm',
140
				'cms.label' => 'jqadm test url',
141
				'cms.status' => 0
142
			),
143
		);
144
145
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
146
		$this->view->addHelper( 'param', $helper );
147
148
		$result = $this->object->save();
149
150
		$manager->delete( $manager->find( '/contact-jqadm' ) );
151
152
		$this->assertEmpty( $this->view->get( 'errors' ) );
153
		$this->assertNull( $result );
154
	}
155
156
157
	public function testSaveException()
158
	{
159
		$object = $this->getClientMock( 'fromArray' );
160
161
		$object->expects( $this->once() )->method( 'fromArray' )
162
			->will( $this->throwException( new \RuntimeException() ) );
163
164
		$object->save();
165
	}
166
167
168
	public function testSearch()
169
	{
170
		$param = array(
171
			'site' => 'unittest', 'lang' => 'de',
172
			'filter' => array(
173
				'key' => array( 0 => 'cms.url' ),
174
				'op' => array( 0 => '==' ),
175
				'val' => array( 0 => '/contact' ),
176
			),
177
			'sort' => array( 'cms.label', '-cms.id' ),
178
		);
179
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
180
		$this->view->addHelper( 'param', $helper );
181
182
		$result = $this->object->search();
183
184
		$this->assertStringContainsString( '/contact', $result );
185
	}
186
187
188
	public function testSearchException()
189
	{
190
		$object = $this->getClientMock( 'initCriteria' );
191
192
		$object->expects( $this->once() )->method( 'initCriteria' )
193
			->will( $this->throwException( new \RuntimeException() ) );
194
195
		$object->search();
196
	}
197
198
199
	public function testGetSubClient()
200
	{
201
		$result = $this->object->getSubClient( 'seo' );
202
		$this->assertInstanceOf( \Aimeos\Admin\JQAdm\Iface::class, $result );
203
	}
204
205
206
	public function testGetSubClientInvalid()
207
	{
208
		$this->expectException( \LogicException::class );
209
		$this->object->getSubClient( '$unknown$' );
210
	}
211
212
213
	public function testGetSubClientUnknown()
214
	{
215
		$this->expectException( \LogicException::class );
216
		$this->object->getSubClient( 'unknown' );
217
	}
218
219
220
	public function getClientMock( $methods, $real = true )
221
	{
222
		$templates = \TestHelper::getAimeos()->getTemplatePaths( 'admin/jqadm/templates' );
223
224
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Cms\Standard::class )
225
			->setConstructorArgs( array( $this->context, $templates ) )
226
			->onlyMethods( (array) $methods )
227
			->getMock();
228
229
		$object->setAimeos( \TestHelper::getAimeos() );
230
		$object->setView( $this->getViewNoRender( $real ) );
231
232
		return $object;
233
	}
234
235
236
	protected function getViewNoRender( $real = true )
237
	{
238
		$view = $this->getMockBuilder( \Aimeos\Base\View\Standard::class )
239
			->setConstructorArgs( array( [] ) )
240
			->onlyMethods( array( 'render' ) )
241
			->getMock();
242
243
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
244
245
		$param = ['site' => 'unittest', 'id' => $real ? $manager->find( '/contact' )->getId() : -1];
246
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $view, $param );
247
		$view->addHelper( 'param', $helper );
248
249
		$helper = new \Aimeos\Base\View\Helper\Config\Standard( $view, $this->context->config() );
250
		$view->addHelper( 'config', $helper );
251
252
		$helper = new \Aimeos\Base\View\Helper\Access\Standard( $view, [] );
253
		$view->addHelper( 'access', $helper );
254
255
		return $view;
256
	}
257
}
258