StandardTest::testGet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
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), 2017-2026
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Catalog\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, 'catalog' )->create();
28
29
		$this->object = new \Aimeos\Admin\JQAdm\Catalog\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, 'catalog' );
45
46
		$this->view->item = $manager->create();
47
		$result = $this->object->create();
48
49
		$this->assertEmpty( $this->view->get( 'errors' ) );
50
		$this->assertStringContainsString( 'item-text', $result );
51
	}
52
53
54
	public function testCopy()
55
	{
56
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
57
58
		$this->view->item = $manager->find( 'cafe', array( 'text' ) );
59
		$result = $this->object->copy();
60
61
		$this->assertEmpty( $this->view->get( 'errors' ) );
62
		$this->assertStringContainsString( 'item-text', $result );
63
	}
64
65
66
	public function testDelete()
67
	{
68
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
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, 'catalog' );
81
82
		$this->view->item = $manager->find( 'cafe', array( 'text' ) );
83
		$result = $this->object->get();
84
85
		$this->assertEmpty( $this->view->get( 'errors' ) );
86
		$this->assertStringContainsString( 'item-text', $result );
87
	}
88
89
90
	public function testSave()
91
	{
92
		$manager = \Aimeos\MShop::create( $this->context, 'catalog' );
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
					'catalog.lists.type' => 'default',
104
				),
105
				array(
106
					'text.id' => '',
107
					'text.content' => 'short desc',
108
					'text.languageid' => 'de',
109
					'text.type' => 'name',
110
					'catalog.lists.type' => 'default',
111
				),
112
				array(
113
					'text.id' => '',
114
					'text.content' => 'long desc',
115
					'text.languageid' => 'de',
116
					'text.type' => 'name',
117
					'catalog.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->getMockBuilder( \Aimeos\Admin\JQAdm\Catalog\Text\Standard::class )
145
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
146
			->onlyMethods( array( 'fromArray' ) )
147
			->getMock();
148
149
		$object->expects( $this->once() )->method( 'fromArray' )
150
			->will( $this->throwException( new \RuntimeException() ) );
151
152
		$this->view = \TestHelper::view();
153
		$this->view->item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
154
155
		$object->setView( $this->view );
156
157
		$this->expectException( \RuntimeException::class );
158
		$object->save();
159
	}
160
161
162
	public function testSaveMShopException()
163
	{
164
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Catalog\Text\Standard::class )
165
			->setConstructorArgs( array( $this->context, \TestHelper::getTemplatePaths() ) )
166
			->onlyMethods( array( 'fromArray' ) )
167
			->getMock();
168
169
		$object->expects( $this->once() )->method( 'fromArray' )
170
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
171
172
		$this->view = \TestHelper::view();
173
		$this->view->item = \Aimeos\MShop::create( $this->context, 'catalog' )->create();
174
175
		$object->setView( $this->view );
176
177
		$this->expectException( \Aimeos\MShop\Exception::class );
178
		$object->save();
179
	}
180
181
182
	public function testSearch()
183
	{
184
		$this->assertEmpty( $this->object->search() );
185
	}
186
187
188
	public function testGetSubClient()
189
	{
190
		$this->expectException( \LogicException::class );
191
		$this->object->getSubClient( 'unknown' );
192
	}
193
}
194