|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021-2025 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Cms\Item; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $object; |
|
15
|
|
|
private $values; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() : void |
|
19
|
|
|
{ |
|
20
|
|
|
$this->values = array( |
|
21
|
|
|
'cms.id' => 10, |
|
22
|
|
|
'cms.siteid' => 99, |
|
23
|
|
|
'cms.url' => '/test', |
|
24
|
|
|
'cms.label' => 'unittest label', |
|
25
|
|
|
'cms.status' => 2, |
|
26
|
|
|
'cms.mtime' => '2011-01-01 00:00:02', |
|
27
|
|
|
'cms.ctime' => '2011-01-01 00:00:01', |
|
28
|
|
|
'cms.editor' => 'unitTestUser', |
|
29
|
|
|
); |
|
30
|
|
|
|
|
31
|
|
|
$this->object = new \Aimeos\MShop\Cms\Item\Standard( 'cms.', $this->values ); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
protected function tearDown() : void |
|
36
|
|
|
{ |
|
37
|
|
|
unset( $this->object ); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
public function testIsModified() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->assertFalse( $this->object->isModified() ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
public function testGetId() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->assertEquals( '10', $this->object->getId() ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
public function testSetId() |
|
54
|
|
|
{ |
|
55
|
|
|
$return = $this->object->setId( null ); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Cms\Item\Iface::class, $return ); |
|
58
|
|
|
$this->assertNull( $this->object->getId() ); |
|
59
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
public function testGetSiteId() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
public function testGetUrl() |
|
70
|
|
|
{ |
|
71
|
|
|
$this->assertEquals( '/test', $this->object->getUrl() ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
public function testSetUrl() |
|
76
|
|
|
{ |
|
77
|
|
|
$return = $this->object->setUrl( '/test2' ); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Cms\Item\Iface::class, $return ); |
|
80
|
|
|
$this->assertEquals( '/test2', $this->object->getUrl() ); |
|
81
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
public function testSetUrlTransform() |
|
86
|
|
|
{ |
|
87
|
|
|
$return = $this->object->setUrl( '/Äpfel/Birnen' ); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Cms\Item\Iface::class, $return ); |
|
90
|
|
|
$this->assertEquals( '/apfel/birnen', $this->object->getUrl() ); |
|
91
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
public function testGetLabel() |
|
96
|
|
|
{ |
|
97
|
|
|
$this->assertEquals( 'unittest label', $this->object->getLabel() ); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
public function testSetLabel() |
|
102
|
|
|
{ |
|
103
|
|
|
$return = $this->object->setLabel( 'unittest set label' ); |
|
104
|
|
|
|
|
105
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Cms\Item\Iface::class, $return ); |
|
106
|
|
|
$this->assertEquals( 'unittest set label', $this->object->getLabel() ); |
|
107
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
|
|
111
|
|
|
public function testGetStatus() |
|
112
|
|
|
{ |
|
113
|
|
|
$this->assertEquals( 2, $this->object->getStatus() ); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
public function testSetStatus() |
|
118
|
|
|
{ |
|
119
|
|
|
$return = $this->object->setStatus( 0 ); |
|
120
|
|
|
|
|
121
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Cms\Item\Iface::class, $return ); |
|
122
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
|
123
|
|
|
$this->assertTrue( $this->object->isModified() ); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
|
|
127
|
|
|
public function testGetTimeModified() |
|
128
|
|
|
{ |
|
129
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
public function testGetTimeCreated() |
|
134
|
|
|
{ |
|
135
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
public function testGetEditor() |
|
140
|
|
|
{ |
|
141
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->editor() ); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
public function testGetResourceType() |
|
146
|
|
|
{ |
|
147
|
|
|
$this->assertEquals( 'cms', $this->object->getResourceType() ); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
public function testFromArray() |
|
152
|
|
|
{ |
|
153
|
|
|
$item = new \Aimeos\MShop\Cms\Item\Standard( 'cms.' ); |
|
154
|
|
|
|
|
155
|
|
|
$list = $entries = array( |
|
156
|
|
|
'cms.id' => 1, |
|
157
|
|
|
'cms.url' => '/test', |
|
158
|
|
|
'cms.label' => 'test item', |
|
159
|
|
|
'cms.status' => 0, |
|
160
|
|
|
); |
|
161
|
|
|
|
|
162
|
|
|
$item = $item->fromArray( $entries, true ); |
|
163
|
|
|
|
|
164
|
|
|
$this->assertEquals( [], $entries ); |
|
165
|
|
|
$this->assertEquals( '', $item->getSiteId() ); |
|
166
|
|
|
$this->assertEquals( $list['cms.id'], $item->getId() ); |
|
167
|
|
|
$this->assertEquals( $list['cms.url'], $item->getUrl() ); |
|
168
|
|
|
$this->assertEquals( $list['cms.label'], $item->getLabel() ); |
|
169
|
|
|
$this->assertEquals( $list['cms.status'], $item->getStatus() ); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
public function testToArray() |
|
174
|
|
|
{ |
|
175
|
|
|
$data = $this->object->toArray( true ); |
|
176
|
|
|
|
|
177
|
|
|
$this->assertEquals( count( $this->values ), count( $data ) ); |
|
178
|
|
|
|
|
179
|
|
|
$this->assertEquals( $this->object->getId(), $data['cms.id'] ); |
|
180
|
|
|
$this->assertEquals( $this->object->getSiteId(), $data['cms.siteid'] ); |
|
181
|
|
|
$this->assertEquals( $this->object->getUrl(), $data['cms.url'] ); |
|
182
|
|
|
$this->assertEquals( $this->object->getLabel(), $data['cms.label'] ); |
|
183
|
|
|
$this->assertEquals( $this->object->getStatus(), $data['cms.status'] ); |
|
184
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $data['cms.ctime'] ); |
|
185
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $data['cms.mtime'] ); |
|
186
|
|
|
$this->assertEquals( $this->object->editor(), $data['cms.editor'] ); |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
|
|
190
|
|
|
public function testIsAvailable() |
|
191
|
|
|
{ |
|
192
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
193
|
|
|
$this->object->setAvailable( false ); |
|
194
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
|
|
198
|
|
|
public function testIsAvailableOnStatus() |
|
199
|
|
|
{ |
|
200
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
|
201
|
|
|
$this->object->setStatus( 0 ); |
|
202
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
203
|
|
|
$this->object->setStatus( -1 ); |
|
204
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
|