diff options
-rw-r--r-- | plugins/playvideos/playvideos.php | 14 | ||||
-rw-r--r-- | tests/plugins/PluginPlayvideosTest.php | 61 |
2 files changed, 73 insertions, 2 deletions
diff --git a/plugins/playvideos/playvideos.php b/plugins/playvideos/playvideos.php index 9918453c..0a80aa58 100644 --- a/plugins/playvideos/playvideos.php +++ b/plugins/playvideos/playvideos.php | |||
@@ -1,12 +1,20 @@ | |||
1 | <?php | 1 | <?php |
2 | /** | ||
3 | * Plugin PlayVideos | ||
4 | * | ||
5 | * Add a button in the toolbar allowing to watch all videos. | ||
6 | * Note: this plugin adds jQuery. | ||
7 | */ | ||
2 | 8 | ||
3 | /** | 9 | /** |
4 | * When linklist is displayed, add play videos to header's toolbar. | 10 | * When linklist is displayed, add play videos to header's toolbar. |
5 | * | 11 | * |
6 | * @param array $data - header data. | 12 | * @param array $data - header data. |
13 | * | ||
7 | * @return mixed - header data with playvideos toolbar item. | 14 | * @return mixed - header data with playvideos toolbar item. |
8 | */ | 15 | */ |
9 | function hook_playvideos_render_header($data) { | 16 | function hook_playvideos_render_header($data) |
17 | { | ||
10 | if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) { | 18 | if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) { |
11 | $data['buttons_toolbar'][] = file_get_contents(PluginManager::$PLUGINS_PATH . '/playvideos/playvideos.html'); | 19 | $data['buttons_toolbar'][] = file_get_contents(PluginManager::$PLUGINS_PATH . '/playvideos/playvideos.html'); |
12 | } | 20 | } |
@@ -18,9 +26,11 @@ function hook_playvideos_render_header($data) { | |||
18 | * When linklist is displayed, include playvideos JS files. | 26 | * When linklist is displayed, include playvideos JS files. |
19 | * | 27 | * |
20 | * @param array $data - footer data. | 28 | * @param array $data - footer data. |
29 | * | ||
21 | * @return mixed - footer data with playvideos JS files added. | 30 | * @return mixed - footer data with playvideos JS files added. |
22 | */ | 31 | */ |
23 | function hook_playvideos_render_footer($data) { | 32 | function hook_playvideos_render_footer($data) |
33 | { | ||
24 | if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) { | 34 | if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) { |
25 | $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/playvideos/jquery-1.11.2.min.js'; | 35 | $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/playvideos/jquery-1.11.2.min.js'; |
26 | $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/playvideos/youtube_playlist.js'; | 36 | $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/playvideos/youtube_playlist.js'; |
diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php new file mode 100644 index 00000000..be1ef774 --- /dev/null +++ b/tests/plugins/PluginPlayvideosTest.php | |||
@@ -0,0 +1,61 @@ | |||
1 | <?php | ||
2 | |||
3 | /** | ||
4 | * PluginPlayvideosTest.php | ||
5 | */ | ||
6 | |||
7 | require_once 'plugins/playvideos/playvideos.php'; | ||
8 | require_once 'application/Router.php'; | ||
9 | |||
10 | /** | ||
11 | * Class PluginPlayvideosTest | ||
12 | * Unit test for the PlayVideos plugin | ||
13 | */ | ||
14 | class PluginPlayvideosTest extends PHPUnit_Framework_TestCase | ||
15 | { | ||
16 | /** | ||
17 | * Reset plugin path | ||
18 | */ | ||
19 | function setUp() | ||
20 | { | ||
21 | PluginManager::$PLUGINS_PATH = 'plugins'; | ||
22 | } | ||
23 | |||
24 | /** | ||
25 | * Test render_linklist hook. | ||
26 | */ | ||
27 | function testPlayvideosHeader() | ||
28 | { | ||
29 | $str = 'stuff'; | ||
30 | $data = array($str => $str); | ||
31 | $data['_PAGE_'] = Router::$PAGE_LINKLIST; | ||
32 | |||
33 | $data = hook_playvideos_render_header($data); | ||
34 | $this->assertEquals($str, $data[$str]); | ||
35 | $this->assertEquals(1, count($data['buttons_toolbar'])); | ||
36 | |||
37 | $data = array($str => $str); | ||
38 | $data['_PAGE_'] = $str; | ||
39 | $this->assertEquals($str, $data[$str]); | ||
40 | $this->assertArrayNotHasKey('buttons_toolbar', $data); | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * Test render_footer hook. | ||
45 | */ | ||
46 | function testPlayvideosFooter() | ||
47 | { | ||
48 | $str = 'stuff'; | ||
49 | $data = array($str => $str); | ||
50 | $data['_PAGE_'] = Router::$PAGE_LINKLIST; | ||
51 | |||
52 | $data = hook_playvideos_render_footer($data); | ||
53 | $this->assertEquals($str, $data[$str]); | ||
54 | $this->assertEquals(2, count($data['js_files'])); | ||
55 | |||
56 | $data = array($str => $str); | ||
57 | $data['_PAGE_'] = $str; | ||
58 | $this->assertEquals($str, $data[$str]); | ||
59 | $this->assertArrayNotHasKey('js_files', $data); | ||
60 | } | ||
61 | } | ||