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\Property; |
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\Property\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( 'Media properties', $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 properties', $result ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
public function testDelete() |
62
|
|
|
{ |
63
|
|
|
$result = $this->object->delete(); |
64
|
|
|
|
65
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
66
|
|
|
$this->assertEmpty( $result ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testGet() |
71
|
|
|
{ |
72
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
73
|
|
|
|
74
|
|
|
$this->view->item = $manager->find( '/kontakt', ['media'] ); |
75
|
|
|
$result = $this->object->get(); |
76
|
|
|
|
77
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
78
|
|
|
$this->assertStringContainsString( 'Media properties', $result ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
public function testSave() |
83
|
|
|
{ |
84
|
|
|
$manager = \Aimeos\MShop::create( $this->context, 'cms' ); |
85
|
|
|
$typeManager = \Aimeos\MShop::create( $this->context, 'media/property/type' ); |
|
|
|
|
86
|
|
|
|
87
|
|
|
$item = $manager->find( '/kontakt', ['media'] ); |
88
|
|
|
$item->setUrl( '/jqadm-test-media-property' ); |
89
|
|
|
$item->setId( null ); |
90
|
|
|
|
91
|
|
|
$this->view->item = $manager->save( $item ); |
92
|
|
|
|
93
|
|
|
$param = array( |
94
|
|
|
'site' => 'unittest', |
95
|
|
|
'media' => array( |
96
|
|
|
0 => array( |
97
|
|
|
'property' => array( |
98
|
|
|
0 => array( |
99
|
|
|
'media.property.id' => '', |
100
|
|
|
'media.property.type' => 'size', |
101
|
|
|
), |
102
|
|
|
), |
103
|
|
|
), |
104
|
|
|
), |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
108
|
|
|
$this->view->addHelper( 'param', $helper ); |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
$result = $this->object->save(); |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
$manager->delete( $this->view->item->getId() ); |
115
|
|
|
|
116
|
|
|
$this->assertEmpty( $this->view->get( 'errors' ) ); |
117
|
|
|
$this->assertEmpty( $result ); |
118
|
|
|
|
119
|
|
|
$mediaItems = $this->view->item->getRefItems( 'media' )->toArray(); |
|
|
|
|
120
|
|
|
$this->assertEquals( 1, count( $mediaItems ) ); |
121
|
|
|
$this->assertEquals( 1, count( reset( $mediaItems )->getPropertyItems() ) ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
public function testSaveException() |
126
|
|
|
{ |
127
|
|
|
$templates = \TestHelper::getAimeos()->getTemplatePaths( 'admin/jqadm/templates' ); |
128
|
|
|
|
129
|
|
|
$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Cms\Media\Property\Standard::class ) |
130
|
|
|
->setConstructorArgs( array( $this->context, $templates ) ) |
131
|
|
|
->onlyMethods( array( 'fromArray' ) ) |
132
|
|
|
->getMock(); |
133
|
|
|
|
134
|
|
|
$object->expects( $this->once() )->method( 'fromArray' ) |
135
|
|
|
->will( $this->throwException( new \RuntimeException() ) ); |
136
|
|
|
|
137
|
|
|
$this->view = \TestHelper::view(); |
138
|
|
|
$this->view->item = \Aimeos\MShop::create( $this->context, 'cms' )->create(); |
139
|
|
|
|
140
|
|
|
$object->setView( $this->view ); |
141
|
|
|
|
142
|
|
|
$this->expectException( \RuntimeException::class ); |
143
|
|
|
$object->save(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
public function testSearch() |
148
|
|
|
{ |
149
|
|
|
$this->assertEmpty( $this->object->search() ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
public function testGetSubClient() |
154
|
|
|
{ |
155
|
|
|
$this->expectException( \LogicException::class ); |
156
|
|
|
$this->object->getSubClient( 'unknown' ); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|