22
33use PHPUnit \Framework \TestCase ;
44use hmerritt \Imdb ;
5+ use hmerritt \Cache ;
56use hmerritt \Response ;
67
78class ImdbTest extends TestCase {
@@ -22,26 +23,55 @@ public function testFilm()
2223 $ this ->assertEquals ('nm0000995 ' , $ film ['cast ' ][0 ]["actor_id " ]);
2324 }
2425
25- public function testSearch ()
26+ public function testFilmBySearching ()
2627 {
2728 $ imdb = new Imdb ;
28- $ search = $ imdb ->search ('Interstellar ' );
29+ $ film = $ imdb ->film ('Interstellar ' , [ ' cache ' => false ] );
2930
30- $ this ->assertEquals ('Interstellar ' , $ search ['titles ' ][0 ]['title ' ]);
31- $ this ->assertEquals ('tt0816692 ' , $ search ['titles ' ][0 ]['id ' ]);
31+ $ this ->assertEquals ('tt0816692 ' , $ film ['id ' ]);
32+ $ this ->assertEquals ('Interstellar ' , $ film ['title ' ]);
33+ $ this ->assertEquals ('2h 49min ' , $ film ['length ' ]);
34+ $ this ->assertEquals ('2014 ' , $ film ['year ' ]);
35+ $ this ->assertEquals ('vi1586278169 ' , $ film ['trailer ' ]["id " ]);
36+ $ this ->assertEquals ('https://www.imdb.com/videoplayer/vi1586278169 ' , $ film ['trailer ' ]["link " ]);
37+ $ this ->assertEquals ('Murph (Older) ' , $ film ['cast ' ][0 ]["character " ]);
38+ $ this ->assertEquals ('Ellen Burstyn ' , $ film ['cast ' ][0 ]["actor " ]);
39+ $ this ->assertEquals ('nm0000995 ' , $ film ['cast ' ][0 ]["actor_id " ]);
3240 }
3341
3442 public function testFilmOptions ()
3543 {
3644 $ imdb = new Imdb ;
45+ $ cache = new Cache ;
3746 $ film = $ imdb ->film ('tt0065531 ' , [
3847 'cache ' => false ,
3948 'curlHeaders ' => ['Accept-Language: de-DE, de;q=0.5 ' ],
40- 'techSpecs ' => false ,
49+ 'techSpecs ' => false
4150 ]);
4251
4352 $ this ->assertEquals ('Vier im roten Kreis ' , $ film ['title ' ]);
4453 $ this ->assertEquals (0 , count ($ film ['technical_specs ' ]));
54+ $ this ->assertEquals (false , $ cache ->has ('tt0065531 ' ));
55+ }
56+
57+ public function testFilmCache ()
58+ {
59+ $ imdb = new Imdb ;
60+ $ cache = new Cache ;
61+ $ film = $ imdb ->film ('tt0816692 ' , [ 'techSpecs ' => false ]);
62+ $ cache_film = $ cache ->get ('tt0816692 ' )->film ;
63+
64+ $ this ->assertEquals (true , $ cache ->has ('tt0816692 ' ));
65+ $ this ->assertEquals ('Interstellar ' , $ cache_film ['title ' ]);
66+ }
67+
68+ public function testSearch ()
69+ {
70+ $ imdb = new Imdb ;
71+ $ search = $ imdb ->search ('Interstellar ' );
72+
73+ $ this ->assertEquals ('Interstellar ' , $ search ['titles ' ][0 ]['title ' ]);
74+ $ this ->assertEquals ('tt0816692 ' , $ search ['titles ' ][0 ]['id ' ]);
4575 }
4676
4777 public function test404Page ()
@@ -50,15 +80,18 @@ public function test404Page()
5080 $ response = new Response ;
5181
5282 $ film = $ imdb ->film ('ttest404 ' , [ 'cache ' => false ]);
83+ $ film_search = $ imdb ->film ('interstellartest4040404040404 ' , [ 'cache ' => false ]);
5384 $ search = $ imdb ->search ('ttest404040404004 ' , [ 'category ' => 'test404 ' ]);
5485
5586 $ emptyResponse = [
5687 'film ' => $ response ->default ('film ' ),
88+ 'film_search ' => $ response ->default ('film ' ),
5789 'search ' => $ response ->default ('search ' ),
5890 ];
5991 $ emptyResponse ['film ' ]['id ' ] = 'ttest404 ' ;
6092
6193 $ this ->assertEquals ($ emptyResponse ['film ' ], $ film );
94+ $ this ->assertEquals ($ emptyResponse ['film_search ' ], $ film_search );
6295 $ this ->assertEquals ($ emptyResponse ['search ' ], $ search );
6396 }
6497
0 commit comments