Add unit tests for Playvideos plugin

+ coding style
This commit is contained in:
ArthurHoaro 2015-11-07 16:30:56 +01:00
parent b17c19ff76
commit 840caea64f
2 changed files with 73 additions and 2 deletions

View file

@ -1,12 +1,20 @@
<?php <?php
/**
* Plugin PlayVideos
*
* Add a button in the toolbar allowing to watch all videos.
* Note: this plugin adds jQuery.
*/
/** /**
* When linklist is displayed, add play videos to header's toolbar. * When linklist is displayed, add play videos to header's toolbar.
* *
* @param array $data - header data. * @param array $data - header data.
*
* @return mixed - header data with playvideos toolbar item. * @return mixed - header data with playvideos toolbar item.
*/ */
function hook_playvideos_render_header($data) { function hook_playvideos_render_header($data)
{
if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) { if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) {
$data['buttons_toolbar'][] = file_get_contents(PluginManager::$PLUGINS_PATH . '/playvideos/playvideos.html'); $data['buttons_toolbar'][] = file_get_contents(PluginManager::$PLUGINS_PATH . '/playvideos/playvideos.html');
} }
@ -18,9 +26,11 @@ function hook_playvideos_render_header($data) {
* When linklist is displayed, include playvideos JS files. * When linklist is displayed, include playvideos JS files.
* *
* @param array $data - footer data. * @param array $data - footer data.
*
* @return mixed - footer data with playvideos JS files added. * @return mixed - footer data with playvideos JS files added.
*/ */
function hook_playvideos_render_footer($data) { function hook_playvideos_render_footer($data)
{
if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) { if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) {
$data['js_files'][] = PluginManager::$PLUGINS_PATH . '/playvideos/jquery-1.11.2.min.js'; $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/playvideos/jquery-1.11.2.min.js';
$data['js_files'][] = PluginManager::$PLUGINS_PATH . '/playvideos/youtube_playlist.js'; $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/playvideos/youtube_playlist.js';

View file

@ -0,0 +1,61 @@
<?php
/**
* PluginPlayvideosTest.php
*/
require_once 'plugins/playvideos/playvideos.php';
require_once 'application/Router.php';
/**
* Class PluginPlayvideosTest
* Unit test for the PlayVideos plugin
*/
class PluginPlayvideosTest extends PHPUnit_Framework_TestCase
{
/**
* Reset plugin path
*/
function setUp()
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Test render_linklist hook.
*/
function testPlayvideosHeader()
{
$str = 'stuff';
$data = array($str => $str);
$data['_PAGE_'] = Router::$PAGE_LINKLIST;
$data = hook_playvideos_render_header($data);
$this->assertEquals($str, $data[$str]);
$this->assertEquals(1, count($data['buttons_toolbar']));
$data = array($str => $str);
$data['_PAGE_'] = $str;
$this->assertEquals($str, $data[$str]);
$this->assertArrayNotHasKey('buttons_toolbar', $data);
}
/**
* Test render_footer hook.
*/
function testPlayvideosFooter()
{
$str = 'stuff';
$data = array($str => $str);
$data['_PAGE_'] = Router::$PAGE_LINKLIST;
$data = hook_playvideos_render_footer($data);
$this->assertEquals($str, $data[$str]);
$this->assertEquals(2, count($data['js_files']));
$data = array($str => $str);
$data['_PAGE_'] = $str;
$this->assertEquals($str, $data[$str]);
$this->assertArrayNotHasKey('js_files', $data);
}
}