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'] ); |
|
|
|
|
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() ) ); |
|
|
|
|
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
|
|
|
|