aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2015-11-07 16:30:56 +0100
committerArthurHoaro <arthur@hoa.ro>2015-11-07 16:30:56 +0100
commit840caea64f8c37f035fb3525f63153eb68492731 (patch)
tree792022187b13f1e65b658f10e755c683f4a2606c
parentb17c19ff76dc63b9ad10d26b244630b59e691e5c (diff)
downloadShaarli-840caea64f8c37f035fb3525f63153eb68492731.tar.gz
Shaarli-840caea64f8c37f035fb3525f63153eb68492731.tar.zst
Shaarli-840caea64f8c37f035fb3525f63153eb68492731.zip
Add unit tests for Playvideos plugin
+ coding style
-rw-r--r--plugins/playvideos/playvideos.php14
-rw-r--r--tests/plugins/PluginPlayvideosTest.php61
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 */
9function hook_playvideos_render_header($data) { 16function 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 */
23function hook_playvideos_render_footer($data) { 32function 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
7require_once 'plugins/playvideos/playvideos.php';
8require_once 'application/Router.php';
9
10/**
11 * Class PluginPlayvideosTest
12 * Unit test for the PlayVideos plugin
13 */
14class 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}