|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MediaMonks\SonataMediaBundle\Tests\Unit\Provider; |
|
4
|
|
|
|
|
5
|
|
|
use MediaMonks\SonataMediaBundle\Exception\InvalidProviderUrlException; |
|
6
|
|
|
use MediaMonks\SonataMediaBundle\Provider\AbstractProvider; |
|
7
|
|
|
use MediaMonks\SonataMediaBundle\Provider\YouTubeProvider; |
|
8
|
|
|
|
|
9
|
|
|
class YoutubeProviderTest extends \PHPUnit_Framework_TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
public function testParseProviderReference() |
|
12
|
|
|
{ |
|
13
|
|
|
$youtube = new YouTubeProvider(); |
|
14
|
|
|
$this->assertEquals('uN2nqdRLhQ8', $youtube->parseProviderReference('https://www.youtube.com/watch?v=uN2nqdRLhQ8')); |
|
15
|
|
|
$this->assertEquals('uN2nqdRLhQ8', $youtube->parseProviderReference('https://www.youtube.com/watch?v=uN2nqdRLhQ8&foo=bar')); |
|
16
|
|
|
$this->assertEquals('uN2nqdRLhQ8', $youtube->parseProviderReference('https://youtu.be/uN2nqdRLhQ8')); |
|
17
|
|
|
$this->assertEquals('uN2nqdRLhQ8', $youtube->parseProviderReference('https://youtu.be/uN2nqdRLhQ8?foo=bar')); |
|
18
|
|
|
$this->assertEquals('uN2nqdRLhQ8', $youtube->parseProviderReference('uN2nqdRLhQ8')); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testParseInvalidProviderReference() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->setExpectedException(InvalidProviderUrlException::class); |
|
24
|
|
|
$youtube = new YouTubeProvider(); |
|
25
|
|
|
$youtube->parseProviderReference('https://www.youtube.com/watch?foo=bar'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testParseInvalidProviderReference2() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->setExpectedException(InvalidProviderUrlException::class); |
|
31
|
|
|
$youtube = new YouTubeProvider(); |
|
32
|
|
|
$youtube->parseProviderReference('https://www.youtube.com'); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testParseInvalidProviderReferenceShort() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->setExpectedException(InvalidProviderUrlException::class); |
|
38
|
|
|
$youtube = new YouTubeProvider(); |
|
39
|
|
|
$youtube->parseProviderReference('https://youtu.be'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
View Code Duplication |
public function testSupports() |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
$provider = new YouTubeProvider(); |
|
45
|
|
|
$this->assertFalse($provider->supports(AbstractProvider::SUPPORT_DOWNLOAD)); |
|
46
|
|
|
$this->assertTrue($provider->supports(AbstractProvider::SUPPORT_EMBED)); |
|
47
|
|
|
$this->assertTrue($provider->supports(AbstractProvider::SUPPORT_IMAGE)); |
|
48
|
|
|
$this->assertFalse($provider->supports('foo')); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.