StandardTest   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 193
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 93
c 1
b 0
f 0
dl 0
loc 193
rs 10
wmc 13

12 Methods

Rating   Name   Duplication   Size   Complexity  
A testGet() 0 9 1
A tearDown() 0 3 1
A setUp() 0 9 1
A testCopy() 0 9 1
A testDelete() 0 9 1
A testCreate() 0 9 1
A testSaveException() 0 9 1
A testSearch() 0 3 1
A testSave() 0 64 2
A getClientMock() 0 16 1
A testSaveMShopException() 0 9 1
A testGetSubClient() 0 4 1
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\Media;
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\Cms\Media\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 testCreate()
38
	{
39
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
40
41
		$this->view->item = $manager->create();
42
		$result = $this->object->create();
43
44
		$this->assertStringContainsString( 'item-media', $result );
45
		$this->assertEmpty( $this->view->get( 'errors' ) );
46
	}
47
48
49
	public function testCopy()
50
	{
51
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
52
53
		$this->view->item = $manager->find( '/kontakt', ['media'] );
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

53
		/** @scrutinizer ignore-call */ 
54
  $this->view->item = $manager->find( '/kontakt', ['media'] );
Loading history...
54
		$result = $this->object->copy();
55
56
		$this->assertEmpty( $this->view->get( 'errors' ) );
57
		$this->assertStringContainsString( '&quot;media.preview&quot;:&quot;\/path\/to\/image-small-2.jpg', $result );
58
	}
59
60
61
	public function testDelete()
62
	{
63
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
64
65
		$this->view->item = $manager->create();
66
		$result = $this->object->delete();
67
68
		$this->assertEmpty( $this->view->get( 'errors' ) );
69
		$this->assertEmpty( $result );
70
	}
71
72
73
	public function testGet()
74
	{
75
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
76
77
		$this->view->item = $manager->find( '/kontakt', ['media'] );
78
		$result = $this->object->get();
79
80
		$this->assertEmpty( $this->view->get( 'errors' ) );
81
		$this->assertStringContainsString( '&quot;media.preview&quot;:&quot;\/path\/to\/image-small-2.jpg', $result );
82
	}
83
84
85
	public function testSave()
86
	{
87
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
88
		$this->view->item = $manager->create();
89
90
91
		$param = array(
92
			'site' => 'unittest',
93
			'media' => [[
94
				'media.id' => '',
95
				'media.type' => 'default',
96
				'media.languageid' => 'de',
97
				'media.label' => 'test',
98
				'cms.lists.type' => 'default',
99
			]],
100
		);
101
102
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
103
		$this->view->addHelper( 'param', $helper );
104
105
		$file = $this->getMockBuilder( \Psr\Http\Message\UploadedFileInterface::class )->getMock();
106
		$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock();
107
		$request->expects( $this->any() )->method( 'getUploadedFiles' )
108
			->willReturn( ['media' => [0 => ['file' => $file]]] );
109
110
		$helper = new \Aimeos\Base\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' );
111
		$this->view ->addHelper( 'request', $helper );
112
113
114
		$managerStub = $this->getMockBuilder( \Aimeos\MShop\Media\Manager\Standard::class )
115
			->setConstructorArgs( array( $this->context ) )
116
			->onlyMethods( ['upload'] )
117
			->getMock();
118
119
		\Aimeos\MShop::inject( \Aimeos\MShop\Media\Manager\Standard::class, $managerStub );
120
121
		$managerStub->expects( $this->once() )->method( 'upload' )->willReturnArgument( 0 );
122
123
124
		$result = $this->object->save();
125
126
127
		$this->assertEmpty( $this->view->get( 'errors' ) );
128
		$this->assertEmpty( $result );
129
		$this->assertEquals( 1, count( $this->view->item->getListItems() ) );
0 ignored issues
show
Bug introduced by
The method getListItems() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MAdmin\Log\Item\Iface or Aimeos\MShop\Group\Item\Iface or Aimeos\MShop\Rule\Item\Iface or Aimeos\MShop\Basket\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Order\Item\Product\Iface or Aimeos\MAdmin\Cache\Item\Iface or Aimeos\MShop\Stock\Item\Iface or Aimeos\MShop\Order\Item\Product\Attribute\Iface or Aimeos\MShop\Order\Item\Service\Iface or Aimeos\MShop\Order\Item\Iface or Aimeos\MShop\Subscription\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MShop\Order\Item\Service\Attribute\Iface or Aimeos\MShop\Review\Item\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Order\Item\Status\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Locale\Item\Iface or Aimeos\MShop\Common\Item\PropertyRef\Iface or Aimeos\MShop\Tag\Item\Iface or Aimeos\MShop\Order\Item\Service\Transaction\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Common\Item\Address\Iface or Aimeos\MShop\Common\Item\Property\Iface or Aimeos\MShop\Common\Item\AddressRef\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Type\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Order\Item\Coupon\Iface or Aimeos\MShop\Customer\Item\Address\Iface or Aimeos\MShop\Order\Item\Address\Iface or Aimeos\MShop\Supplier\Item\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

129
		$this->assertEquals( 1, count( $this->view->item->/** @scrutinizer ignore-call */ getListItems() ) );
Loading history...
130
131
		foreach( $this->view->item->getListItems( 'media' ) as $listItem )
132
		{
133
			$this->assertEquals( 'media', $listItem->getDomain() );
134
135
			$refItem = $listItem->getRefItem();
136
			$this->assertEquals( 'de', $refItem->getLanguageId() );
137
			$this->assertEquals( 'test', $refItem->getLabel() );
138
		}
139
140
141
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, ['site' => 'unittest', 'media' => []] );
142
		$this->view->addHelper( 'param', $helper );
143
144
		$result = $this->object->save();
145
146
		$this->assertEmpty( $this->view->get( 'errors' ) );
147
		$this->assertEmpty( $result );
148
		$this->assertEquals( 0, count( $this->view->item->getListItems() ) );
149
	}
150
151
152
	public function testSaveException()
153
	{
154
		$object = $this->getClientMock( 'fromArray' );
155
156
		$object->expects( $this->once() )->method( 'fromArray' )
157
			->will( $this->throwException( new \RuntimeException() ) );
158
159
		$this->expectException( \RuntimeException::class );
160
		$object->save();
161
	}
162
163
164
	public function testSaveMShopException()
165
	{
166
		$object = $this->getClientMock( 'fromArray' );
167
168
		$object->expects( $this->once() )->method( 'fromArray' )
169
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
170
171
		$this->expectException( \Aimeos\MShop\Exception::class );
172
		$object->save();
173
	}
174
175
176
	public function testSearch()
177
	{
178
		$this->assertEmpty( $this->object->search() );
179
	}
180
181
182
	public function testGetSubClient()
183
	{
184
		$this->expectException( \LogicException::class );
185
		$this->object->getSubClient( 'unknown' );
186
	}
187
188
189
	public function getClientMock( $method )
190
	{
191
		$templates = \TestHelper::getAimeos()->getTemplatePaths( 'admin/jqadm/templates' );
192
193
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Cms\Media\Standard::class )
194
			->setConstructorArgs( array( $this->context, $templates ) )
195
			->onlyMethods( [$method] )
196
			->getMock();
197
198
		$view = \TestHelper::view();
199
		$view->item = \Aimeos\MShop::create( $this->context, 'cms' )->create();
200
201
		$object->setAimeos( \TestHelper::getAimeos() );
202
		$object->setView( $view );
203
204
		return $object;
205
	}
206
}
207