<?php
+/**
+ * Plugin readityourself
+ */
+
// If we're talking about https://github.com/memiks/readityourself
// it seems kinda dead.
// Not tested.
}
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) {
--- /dev/null
+<?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);
+ }
+}