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\Media\Property;
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\Property\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( 'Media properties', $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( 'Media properties', $result );
58
	}
59
60
61
	public function testDelete()
62
	{
63
		$result = $this->object->delete();
64
65
		$this->assertEmpty( $this->view->get( 'errors' ) );
66
		$this->assertEmpty( $result );
67
	}
68
69
70
	public function testGet()
71
	{
72
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
73
74
		$this->view->item = $manager->find( '/kontakt', ['media'] );
75
		$result = $this->object->get();
76
77
		$this->assertEmpty( $this->view->get( 'errors' ) );
78
		$this->assertStringContainsString( 'Media properties', $result );
79
	}
80
81
82
	public function testSave()
83
	{
84
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
85
		$typeManager = \Aimeos\MShop::create( $this->context, 'media/property/type' );
0 ignored issues
show
Unused Code introduced by
The assignment to $typeManager is dead and can be removed.
Loading history...
86
87
		$item = $manager->find( '/kontakt', ['media'] );
88
		$item->setUrl( '/jqadm-test-media-property' );
89
		$item->setId( null );
90
91
		$this->view->item = $manager->save( $item );
92
93
		$param = array(
94
			'site' => 'unittest',
95
			'media' => array(
96
				0 => array(
97
					'property' => array(
98
						0 => array(
99
							'media.property.id' => '',
100
							'media.property.type' => 'size',
101
						),
102
					),
103
				),
104
			),
105
		);
106
107
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
108
		$this->view->addHelper( 'param', $helper );
109
110
111
		$result = $this->object->save();
112
113
114
		$manager->delete( $this->view->item->getId() );
115
116
		$this->assertEmpty( $this->view->get( 'errors' ) );
117
		$this->assertEmpty( $result );
118
119
		$mediaItems = $this->view->item->getRefItems( 'media' )->toArray();
0 ignored issues
show
Bug introduced by
The method getRefItems() 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

119
		$mediaItems = $this->view->item->/** @scrutinizer ignore-call */ getRefItems( 'media' )->toArray();
Loading history...
120
		$this->assertEquals( 1, count( $mediaItems ) );
121
		$this->assertEquals( 1, count( reset( $mediaItems )->getPropertyItems() ) );
122
	}
123
124
125
	public function testSaveException()
126
	{
127
		$templates = \TestHelper::getAimeos()->getTemplatePaths( 'admin/jqadm/templates' );
128
129
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Cms\Media\Property\Standard::class )
130
			->setConstructorArgs( array( $this->context, $templates ) )
131
			->onlyMethods( array( 'fromArray' ) )
132
			->getMock();
133
134
		$object->expects( $this->once() )->method( 'fromArray' )
135
			->will( $this->throwException( new \RuntimeException() ) );
136
137
		$this->view = \TestHelper::view();
138
		$this->view->item = \Aimeos\MShop::create( $this->context, 'cms' )->create();
139
140
		$object->setView( $this->view );
141
142
		$this->expectException( \RuntimeException::class );
143
		$object->save();
144
	}
145
146
147
	public function testSearch()
148
	{
149
		$this->assertEmpty( $this->object->search() );
150
	}
151
152
153
	public function testGetSubClient()
154
	{
155
		$this->expectException( \LogicException::class );
156
		$this->object->getSubClient( 'unknown' );
157
	}
158
}
159