Passed
Push — master ( ad5f8f...6fcf2d )
by Aimeos
07:12 queued 04:36
created

StandardTest::testGetViewException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
nc 1
nop 0
dl 0
loc 6
c 1
b 0
f 0
cc 1
rs 10
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Cms;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
	private $context;
15
	private $object;
16
	private $view;
17
18
19
	protected function setUp() : void
20
	{
21
		$this->view = \TestHelperJqadm::view();
22
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
23
		$helper = new \Aimeos\MW\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' );
24
		$this->view ->addHelper( 'request', $helper );
25
26
		$this->context = \TestHelperJqadm::getContext();
27
28
		$this->object = new \Aimeos\Admin\JQAdm\Cms\Standard( $this->context );
29
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
30
		$this->object->setAimeos( \TestHelperJqadm::getAimeos() );
31
		$this->object->setView( $this->view );
32
	}
33
34
35
	protected function tearDown() : void
36
	{
37
		unset( $this->object, $this->view, $this->context );
38
	}
39
40
41
	public function testCreate()
42
	{
43
		$result = $this->object->create();
44
45
		$this->assertStringContainsString( 'cms', $result );
46
		$this->assertEmpty( $this->view->get( 'errors' ) );
47
	}
48
49
50
	public function testCreateException()
51
	{
52
		$object = $this->getClientMock( 'getSubClients' );
53
54
		$object->expects( $this->once() )->method( 'getSubClients' )
55
			->will( $this->throwException( new \RuntimeException() ) );
56
57
		$object->create();
58
	}
59
60
61
	public function testCopy()
62
	{
63
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
64
65
		$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\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Review\Manager\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Order\Manager\Base\Coupon\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Order\Manager\Base\Service\Iface or Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Cms\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Order\Manag...Service\Attribute\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Order\Manag...Product\Attribute\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Rule\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Address\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\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\Order\Manager\Status\Iface or Aimeos\MShop\Rule\Manager\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Plugin\Manager\Type\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\MShop\Attribute\Manager\Lists\Type\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\Base\Product\Iface or Aimeos\MShop\Price\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\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

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