Completed
Push — master ( db1bc0...975b10 )
by
unknown
03:49
created

MediaTest::testGetMediaFileExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
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');
0 ignored issues
show
Documentation introduced by
'identifier_123' is of type string, but the function expects a boolean.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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