9
9
namespace RicardoFiorani \Test ;
10
10
11
11
use PHPUnit_Framework_TestCase ;
12
+ use RicardoFiorani \Container \Factory \ServicesContainerFactory ;
12
13
use RicardoFiorani \Detector \VideoServiceDetector ;
13
14
use RicardoFiorani \Exception \ServiceNotAvailableException ;
14
15
15
16
class ServiceDetectorTest extends PHPUnit_Framework_TestCase
16
17
{
17
18
/**
18
- * @dataProvider youtubeDataProvider
19
+ * @dataProvider videoUrlProvider
19
20
* @param $url
20
- * @param $expectedEmbedCode
21
+ * @param $expectedServiceName
21
22
* @throws ServiceNotAvailableException
22
23
*/
23
- public function testCanParseYoutubeUrl ($ url , $ expectedEmbedCode )
24
+ public function testCanParseUrl ($ url , $ expectedServiceName )
24
25
{
25
26
$ detector = new VideoServiceDetector ();
26
27
$ video = $ detector ->parse ($ url );
27
- $ this ->assertEquals ( $ video -> getEmbedUrl () , $ expectedEmbedCode );
28
+ $ this ->assertInstanceOf ( $ expectedServiceName , $ video );
28
29
}
29
30
30
- public function youtubeDataProvider ()
31
+ /**
32
+ * @return array
33
+ */
34
+ public function videoUrlProvider ()
31
35
{
32
36
33
37
return array (
34
38
'Normal Youtube URL ' => array (
35
39
'https://www.youtube.com/watch?v=mWRsgZuwf_8 ' ,
36
- 'http://www.youtube.com/embed/mWRsgZuwf_8 ' ,
40
+ '\\ RicardoFiorani \\ Adapter \\ Youtube \\ YoutubeServiceAdapter ' ,
37
41
),
38
42
'Short Youtube URL ' => array (
39
43
'https://youtu.be/JMLBOKVfHaA ' ,
40
- 'http://www.youtube.com/embed/JMLBOKVfHaA ' ,
44
+ 'RicardoFiorani \\ Adapter \\ Youtube \\ YoutubeServiceAdapter ' ,
41
45
),
42
46
'Embed Youtube URL ' => array (
43
47
'<iframe width="420" height="315" src="https://www.youtube.com/embed/vwp9JkaESdg" frameborder="0" allowfullscreen></iframe> ' ,
44
- 'http://www.youtube.com/embed/vwp9JkaESdg ' ,
48
+ '\\RicardoFiorani \\Adapter \\Youtube \\YoutubeServiceAdapter ' ,
49
+ ),
50
+ 'Common Vimeo URL ' => array (
51
+ 'https://vimeo.com/137781541 ' ,
52
+ '\\RicardoFiorani \\Adapter \\Vimeo \\VimeoServiceAdapter ' ,
53
+ ),
54
+ 'Commom Dailymotion URL ' => array (
55
+ 'http://www.dailymotion.com/video/x332a71_que-categoria-jogador-lucas-lima-faz-golaco-em-treino-do-santos_sport ' ,
56
+ '\\RicardoFiorani \\Adapter \\Dailymotion \\DailyMotionServiceAdapter ' ,
45
57
),
46
58
);
47
59
}
48
60
49
61
/**
50
- * @dataProvider vimeoDataProvider
51
- * @param string $url
52
- * @param string $expectedEmbedCode
62
+ * @throws ServiceNotAvailableException
63
+ * @dataProvider invalidVideoUrlProvider
53
64
*/
54
- public function testCanParseVimeoUrl ($ url, $ expectedEmbedCode )
65
+ public function testThrowsExceptionOnInvalidUrl ($ url )
55
66
{
56
67
$ detector = new VideoServiceDetector ();
68
+ $ this ->setExpectedException ('\\RicardoFiorani \\Exception \\ServiceNotAvailableException ' );
57
69
$ video = $ detector ->parse ($ url );
58
- $ this ->assertEquals ($ video ->getEmbedUrl (), $ expectedEmbedCode );
59
70
}
60
71
61
- public function vimeoDataProvider ()
72
+ /**
73
+ * @return array
74
+ */
75
+ public function invalidVideoUrlProvider ($ url )
62
76
{
63
77
return array (
64
- 'Common Vimeo URL ' => array (
65
- 'https://vimeo.com/137781541 ' ,
66
- 'http://player.vimeo.com/video/137781541 '
67
- )
78
+ array (
79
+ 'http://tvuol.uol.com.br/video/dirigindo-pelo-mundo-de-final-fantasy-xv-0402CC9B3764E4A95326 ' ,
80
+ ),
81
+ array (
82
+ 'https://www.google.com.br/ ' ,
83
+ ),
84
+ array (
85
+ 'https://www.youtube.com/ ' ,
86
+ ),
68
87
);
69
88
}
89
+
90
+ /**
91
+ * @dataProvider videoUrlProvider
92
+ */
93
+ public function testServiceDetectorDontReparseSameUrl ($ url )
94
+ {
95
+ $ detector = new VideoServiceDetector ();
96
+ $ video = $ detector ->parse ($ url );
97
+
98
+ $ this ->assertSame ($ video , $ detector ->parse ($ url ));
99
+ }
100
+
101
+ public function testServiceContainerGetter ()
102
+ {
103
+ $ detector = new VideoServiceDetector ();
104
+ $ this ->assertInstanceOf ('RicardoFiorani \\Container \\ServicesContainer ' , $ detector ->getServiceContainer ());
105
+ }
106
+
107
+ public function testServiceContainerSetter ()
108
+ {
109
+ $ detector = new VideoServiceDetector ();
110
+ $ serviceContainer = ServicesContainerFactory::createNewServiceDetector ();
111
+ $ detector ->setServiceContainer ($ serviceContainer );
112
+ $ this ->assertSame ($ serviceContainer , $ detector ->getServiceContainer ());
113
+ }
114
+
115
+
70
116
}
0 commit comments