StandardTest   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 184
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 95
dl 0
loc 184
rs 10
c 0
b 0
f 0
wmc 12

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testCopy() 0 9 1
A testDelete() 0 9 1
A testCreate() 0 9 1
A setUp() 0 14 1
A tearDown() 0 3 1
A testGet() 0 9 1
A testSearch() 0 3 1
A testSaveException() 0 19 1
A testGetSubClient() 0 4 1
A testSave() 0 48 2
A testSaveMShopException() 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\Seo;
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\Seo\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-seo', $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( 'Contact', $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( 'Contact', $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
			'seo' => array(
98
				array(
99
					'text.id' => '',
100
					'text.content' => 'test name',
101
					'text.languageid' => 'de',
102
					'text.type' => 'name',
103
					'cms.lists.type' => 'default',
104
				),
105
				array(
106
					'text.id' => '',
107
					'text.content' => 'short desc',
108
					'text.languageid' => 'de',
109
					'text.type' => 'name',
110
					'cms.lists.type' => 'default',
111
				),
112
				array(
113
					'text.id' => '',
114
					'text.content' => 'long desc',
115
					'text.languageid' => 'de',
116
					'text.type' => 'name',
117
					'cms.lists.type' => 'default',
118
				),
119
			),
120
		);
121
122
		$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param );
123
		$this->view->addHelper( 'param', $helper );
124
		$this->view->item = $item;
125
126
		$result = $this->object->save();
127
128
		$this->assertEmpty( $this->view->get( 'errors' ) );
129
		$this->assertEmpty( $result );
130
		$this->assertEquals( 3, count( $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

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