StandardTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 178
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 91
dl 0
loc 178
rs 10
c 0
b 0
f 0
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreate() 0 9 1
A testGetSubClient() 0 4 1
A testSearch() 0 3 1
A testCopy() 0 9 1
A tearDown() 0 3 1
A testDelete() 0 9 1
A testSaveMShopException() 0 19 1
A testGet() 0 9 1
A testSave() 0 43 1
A setUp() 0 14 1
A testSaveException() 0 19 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\Content;
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
		$langManager = \Aimeos\MShop::create( $this->context, 'locale/language' );
25
26
		$this->view->pageLanguages = $langManager->search( $langManager->filter() );
27
		$this->view->item = \Aimeos\MShop::create( $this->context, 'cms' )->create();
28
29
		$this->object = new \Aimeos\Admin\JQAdm\Cms\Content\Standard( $this->context );
30
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
31
		$this->object->setAimeos( \TestHelper::getAimeos() );
32
		$this->object->setView( $this->view );
33
	}
34
35
36
	protected function tearDown() : void
37
	{
38
		unset( $this->object, $this->view, $this->context );
39
	}
40
41
42
	public function testCreate()
43
	{
44
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
45
46
		$this->view->item = $manager->create();
47
		$result = $this->object->create();
48
49
		$this->assertStringContainsString( 'item-content', $result );
50
		$this->assertEmpty( $this->view->get( 'errors' ) );
51
	}
52
53
54
	public function testCopy()
55
	{
56
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
57
58
		$this->view->item = $manager->find( '/contact', ['text'] );
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

58
		/** @scrutinizer ignore-call */ 
59
  $this->view->item = $manager->find( '/contact', ['text'] );
Loading history...
59
		$result = $this->object->copy();
60
61
		$this->assertEmpty( $this->view->get( 'errors' ) );
62
		$this->assertStringContainsString( 'Hello', $result );
63
	}
64
65
66
	public function testDelete()
67
	{
68
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
69
70
		$this->view->item = $manager->create();
71
		$result = $this->object->delete();
72
73
		$this->assertEmpty( $this->view->get( 'errors' ) );
74
		$this->assertEmpty( $result );
75
	}
76
77
78
	public function testGet()
79
	{
80
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
81
82
		$this->view->item = $manager->find( '/contact', ['text'] );
83
		$result = $this->object->get();
84
85
		$this->assertEmpty( $this->view->get( 'errors' ) );
86
		$this->assertStringContainsString( 'Hello', $result );
87
	}
88
89
90
	public function testSave()
91
	{
92
		$manager = \Aimeos\MShop::create( $this->context, 'cms' );
93
		$item = $manager->create();
94
95
		$param = array(
96
			'site' => 'unittest',
97
			'content' => array(
98
				array(
99
					'text.id' => '',
100
					'text.languageid' => 'en',
101
					'text.content' => '<h1>Hello!</h1>',
102
					'cms.lists.type' => 'default',
103
					'cms.lists.position' => 0,
104
				),
105
				array(
106
					'text.id' => '',
107
					'text.languageid' => 'de',
108
					'text.content' => '<h1>Hallo!</h1>',
109
					'cms.lists.type' => 'default',
110
					'cms.lists.position' => 1,
111
				),
112
			),
113
		);
114
115
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
116
		$this->view->addHelper( 'param', $helper );
117
		$this->view->item = $item;
118
119
		$result = $this->object->save();
120
		$listItems = $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

120
		/** @scrutinizer ignore-call */ 
121
  $listItems = $item->getListItems();
Loading history...
121
122
		$this->assertEmpty( $this->view->get( 'errors' ) );
123
		$this->assertEmpty( $result );
124
		$this->assertEquals( 2, count( $listItems ) );
125
126
		$this->assertEquals( [0, 1], $listItems->getPosition()->values()->toArray() );
127
		$this->assertEquals( ['text', 'text'], $listItems->getDomain()->values()->toArray() );
128
129
		$refItems = $listItems->getRefItem();
130
131
		$this->assertEquals( ['en', 'de'], $refItems->getLanguageId()->values()->toArray() );
132
		$this->assertEquals( ['<h1>Hello!</h1>', '<h1>Hallo!</h1>'], $refItems->getContent()->values()->toArray() );
133
	}
134
135
136
	public function testSaveException()
137
	{
138
		$templates = \TestHelper::getAimeos()->getTemplatePaths( 'admin/jqadm/templates' );
139
140
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Cms\Content\Standard::class )
141
			->setConstructorArgs( array( $this->context, $templates ) )
142
			->onlyMethods( array( 'fromArray' ) )
143
			->getMock();
144
145
		$object->expects( $this->once() )->method( 'fromArray' )
146
			->will( $this->throwException( new \RuntimeException() ) );
147
148
		$this->view = \TestHelper::view();
149
		$this->view->item = \Aimeos\MShop::create( $this->context, 'cms' )->create();
150
151
		$object->setView( $this->view );
152
153
		$this->expectException( \RuntimeException::class );
154
		$object->save();
155
	}
156
157
158
	public function testSaveMShopException()
159
	{
160
		$templates = \TestHelper::getAimeos()->getTemplatePaths( 'admin/jqadm/templates' );
161
162
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Cms\Content\Standard::class )
163
			->setConstructorArgs( array( $this->context, $templates ) )
164
			->onlyMethods( array( 'fromArray' ) )
165
			->getMock();
166
167
		$object->expects( $this->once() )->method( 'fromArray' )
168
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
169
170
		$this->view = \TestHelper::view();
171
		$this->view->item = \Aimeos\MShop::create( $this->context, 'cms' )->create();
172
173
		$object->setView( $this->view );
174
175
		$this->expectException( \Aimeos\MShop\Exception::class );
176
		$object->save();
177
	}
178
179
180
	public function testSearch()
181
	{
182
		$this->assertEmpty( $this->object->search() );
183
	}
184
185
186
	public function testGetSubClient()
187
	{
188
		$this->expectException( \LogicException::class );
189
		$this->object->getSubClient( 'unknown' );
190
	}
191
}
192