|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata Project package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\MediaBundle\Tests\Entity; |
|
13
|
|
|
|
|
14
|
|
|
class MediaTest extends \PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function testMetadata() |
|
17
|
|
|
{ |
|
18
|
|
|
$media = new Media(); |
|
19
|
|
|
|
|
20
|
|
|
$media->setProviderMetadata(array('thumbnail_url' => 'http://pasloin.com/thumb.png')); |
|
21
|
|
|
|
|
22
|
|
|
$this->assertSame($media->getMetadataValue('thumbnail_url'), 'http://pasloin.com/thumb.png', '::getMetadataValue() return the good value'); |
|
23
|
|
|
$this->assertSame($media->getMetadataValue('thumbnail_url1', 'default'), 'default', '::getMetadataValue() return the default'); |
|
24
|
|
|
$this->assertSame($media->getMetadataValue('thumbnail_url1'), null, '::getMetadataValue() return the null value'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testStatusList() |
|
28
|
|
|
{ |
|
29
|
|
|
$status = Media::getStatusList(); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertInternalType('array', $status); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testSetGet() |
|
35
|
|
|
{ |
|
36
|
|
|
$media = new Media(); |
|
37
|
|
|
$media->setName('MediaBundle'); |
|
38
|
|
|
$media->setSize(12); |
|
39
|
|
|
$media->setDescription('description'); |
|
40
|
|
|
$media->setEnabled(true); |
|
41
|
|
|
$media->setProviderName('name'); |
|
42
|
|
|
$media->setLength(2); |
|
43
|
|
|
$media->setCopyright('copyleft'); |
|
44
|
|
|
$media->setAuthorName('Thomas'); |
|
45
|
|
|
$media->setCdnIsFlushable(true); |
|
46
|
|
|
$media->setCdnFlushIdentifier('identifier_123'); |
|
|
|
|
|
|
47
|
|
|
$media->setCdnFlushAt(new \DateTime()); |
|
48
|
|
|
$media->setContentType('sonata/media'); |
|
49
|
|
|
$media->setCreatedAt(new \DateTime()); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertSame(12, $media->getSize()); |
|
52
|
|
|
$this->assertSame('description', $media->getDescription()); |
|
53
|
|
|
$this->assertTrue($media->getEnabled()); |
|
54
|
|
|
$this->assertSame('name', $media->getProviderName()); |
|
55
|
|
|
$this->assertSame(2, $media->getLength()); |
|
56
|
|
|
$this->assertSame('copyleft', $media->getCopyright()); |
|
57
|
|
|
$this->assertSame('Thomas', $media->getAuthorName()); |
|
58
|
|
|
$this->assertTrue($media->getCdnIsFlushable()); |
|
59
|
|
|
$this->assertSame('identifier_123', $media->getCdnFlushIdentifier()); |
|
60
|
|
|
$this->assertInstanceOf('DateTime', $media->getCdnFlushAt()); |
|
61
|
|
|
$this->assertInstanceOf('DateTime', $media->getCreatedAt()); |
|
62
|
|
|
$this->assertSame('sonata/media', $media->getContentType()); |
|
63
|
|
|
$this->assertSame('MediaBundle', (string) $media); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertNull($media->getMetadataValue('foo')); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function testGetMediaFileExtension() |
|
69
|
|
|
{ |
|
70
|
|
|
$media = new Media(); |
|
71
|
|
|
|
|
72
|
|
|
$media->setProviderReference('https://sonata-project.org/bundles/sonatageneral/images/logo-small.png?some-query-string=1'); |
|
73
|
|
|
$this->assertSame('png', $media->getExtension(), 'extension should not contain query strings'); |
|
74
|
|
|
|
|
75
|
|
|
$media->setProviderReference('https://sonata-project.org/bundles/sonatageneral/images/logo-small.png#some-hash'); |
|
76
|
|
|
$this->assertSame('png', $media->getExtension(), 'extension should not contain hashes'); |
|
77
|
|
|
|
|
78
|
|
|
$media->setProviderReference('https://sonata-project.org/bundles/sonatageneral/images/logo-small.png?some-query-string=1#with-some-hash'); |
|
79
|
|
|
$this->assertSame('png', $media->getExtension(), 'extension should not contain query strings or hashes'); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: