StandardTest   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 181
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 90
dl 0
loc 181
rs 10
c 0
b 0
f 0
wmc 13

12 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetSubClient() 0 4 1
A testDelete() 0 9 1
A testGet() 0 9 1
A testCopy() 0 9 1
A setUp() 0 14 1
A testCreate() 0 9 1
A getClientMock() 0 14 1
A tearDown() 0 3 1
A testSaveMShopException() 0 9 1
A testSave() 0 48 2
A testSaveException() 0 9 1
A testSearch() 0 3 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2025
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Attribute\Text;
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, 'attribute' )->create();
28
29
		$this->object = new \Aimeos\Admin\JQAdm\Attribute\Text\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, 'attribute' );
45
46
		$this->view->item = $manager->create();
47
		$result = $this->object->create();
48
49
		$this->assertStringContainsString( 'item-text', $result );
50
		$this->assertEmpty( $this->view->get( 'errors' ) );
51
	}
52
53
54
	public function testCopy()
55
	{
56
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
57
58
		$this->view->item = $manager->find( 'white', ['text'], 'product', 'color' );
59
		$result = $this->object->copy();
60
61
		$this->assertEmpty( $this->view->get( 'errors' ) );
62
		$this->assertStringContainsString( '&quot;text.type&quot;:&quot;name&quot;', $result );
63
	}
64
65
66
	public function testDelete()
67
	{
68
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
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, 'attribute' );
81
82
		$this->view->item = $manager->find( 'white', ['text'], 'product', 'color' );
83
		$result = $this->object->get();
84
85
		$this->assertEmpty( $this->view->get( 'errors' ) );
86
		$this->assertStringContainsString( '&quot;text.type&quot;:&quot;name&quot;', $result );
87
	}
88
89
90
	public function testSave()
91
	{
92
		$manager = \Aimeos\MShop::create( $this->context, 'attribute' );
93
		$item = $manager->create();
94
95
		$param = array(
96
			'site' => 'unittest',
97
			'text' => array(
98
				array(
99
					'text.id' => '',
100
					'text.content' => 'test name',
101
					'text.languageid' => 'de',
102
					'text.type' => 'name',
103
					'attribute.lists.type' => 'default',
104
				),
105
				array(
106
					'text.id' => '',
107
					'text.content' => 'short desc',
108
					'text.languageid' => 'de',
109
					'text.type' => 'name',
110
					'attribute.lists.type' => 'default',
111
				),
112
				array(
113
					'text.id' => '',
114
					'text.content' => 'long desc',
115
					'text.languageid' => 'de',
116
					'text.type' => 'name',
117
					'attribute.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( $this->view->item->getListItems() ) );
131
132
		foreach( $this->view->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
		$object = $this->getClientMock( 'fromArray' );
145
146
		$object->expects( $this->once() )->method( 'fromArray' )
147
			->will( $this->throwException( new \RuntimeException() ) );
148
149
		$this->expectException( \RuntimeException::class );
150
		$object->save();
151
	}
152
153
154
	public function testSaveMShopException()
155
	{
156
		$object = $this->getClientMock( 'fromArray' );
157
158
		$object->expects( $this->once() )->method( 'fromArray' )
159
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
160
161
		$this->expectException( \Aimeos\MShop\Exception::class );
162
		$object->save();
163
	}
164
165
166
	public function testSearch()
167
	{
168
		$this->assertEmpty( $this->object->search() );
169
	}
170
171
172
	public function testGetSubClient()
173
	{
174
		$this->expectException( \LogicException::class );
175
		$this->object->getSubClient( 'unknown' );
176
	}
177
178
179
	public function getClientMock( $method )
180
	{
181
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Attribute\Media\Standard::class )
182
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
183
			->onlyMethods( [$method] )
184
			->getMock();
185
186
		$view = \TestHelper::view();
187
		$view->item = \Aimeos\MShop::create( $this->context, 'attribute' )->create();
188
189
		$object->setAimeos( \TestHelper::getAimeos() );
190
		$object->setView( $view );
191
192
		return $object;
193
	}
194
}
195