unit tests for readityourself plugin + remove hard error

This commit is contained in:
ArthurHoaro 2015-11-08 12:16:55 +01:00
parent 75b69987b3
commit b11c8f25df
2 changed files with 90 additions and 7 deletions

View file

@ -1,5 +1,9 @@
<?php
/**
* Plugin readityourself
*/
// If we're talking about https://github.com/memiks/readityourself
// it seems kinda dead.
// Not tested.
@ -10,20 +14,24 @@ if (is_file(PluginManager::$PLUGINS_PATH . '/readityourself/config.php')) {
}
if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) {
header('Content-Type: text/plain; charset=utf-8');
echo 'ReadItYourself plugin error: '. PHP_EOL;
echo ' Please copy "plugins/readityourself/config.php.dist" to config.php and configure your readityourself URL.'. PHP_EOL;
echo ' You can also define "$GLOBALS[\'plugins\'][\'READITYOUSELF_URL\']" in your global Shaarli config.php file.';
exit;
$GLOBALS['plugins']['errors'][] = 'Wallabag plugin error: '.
'Please define "$GLOBALS[\'plugins\'][\'WALLABAG_URL\']" '.
'in "plugins/wallabag/config.php" or in your Shaarli config.php file.';
}
/**
* Add readityourself icon to link_plugin when rendering linklist.
*
* @param $data - linklist data.
* @param mixed $data - linklist data.
*
* @return mixed - linklist data with readityourself plugin.
*/
function hook_readityourself_render_linklist($data) {
function hook_readityourself_render_linklist($data)
{
if (!isset($GLOBALS['plugins']['READITYOUSELF_URL'])) {
return $data;
}
$readityourself_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/readityourself/readityourself.html');
foreach ($data['links'] as &$value) {

View file

@ -0,0 +1,75 @@
<?php
/**
* PluginReadityourselfTest.php.php
*/
require_once 'plugins/readityourself/readityourself.php';
/**
* Class PluginWallabagTest
* Unit test for the Wallabag plugin
*/
class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
{
/**
* Reset plugin path
*/
function setUp()
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Test render_linklist hook.
*/
function testReadityourselfLinklist()
{
$GLOBALS['plugins']['READITYOUSELF_URL'] = 'value';
$str = 'http://randomstr.com/test';
$data = array(
'title' => $str,
'links' => array(
array(
'url' => $str,
)
)
);
$data = hook_readityourself_render_linklist($data);
$link = $data['links'][0];
// data shouldn't be altered
$this->assertEquals($str, $data['title']);
$this->assertEquals($str, $link['url']);
// plugin data
$this->assertEquals(1, count($link['link_plugin']));
$this->assertNotFalse(strpos($link['link_plugin'][0], $str));
}
/**
* Test without config: nothing should happened.
*/
function testReadityourselfLinklistWithoutConfig()
{
unset($GLOBALS['plugins']['READITYOUSELF_URL']);
$str = 'http://randomstr.com/test';
$data = array(
'title' => $str,
'links' => array(
array(
'url' => $str,
)
)
);
$data = hook_readityourself_render_linklist($data);
$link = $data['links'][0];
// data shouldn't be altered
$this->assertEquals($str, $data['title']);
$this->assertEquals($str, $link['url']);
// plugin data
$this->assertArrayNotHasKey('link_plugin', $link);
}
}