1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2011 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MShop\Media\Item; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
private $object; |
16
|
|
|
private $values; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
$this->values = array( |
22
|
|
|
'media.id' => 1, |
23
|
|
|
'media.siteid' => 123, |
24
|
|
|
'media.type' => 'category', |
25
|
|
|
'media.domain' => 'test_dom', |
26
|
|
|
'media.label' => 'testPicture', |
27
|
|
|
'media.mimetype' => 'image/jpeg', |
28
|
|
|
'media.url' => 'http://www.url.com/test.jpg', |
29
|
|
|
'media.preview' => [1 => '/directory/test.jpg'], |
30
|
|
|
'media.status' => 6, |
31
|
|
|
'media.languageid' => 'de', |
32
|
|
|
'media.mtime' => '2011-01-01 00:00:02', |
33
|
|
|
'media.ctime' => '2011-01-01 00:00:01', |
34
|
|
|
'media.editor' => 'unitTestUser', |
35
|
|
|
'languageid' => 'de', |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$this->object = new \Aimeos\MShop\Media\Item\Standard( $this->values ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
protected function tearDown() |
43
|
|
|
{ |
44
|
|
|
unset( $this->object ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
public function testGetId() |
49
|
|
|
{ |
50
|
|
|
$this->assertEquals( 1, $this->object->getId() ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
public function testSetId() |
55
|
|
|
{ |
56
|
|
|
$return = $this->object->setId( null ); |
57
|
|
|
|
58
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Media\Item\Iface::class, $return ); |
59
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
60
|
|
|
$this->assertTrue( $this->object->isModified() ); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
public function testGetDomain() |
65
|
|
|
{ |
66
|
|
|
$this->assertEquals( 'test_dom', $this->object->getDomain() ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
public function testSetDomain() |
71
|
|
|
{ |
72
|
|
|
$return = $this->object->setDomain( null ); |
73
|
|
|
|
74
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Media\Item\Iface::class, $return ); |
75
|
|
|
$this->assertEquals( null, $this->object->getDomain() ); |
76
|
|
|
$this->assertTrue( $this->object->isModified() ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
public function testGetType() |
81
|
|
|
{ |
82
|
|
|
$this->assertEquals( 'category', $this->object->getType() ); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
public function testSetType() |
87
|
|
|
{ |
88
|
|
|
$return = $this->object->setType( 'size' ); |
89
|
|
|
|
90
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Media\Item\Iface::class, $return ); |
91
|
|
|
$this->assertEquals( 'size', $this->object->getType() ); |
92
|
|
|
$this->assertTrue( $this->object->isModified() ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function testGetLabel() |
97
|
|
|
{ |
98
|
|
|
$this->assertEquals( 'testPicture', $this->object->getLabel() ); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
public function testSetLabel() |
103
|
|
|
{ |
104
|
|
|
$return = $this->object->setLabel( 'newPicture' ); |
105
|
|
|
|
106
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Media\Item\Iface::class, $return ); |
107
|
|
|
$this->assertEquals( 'newPicture', $this->object->getLabel() ); |
108
|
|
|
$this->assertTrue( $this->object->isModified() ); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
public function testGetLanguageId() |
113
|
|
|
{ |
114
|
|
|
$this->assertEquals( 'de', $this->object->getLanguageId() ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testSetLanguageId() |
119
|
|
|
{ |
120
|
|
|
$return = $this->object->setLanguageId( 'en' ); |
121
|
|
|
|
122
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Media\Item\Iface::class, $return ); |
123
|
|
|
$this->assertEquals( 'en', $this->object->getLanguageId() ); |
124
|
|
|
$this->assertTrue( $this->object->isModified() ); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
public function testSetLanguageIdInvalid() |
129
|
|
|
{ |
130
|
|
|
$this->setExpectedException( \Aimeos\MShop\Exception::class ); |
131
|
|
|
$this->object->setLanguageId( '00' ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
public function testGetMimeType() |
136
|
|
|
{ |
137
|
|
|
$this->assertEquals( 'image/jpeg', $this->object->getMimeType() ); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
public function testSetMimeType() |
142
|
|
|
{ |
143
|
|
|
$return = $this->object->setMimeType( 'image/png' ); |
144
|
|
|
|
145
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Media\Item\Iface::class, $return ); |
146
|
|
|
$this->assertEquals( 'image/png', $this->object->getMimeType() ); |
147
|
|
|
$this->assertTrue( $this->object->isModified() ); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
public function testSetMimeTypeNoSlash() |
152
|
|
|
{ |
153
|
|
|
$this->setExpectedException( \Aimeos\MShop\Media\Exception::class ); |
154
|
|
|
$this->object->setMimeType( 'image' ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testSetMimeTypeInvalidCategory() |
159
|
|
|
{ |
160
|
|
|
$this->setExpectedException( \Aimeos\MShop\Media\Exception::class ); |
161
|
|
|
$this->object->setMimeType( 'image+audio/test' ); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
|
165
|
|
|
public function testGetUrl() |
166
|
|
|
{ |
167
|
|
|
$this->assertEquals( 'http://www.url.com/test.jpg', $this->object->getUrl() ); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
|
171
|
|
|
public function testSetUrl() |
172
|
|
|
{ |
173
|
|
|
$return = $this->object->setUrl( '/pictures/category.jpg' ); |
174
|
|
|
|
175
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Media\Item\Iface::class, $return ); |
176
|
|
|
$this->assertEquals( '/pictures/category.jpg', $this->object->getUrl() ); |
177
|
|
|
$this->assertTrue( $this->object->isModified() ); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
|
181
|
|
|
public function testGetPreview() |
182
|
|
|
{ |
183
|
|
|
$this->assertEquals( '/directory/test.jpg', $this->object->getPreview() ); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
|
187
|
|
|
public function testGetPreviews() |
188
|
|
|
{ |
189
|
|
|
$this->assertEquals( [1 => '/directory/test.jpg'], $this->object->getPreviews() ); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
public function testSetPreview() |
194
|
|
|
{ |
195
|
|
|
$return = $this->object->setPreview( '/pictures/category.jpg' ); |
196
|
|
|
|
197
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Media\Item\Iface::class, $return ); |
198
|
|
|
$this->assertEquals( [1 => '/pictures/category.jpg'], $this->object->getPreviews() ); |
199
|
|
|
$this->assertEquals( '/pictures/category.jpg', $this->object->getPreview() ); |
200
|
|
|
$this->assertTrue( $this->object->isModified() ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
|
204
|
|
|
public function testSetPreviews() |
205
|
|
|
{ |
206
|
|
|
$return = $this->object->setPreviews( [1 => '/pictures/category.jpg'] ); |
207
|
|
|
|
208
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Media\Item\Iface::class, $return ); |
209
|
|
|
$this->assertEquals( [1 => '/pictures/category.jpg'], $this->object->getPreviews() ); |
210
|
|
|
$this->assertTrue( $this->object->isModified() ); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
|
214
|
|
|
public function testGetStatus() |
215
|
|
|
{ |
216
|
|
|
$this->assertEquals( 6, $this->object->getStatus() ); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
|
220
|
|
|
public function testSetStatus() |
221
|
|
|
{ |
222
|
|
|
$return = $this->object->setStatus( 0 ); |
223
|
|
|
|
224
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Media\Item\Iface::class, $return ); |
225
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
226
|
|
|
$this->assertTrue( $this->object->isModified() ); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
public function testGetTimeModified() |
231
|
|
|
{ |
232
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
|
236
|
|
|
public function testGetTimeCreated() |
237
|
|
|
{ |
238
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
|
242
|
|
|
public function testGetEditor() |
243
|
|
|
{ |
244
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->getEditor() ); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
|
248
|
|
|
public function testGetName() |
249
|
|
|
{ |
250
|
|
|
$this->assertEquals( 'testPicture', $this->object->getName() ); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
|
254
|
|
|
public function testGetNameProperties() |
255
|
|
|
{ |
256
|
|
|
$values = ['media.value' => 'title', 'media.type' => 'name', 'languageid' => null]; |
257
|
|
|
$propItems = [new \Aimeos\MShop\Common\Item\Property\Standard( 'media.', $values )]; |
258
|
|
|
$object = new \Aimeos\MShop\Media\Item\Standard( $this->values, [], [], $propItems ); |
259
|
|
|
|
260
|
|
|
$this->assertEquals( 'title', $object->getName() ); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
|
264
|
|
|
public function testGetResourceType() |
265
|
|
|
{ |
266
|
|
|
$this->assertEquals( 'media', $this->object->getResourceType() ); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
|
270
|
|
|
public function testFromArray() |
271
|
|
|
{ |
272
|
|
|
$item = new \Aimeos\MShop\Media\Item\Standard(); |
273
|
|
|
|
274
|
|
|
$list = $entries = array( |
275
|
|
|
'media.id' => 1, |
276
|
|
|
'media.domain' => 'product', |
277
|
|
|
'media.label' => 'test item', |
278
|
|
|
'media.languageid' => 'de', |
279
|
|
|
'media.type' => 'test', |
280
|
|
|
'media.mimetype' => 'image/jpeg', |
281
|
|
|
'media.preview' => [1 => 'preview.jpg'], |
282
|
|
|
'media.url' => 'image.jpg', |
283
|
|
|
'media.status' => 0, |
284
|
|
|
); |
285
|
|
|
|
286
|
|
|
$item = $item->fromArray( $entries, true ); |
287
|
|
|
|
288
|
|
|
$this->assertEquals( [], $entries ); |
289
|
|
|
$this->assertEquals( $list['media.id'], $item->getId() ); |
290
|
|
|
$this->assertEquals( $list['media.domain'], $item->getDomain() ); |
291
|
|
|
$this->assertEquals( $list['media.label'], $item->getLabel() ); |
292
|
|
|
$this->assertEquals( $list['media.languageid'], $item->getLanguageId() ); |
293
|
|
|
$this->assertEquals( $list['media.type'], $item->getType() ); |
294
|
|
|
$this->assertEquals( $list['media.mimetype'], $item->getMimetype() ); |
295
|
|
|
$this->assertEquals( $list['media.preview'], $item->getPreviews() ); |
296
|
|
|
$this->assertEquals( $list['media.url'], $item->getUrl() ); |
297
|
|
|
$this->assertEquals( $list['media.status'], $item->getStatus() ); |
298
|
|
|
$this->assertNull( $item->getSiteId() ); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
|
302
|
|
|
public function testToArray() |
303
|
|
|
{ |
304
|
|
|
$arrayObject = $this->object->toArray( true ); |
305
|
|
|
|
306
|
|
|
$this->assertEquals( count( $this->values ) - 1, count( $arrayObject ) ); |
307
|
|
|
|
308
|
|
|
$this->assertEquals( $this->object->getId(), $arrayObject['media.id'] ); |
309
|
|
|
$this->assertEquals( $this->object->getSiteId(), $arrayObject['media.siteid'] ); |
310
|
|
|
$this->assertEquals( $this->object->getDomain(), $arrayObject['media.domain'] ); |
311
|
|
|
$this->assertEquals( $this->object->getLabel(), $arrayObject['media.label'] ); |
312
|
|
|
$this->assertEquals( $this->object->getLanguageId(), $arrayObject['media.languageid'] ); |
313
|
|
|
$this->assertEquals( $this->object->getMimeType(), $arrayObject['media.mimetype'] ); |
314
|
|
|
$this->assertEquals( $this->object->getType(), $arrayObject['media.type'] ); |
315
|
|
|
$this->assertEquals( $this->object->getUrl(), $arrayObject['media.url'] ); |
316
|
|
|
$this->assertEquals( $this->object->getPreviews(), $arrayObject['media.preview'] ); |
317
|
|
|
$this->assertEquals( $this->object->getStatus(), $arrayObject['media.status'] ); |
318
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['media.ctime'] ); |
319
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $arrayObject['media.mtime'] ); |
320
|
|
|
$this->assertEquals( $this->object->getEditor(), $arrayObject['media.editor'] ); |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
|
324
|
|
|
public function testIsAvailable() |
325
|
|
|
{ |
326
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
327
|
|
|
$this->object->setAvailable( false ); |
328
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
|
332
|
|
|
public function testIsAvailableOnStatus() |
333
|
|
|
{ |
334
|
|
|
$this->assertTrue( $this->object->isAvailable() ); |
335
|
|
|
$this->object->setStatus( 0 ); |
336
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
337
|
|
|
$this->object->setStatus( -1 ); |
338
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
} |
342
|
|
|
|