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\Media; |
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
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Cms\Media\Standard( $this->context ); |
25
|
|
|
$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context ); |
26
|
|
|
$this->object->setAimeos( \TestHelper::getAimeos() ); |
27
|
|
|
$this->object->setView( $this->view ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
protected function tearDown() : void |
32
|
|
|
{ |
33
|
|
|
unset( $this->object, $this->view, $this->context ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
public function testCreate() |
38
|
|
|
{ |
39
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
40
|
|
|
|
41
|
|
|
$this->view->item = $manager->create(); |
42
|
|
|
$result = $this->object->create(); |
43
|
|
|
|
44
|
|
|
$this->assertStringContainsString( 'item-media', $result ); |
45
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function testCopy() |
50
|
|
|
{ |
51
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
52
|
|
|
|
53
|
|
|
$this->view->item = $manager->find( '/kontakt', ['media'] ); |
|
|
|
|
54
|
|
|
$result = $this->object->copy(); |
55
|
|
|
|
56
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
57
|
|
|
$this->assertStringContainsString( '"media.preview":"\/path\/to\/image-small-2.jpg', $result ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testDelete() |
62
|
|
|
{ |
63
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
64
|
|
|
|
65
|
|
|
$this->view->item = $manager->create(); |
66
|
|
|
$result = $this->object->delete(); |
67
|
|
|
|
68
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
69
|
|
|
$this->assertEmpty( $result ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
public function testGet() |
74
|
|
|
{ |
75
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
76
|
|
|
|
77
|
|
|
$this->view->item = $manager->find( '/kontakt', ['media'] ); |
78
|
|
|
$result = $this->object->get(); |
79
|
|
|
|
80
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
81
|
|
|
$this->assertStringContainsString( '"media.preview":"\/path\/to\/image-small-2.jpg', $result ); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
public function testSave() |
86
|
|
|
{ |
87
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
88
|
|
|
$this->view->item = $manager->create(); |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
$param = array( |
92
|
|
|
'site' => 'unittest', |
93
|
|
|
'media' => [[ |
94
|
|
|
'media.id' => '', |
95
|
|
|
'media.type' => 'default', |
96
|
|
|
'media.languageid' => 'de', |
97
|
|
|
'media.label' => 'test', |
98
|
|
|
'cms.lists.type' => 'default', |
99
|
|
|
]], |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
103
|
|
|
$this->view->addHelper( 'param', $helper ); |
104
|
|
|
|
105
|
|
|
$file = $this->getMockBuilder( \Psr\Http\Message\UploadedFileInterface::class )->getMock(); |
106
|
|
|
$request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
107
|
|
|
$request->expects( $this->any() )->method( 'getUploadedFiles' ) |
108
|
|
|
->willReturn( ['media' => [0 => ['file' => $file]]] ); |
109
|
|
|
|
110
|
|
|
$helper = new \Aimeos\Base\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' ); |
111
|
|
|
$this->view ->addHelper( 'request', $helper ); |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
$managerStub = $this->getMockBuilder( \Aimeos\MShop\Media\Manager\Standard::class ) |
115
|
|
|
->setConstructorArgs( array( $this->context ) ) |
116
|
|
|
->onlyMethods( ['upload'] ) |
117
|
|
|
->getMock(); |
118
|
|
|
|
119
|
|
|
\Aimeos\MShop::inject( \Aimeos\MShop\Media\Manager\Standard::class, $managerStub ); |
120
|
|
|
|
121
|
|
|
$managerStub->expects( $this->once() )->method( 'upload' )->willReturnArgument( 0 ); |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
$result = $this->object->save(); |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
128
|
|
|
$this->assertEmpty( $result ); |
129
|
|
|
$this->assertEquals( 1, count( $this->view->item->getListItems() ) ); |
|
|
|
|
130
|
|
|
|
131
|
|
|
foreach( $this->view->item->getListItems( 'media' ) as $listItem ) |
132
|
|
|
{ |
133
|
|
|
$this->assertEquals( 'media', $listItem->getDomain() ); |
134
|
|
|
|
135
|
|
|
$refItem = $listItem->getRefItem(); |
136
|
|
|
$this->assertEquals( 'de', $refItem->getLanguageId() ); |
137
|
|
|
$this->assertEquals( 'test', $refItem->getLabel() ); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, ['site' => 'unittest', 'media' => []] ); |
142
|
|
|
$this->view->addHelper( 'param', $helper ); |
143
|
|
|
|
144
|
|
|
$result = $this->object->save(); |
145
|
|
|
|
146
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
147
|
|
|
$this->assertEmpty( $result ); |
148
|
|
|
$this->assertEquals( 0, count( $this->view->item->getListItems() ) ); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
|
152
|
|
|
public function testSaveException() |
153
|
|
|
{ |
154
|
|
|
$object = $this->getClientMock( 'fromArray' ); |
155
|
|
|
|
156
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
157
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
158
|
|
|
|
159
|
|
|
$this->expectException( \RuntimeException::class ); |
160
|
|
|
$object->save(); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
public function testSaveMShopException() |
165
|
|
|
{ |
166
|
|
|
$object = $this->getClientMock( 'fromArray' ); |
167
|
|
|
|
168
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
169
|
|
|
->will( $this->throwException( new \Aimeos\MShop\Exception() ) ); |
170
|
|
|
|
171
|
|
|
$this->expectException( \Aimeos\MShop\Exception::class ); |
172
|
|
|
$object->save(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
|
176
|
|
|
public function testSearch() |
177
|
|
|
{ |
178
|
|
|
$this->assertEmpty( $this->object->search() ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
public function testGetSubClient() |
183
|
|
|
{ |
184
|
|
|
$this->expectException( \LogicException::class ); |
185
|
|
|
$this->object->getSubClient( 'unknown' ); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
|
189
|
|
|
public function getClientMock( $method ) |
190
|
|
|
{ |
191
|
|
|
$templates = \TestHelper::getAimeos()->getTemplatePaths( 'admin/jqadm/templates' ); |
192
|
|
|
|
193
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Cms\Media\Standard::class ) |
194
|
|
|
->setConstructorArgs( array( $this->context, $templates ) ) |
195
|
|
|
->onlyMethods( [$method] ) |
196
|
|
|
->getMock(); |
197
|
|
|
|
198
|
|
|
$view = \TestHelper::view(); |
199
|
|
|
$view->item = \Aimeos\MShop::create( $this->context, 'cms' )->create(); |
200
|
|
|
|
201
|
|
|
$object->setAimeos( \TestHelper::getAimeos() ); |
202
|
|
|
$object->setView( $view ); |
203
|
|
|
|
204
|
|
|
return $object; |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|