Merge pull request from shaarli/plugin-proposition

Plugin proposition
This commit is contained in:
Arthur 2015-11-08 13:29:32 +01:00
commit fd006c630b
61 changed files with 13270 additions and 484 deletions

354
tests/ConfigTest.php Executable file → Normal file
View file

@ -1,177 +1,177 @@
<?php
/**
* Config' tests
*/
require_once 'application/Config.php';
/**
* Unitary tests for Shaarli config related functions
*/
class ConfigTest extends PHPUnit_Framework_TestCase
{
// Configuration input set.
private static $_configFields;
/**
* Executed before each test.
*/
public function setUp()
{
self::$_configFields = array(
'login' => 'login',
'hash' => 'hash',
'salt' => 'salt',
'timezone' => 'Europe/Paris',
'title' => 'title',
'titleLink' => 'titleLink',
'redirector' => '',
'disablesessionprotection' => false,
'privateLinkByDefault' => false,
'config' => array(
'CONFIG_FILE' => 'tests/config.php',
'DATADIR' => 'tests',
'config1' => 'config1data',
'config2' => 'config2data',
)
);
}
/**
* Executed after each test.
*
* @return void
*/
public function tearDown()
{
if (is_file(self::$_configFields['config']['CONFIG_FILE'])) {
unlink(self::$_configFields['config']['CONFIG_FILE']);
}
}
/**
* Test writeConfig function, valid use case, while being logged in.
*/
public function testWriteConfig()
{
writeConfig(self::$_configFields, true);
include self::$_configFields['config']['CONFIG_FILE'];
$this->assertEquals(self::$_configFields['login'], $GLOBALS['login']);
$this->assertEquals(self::$_configFields['hash'], $GLOBALS['hash']);
$this->assertEquals(self::$_configFields['salt'], $GLOBALS['salt']);
$this->assertEquals(self::$_configFields['timezone'], $GLOBALS['timezone']);
$this->assertEquals(self::$_configFields['title'], $GLOBALS['title']);
$this->assertEquals(self::$_configFields['titleLink'], $GLOBALS['titleLink']);
$this->assertEquals(self::$_configFields['redirector'], $GLOBALS['redirector']);
$this->assertEquals(self::$_configFields['disablesessionprotection'], $GLOBALS['disablesessionprotection']);
$this->assertEquals(self::$_configFields['privateLinkByDefault'], $GLOBALS['privateLinkByDefault']);
$this->assertEquals(self::$_configFields['config']['config1'], $GLOBALS['config']['config1']);
$this->assertEquals(self::$_configFields['config']['config2'], $GLOBALS['config']['config2']);
}
/**
* Test writeConfig option while logged in:
* 1. init fields.
* 2. update fields, add new sub config, add new root config.
* 3. rewrite config.
* 4. check result.
*/
public function testWriteConfigFieldUpdate()
{
writeConfig(self::$_configFields, true);
self::$_configFields['title'] = 'ok';
self::$_configFields['config']['config1'] = 'ok';
self::$_configFields['config']['config_new'] = 'ok';
self::$_configFields['new'] = 'should not be saved';
writeConfig(self::$_configFields, true);
include self::$_configFields['config']['CONFIG_FILE'];
$this->assertEquals('ok', $GLOBALS['title']);
$this->assertEquals('ok', $GLOBALS['config']['config1']);
$this->assertEquals('ok', $GLOBALS['config']['config_new']);
$this->assertFalse(isset($GLOBALS['new']));
}
/**
* Test writeConfig function with an empty array.
*
* @expectedException MissingFieldConfigException
*/
public function testWriteConfigEmpty()
{
writeConfig(array(), true);
}
/**
* Test writeConfig function with a missing mandatory field.
*
* @expectedException MissingFieldConfigException
*/
public function testWriteConfigMissingField()
{
unset(self::$_configFields['login']);
writeConfig(self::$_configFields, true);
}
/**
* Test writeConfig function while being logged out, and there is no config file existing.
*/
public function testWriteConfigLoggedOutNoFile()
{
writeConfig(self::$_configFields, false);
}
/**
* Test writeConfig function while being logged out, and a config file already exists.
*
* @expectedException UnauthorizedConfigException
*/
public function testWriteConfigLoggedOutWithFile()
{
file_put_contents(self::$_configFields['config']['CONFIG_FILE'], '');
writeConfig(self::$_configFields, false);
}
/**
* Test mergeDeprecatedConfig while being logged in:
* 1. init a config file.
* 2. init a options.php file with update value.
* 3. merge.
* 4. check updated value in config file.
*/
public function testMergeDeprecatedConfig()
{
// init
writeConfig(self::$_configFields, true);
$configCopy = self::$_configFields;
$invert = !$configCopy['privateLinkByDefault'];
$configCopy['privateLinkByDefault'] = $invert;
// Use writeConfig to create a options.php
$configCopy['config']['CONFIG_FILE'] = 'tests/options.php';
writeConfig($configCopy, true);
$this->assertTrue(is_file($configCopy['config']['CONFIG_FILE']));
// merge configs
mergeDeprecatedConfig(self::$_configFields, true);
// make sure updated field is changed
include self::$_configFields['config']['CONFIG_FILE'];
$this->assertEquals($invert, $GLOBALS['privateLinkByDefault']);
$this->assertFalse(is_file($configCopy['config']['CONFIG_FILE']));
}
/**
* Test mergeDeprecatedConfig while being logged in without options file.
*/
public function testMergeDeprecatedConfigNoFile()
{
writeConfig(self::$_configFields, true);
mergeDeprecatedConfig(self::$_configFields, true);
include self::$_configFields['config']['CONFIG_FILE'];
$this->assertEquals(self::$_configFields['login'], $GLOBALS['login']);
}
}
<?php
/**
* Config' tests
*/
require_once 'application/Config.php';
/**
* Unitary tests for Shaarli config related functions
*/
class ConfigTest extends PHPUnit_Framework_TestCase
{
// Configuration input set.
private static $configFields;
/**
* Executed before each test.
*/
public function setUp()
{
self::$configFields = array(
'login' => 'login',
'hash' => 'hash',
'salt' => 'salt',
'timezone' => 'Europe/Paris',
'title' => 'title',
'titleLink' => 'titleLink',
'redirector' => '',
'disablesessionprotection' => false,
'privateLinkByDefault' => false,
'config' => array(
'CONFIG_FILE' => 'tests/config.php',
'DATADIR' => 'tests',
'config1' => 'config1data',
'config2' => 'config2data',
)
);
}
/**
* Executed after each test.
*
* @return void
*/
public function tearDown()
{
if (is_file(self::$configFields['config']['CONFIG_FILE'])) {
unlink(self::$configFields['config']['CONFIG_FILE']);
}
}
/**
* Test writeConfig function, valid use case, while being logged in.
*/
public function testWriteConfig()
{
writeConfig(self::$configFields, true);
include self::$configFields['config']['CONFIG_FILE'];
$this->assertEquals(self::$configFields['login'], $GLOBALS['login']);
$this->assertEquals(self::$configFields['hash'], $GLOBALS['hash']);
$this->assertEquals(self::$configFields['salt'], $GLOBALS['salt']);
$this->assertEquals(self::$configFields['timezone'], $GLOBALS['timezone']);
$this->assertEquals(self::$configFields['title'], $GLOBALS['title']);
$this->assertEquals(self::$configFields['titleLink'], $GLOBALS['titleLink']);
$this->assertEquals(self::$configFields['redirector'], $GLOBALS['redirector']);
$this->assertEquals(self::$configFields['disablesessionprotection'], $GLOBALS['disablesessionprotection']);
$this->assertEquals(self::$configFields['privateLinkByDefault'], $GLOBALS['privateLinkByDefault']);
$this->assertEquals(self::$configFields['config']['config1'], $GLOBALS['config']['config1']);
$this->assertEquals(self::$configFields['config']['config2'], $GLOBALS['config']['config2']);
}
/**
* Test writeConfig option while logged in:
* 1. init fields.
* 2. update fields, add new sub config, add new root config.
* 3. rewrite config.
* 4. check result.
*/
public function testWriteConfigFieldUpdate()
{
writeConfig(self::$configFields, true);
self::$configFields['title'] = 'ok';
self::$configFields['config']['config1'] = 'ok';
self::$configFields['config']['config_new'] = 'ok';
self::$configFields['new'] = 'should not be saved';
writeConfig(self::$configFields, true);
include self::$configFields['config']['CONFIG_FILE'];
$this->assertEquals('ok', $GLOBALS['title']);
$this->assertEquals('ok', $GLOBALS['config']['config1']);
$this->assertEquals('ok', $GLOBALS['config']['config_new']);
$this->assertFalse(isset($GLOBALS['new']));
}
/**
* Test writeConfig function with an empty array.
*
* @expectedException MissingFieldConfigException
*/
public function testWriteConfigEmpty()
{
writeConfig(array(), true);
}
/**
* Test writeConfig function with a missing mandatory field.
*
* @expectedException MissingFieldConfigException
*/
public function testWriteConfigMissingField()
{
unset(self::$configFields['login']);
writeConfig(self::$configFields, true);
}
/**
* Test writeConfig function while being logged out, and there is no config file existing.
*/
public function testWriteConfigLoggedOutNoFile()
{
writeConfig(self::$configFields, false);
}
/**
* Test writeConfig function while being logged out, and a config file already exists.
*
* @expectedException UnauthorizedConfigException
*/
public function testWriteConfigLoggedOutWithFile()
{
file_put_contents(self::$configFields['config']['CONFIG_FILE'], '');
writeConfig(self::$configFields, false);
}
/**
* Test mergeDeprecatedConfig while being logged in:
* 1. init a config file.
* 2. init a options.php file with update value.
* 3. merge.
* 4. check updated value in config file.
*/
public function testMergeDeprecatedConfig()
{
// init
writeConfig(self::$configFields, true);
$configCopy = self::$configFields;
$invert = !$configCopy['privateLinkByDefault'];
$configCopy['privateLinkByDefault'] = $invert;
// Use writeConfig to create a options.php
$configCopy['config']['CONFIG_FILE'] = 'tests/options.php';
writeConfig($configCopy, true);
$this->assertTrue(is_file($configCopy['config']['CONFIG_FILE']));
// merge configs
mergeDeprecatedConfig(self::$configFields, true);
// make sure updated field is changed
include self::$configFields['config']['CONFIG_FILE'];
$this->assertEquals($invert, $GLOBALS['privateLinkByDefault']);
$this->assertFalse(is_file($configCopy['config']['CONFIG_FILE']));
}
/**
* Test mergeDeprecatedConfig while being logged in without options file.
*/
public function testMergeDeprecatedConfigNoFile()
{
writeConfig(self::$configFields, true);
mergeDeprecatedConfig(self::$configFields, true);
include self::$configFields['config']['CONFIG_FILE'];
$this->assertEquals(self::$configFields['login'], $GLOBALS['login']);
}
}

View file

@ -0,0 +1,66 @@
<?php
/**
* Plugin Manager tests
*/
require_once 'application/PluginManager.php';
/**
* Unit tests for Plugins
*/
class PluginManagerTest extends PHPUnit_Framework_TestCase
{
/**
* Path to tests plugin.
* @var string $pluginPath
*/
private static $pluginPath = 'tests/plugins';
/**
* Test plugin.
* @var string $pluginName
*/
private static $pluginName = 'test';
/**
* Test plugin loading and hook execution.
*
* @return void
*/
public function testPlugin()
{
$pluginManager = PluginManager::getInstance();
PluginManager::$PLUGINS_PATH = self::$pluginPath;
$pluginManager->load(array(self::$pluginName));
$this->assertTrue(function_exists('hook_test_random'));
$data = array(0 => 'woot');
$pluginManager->executeHooks('random', $data);
$this->assertEquals('woot', $data[1]);
$data = array(0 => 'woot');
$pluginManager->executeHooks('random', $data, array('target' => 'test'));
$this->assertEquals('page test', $data[1]);
$data = array(0 => 'woot');
$pluginManager->executeHooks('random', $data, array('loggedin' => true));
$this->assertEquals('loggedin', $data[1]);
}
/**
* Test missing plugin loading.
*
* @return void
*/
public function testPluginNotFound()
{
$pluginManager = PluginManager::getInstance();
$pluginManager->load(array());
$pluginManager->load(array('nope', 'renope'));
}
}

515
tests/RouterTest.php Normal file
View file

@ -0,0 +1,515 @@
<?php
/**
* Router tests
*/
require_once 'application/Router.php';
/**
* Unit tests for Router
*/
class RouterTest extends PHPUnit_Framework_TestCase
{
/**
* Test findPage: login page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageLoginValid()
{
$this->assertEquals(
Router::$PAGE_LOGIN,
Router::findPage('do=login', array(), false)
);
$this->assertEquals(
Router::$PAGE_LOGIN,
Router::findPage('do=login', array(), 1)
);
$this->assertEquals(
Router::$PAGE_LOGIN,
Router::findPage('do=login&stuff', array(), false)
);
}
/**
* Test findPage: login page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPageLoginInvalid()
{
$this->assertNotEquals(
Router::$PAGE_LOGIN,
Router::findPage('do=login', array(), true)
);
$this->assertNotEquals(
Router::$PAGE_LOGIN,
Router::findPage('do=other', array(), false)
);
}
/**
* Test findPage: picwall page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPagePicwallValid()
{
$this->assertEquals(
Router::$PAGE_PICWALL,
Router::findPage('do=picwall', array(), false)
);
$this->assertEquals(
Router::$PAGE_PICWALL,
Router::findPage('do=picwall', array(), true)
);
}
/**
* Test findPage: picwall page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPagePicwallInvalid()
{
$this->assertEquals(
Router::$PAGE_PICWALL,
Router::findPage('do=picwall&stuff', array(), false)
);
$this->assertNotEquals(
Router::$PAGE_PICWALL,
Router::findPage('do=other', array(), false)
);
}
/**
* Test findPage: tagcloud page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageTagcloudValid()
{
$this->assertEquals(
Router::$PAGE_TAGCLOUD,
Router::findPage('do=tagcloud', array(), false)
);
$this->assertEquals(
Router::$PAGE_TAGCLOUD,
Router::findPage('do=tagcloud', array(), true)
);
$this->assertEquals(
Router::$PAGE_TAGCLOUD,
Router::findPage('do=tagcloud&stuff', array(), false)
);
}
/**
* Test findPage: tagcloud page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPageTagcloudInvalid()
{
$this->assertNotEquals(
Router::$PAGE_TAGCLOUD,
Router::findPage('do=other', array(), false)
);
}
/**
* Test findPage: linklist page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageLinklistValid()
{
$this->assertEquals(
Router::$PAGE_LINKLIST,
Router::findPage('', array(), true)
);
$this->assertEquals(
Router::$PAGE_LINKLIST,
Router::findPage('whatever', array(), true)
);
$this->assertEquals(
Router::$PAGE_LINKLIST,
Router::findPage('whatever', array(), false)
);
$this->assertEquals(
Router::$PAGE_LINKLIST,
Router::findPage('do=tools', array(), false)
);
}
/**
* Test findPage: tools page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageToolsValid()
{
$this->assertEquals(
Router::$PAGE_TOOLS,
Router::findPage('do=tools', array(), true)
);
$this->assertEquals(
Router::$PAGE_TOOLS,
Router::findPage('do=tools&stuff', array(), true)
);
}
/**
* Test findPage: tools page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPageToolsInvalid()
{
$this->assertNotEquals(
Router::$PAGE_TOOLS,
Router::findPage('do=tools', array(), 1)
);
$this->assertNotEquals(
Router::$PAGE_TOOLS,
Router::findPage('do=tools', array(), false)
);
$this->assertNotEquals(
Router::$PAGE_TOOLS,
Router::findPage('do=other', array(), true)
);
}
/**
* Test findPage: changepasswd page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageChangepasswdValid()
{
$this->assertEquals(
Router::$PAGE_CHANGEPASSWORD,
Router::findPage('do=changepasswd', array(), true)
);
$this->assertEquals(
Router::$PAGE_CHANGEPASSWORD,
Router::findPage('do=changepasswd&stuff', array(), true)
);
}
/**
* Test findPage: changepasswd page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPageChangepasswdInvalid()
{
$this->assertNotEquals(
Router::$PAGE_CHANGEPASSWORD,
Router::findPage('do=changepasswd', array(), 1)
);
$this->assertNotEquals(
Router::$PAGE_CHANGEPASSWORD,
Router::findPage('do=changepasswd', array(), false)
);
$this->assertNotEquals(
Router::$PAGE_CHANGEPASSWORD,
Router::findPage('do=other', array(), true)
);
}
/**
* Test findPage: configure page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageConfigureValid()
{
$this->assertEquals(
Router::$PAGE_CONFIGURE,
Router::findPage('do=configure', array(), true)
);
$this->assertEquals(
Router::$PAGE_CONFIGURE,
Router::findPage('do=configure&stuff', array(), true)
);
}
/**
* Test findPage: configure page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPageConfigureInvalid()
{
$this->assertNotEquals(
Router::$PAGE_CONFIGURE,
Router::findPage('do=configure', array(), 1)
);
$this->assertNotEquals(
Router::$PAGE_CONFIGURE,
Router::findPage('do=configure', array(), false)
);
$this->assertNotEquals(
Router::$PAGE_CONFIGURE,
Router::findPage('do=other', array(), true)
);
}
/**
* Test findPage: changetag page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageChangetagValid()
{
$this->assertEquals(
Router::$PAGE_CHANGETAG,
Router::findPage('do=changetag', array(), true)
);
$this->assertEquals(
Router::$PAGE_CHANGETAG,
Router::findPage('do=changetag&stuff', array(), true)
);
}
/**
* Test findPage: changetag page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPageChangetagInvalid()
{
$this->assertNotEquals(
Router::$PAGE_CHANGETAG,
Router::findPage('do=changetag', array(), 1)
);
$this->assertNotEquals(
Router::$PAGE_CHANGETAG,
Router::findPage('do=changetag', array(), false)
);
$this->assertNotEquals(
Router::$PAGE_CHANGETAG,
Router::findPage('do=other', array(), true)
);
}
/**
* Test findPage: addlink page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageAddlinkValid()
{
$this->assertEquals(
Router::$PAGE_ADDLINK,
Router::findPage('do=addlink', array(), true)
);
$this->assertEquals(
Router::$PAGE_ADDLINK,
Router::findPage('do=addlink&stuff', array(), true)
);
}
/**
* Test findPage: addlink page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPageAddlinkInvalid()
{
$this->assertNotEquals(
Router::$PAGE_ADDLINK,
Router::findPage('do=addlink', array(), 1)
);
$this->assertNotEquals(
Router::$PAGE_ADDLINK,
Router::findPage('do=addlink', array(), false)
);
$this->assertNotEquals(
Router::$PAGE_ADDLINK,
Router::findPage('do=other', array(), true)
);
}
/**
* Test findPage: export page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageExportValid()
{
$this->assertEquals(
Router::$PAGE_EXPORT,
Router::findPage('do=export', array(), true)
);
$this->assertEquals(
Router::$PAGE_EXPORT,
Router::findPage('do=export&stuff', array(), true)
);
}
/**
* Test findPage: export page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPageExportInvalid()
{
$this->assertNotEquals(
Router::$PAGE_EXPORT,
Router::findPage('do=export', array(), 1)
);
$this->assertNotEquals(
Router::$PAGE_EXPORT,
Router::findPage('do=export', array(), false)
);
$this->assertNotEquals(
Router::$PAGE_EXPORT,
Router::findPage('do=other', array(), true)
);
}
/**
* Test findPage: import page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageImportValid()
{
$this->assertEquals(
Router::$PAGE_IMPORT,
Router::findPage('do=import', array(), true)
);
$this->assertEquals(
Router::$PAGE_IMPORT,
Router::findPage('do=import&stuff', array(), true)
);
}
/**
* Test findPage: import page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPageImportInvalid()
{
$this->assertNotEquals(
Router::$PAGE_IMPORT,
Router::findPage('do=import', array(), 1)
);
$this->assertNotEquals(
Router::$PAGE_IMPORT,
Router::findPage('do=import', array(), false)
);
$this->assertNotEquals(
Router::$PAGE_IMPORT,
Router::findPage('do=other', array(), true)
);
}
/**
* Test findPage: editlink page output.
* Valid: page should be return.
*
* @return void
*/
public function testFindPageEditlinkValid()
{
$this->assertEquals(
Router::$PAGE_EDITLINK,
Router::findPage('whatever', array('edit_link' => 1), true)
);
$this->assertEquals(
Router::$PAGE_EDITLINK,
Router::findPage('', array('edit_link' => 1), true)
);
$this->assertEquals(
Router::$PAGE_EDITLINK,
Router::findPage('whatever', array('post' => 1), true)
);
$this->assertEquals(
Router::$PAGE_EDITLINK,
Router::findPage('whatever', array('post' => 1, 'edit_link' => 1), true)
);
}
/**
* Test findPage: editlink page output.
* Invalid: page shouldn't be return.
*
* @return void
*/
public function testFindPageEditlinkInvalid()
{
$this->assertNotEquals(
Router::$PAGE_EDITLINK,
Router::findPage('whatever', array('edit_link' => 1), false)
);
$this->assertNotEquals(
Router::$PAGE_EDITLINK,
Router::findPage('whatever', array('edit_link' => 1), 1)
);
$this->assertNotEquals(
Router::$PAGE_EDITLINK,
Router::findPage('whatever', array(), true)
);
}
}

View file

@ -0,0 +1,67 @@
<?php
/**
* PlugQrcodeTest.php
*/
require_once 'plugins/qrcode/qrcode.php';
require_once 'application/Router.php';
/**
* Class PlugQrcodeTest
* Unit test for the QR-Code plugin
*/
class PlugQrcodeTest extends PHPUnit_Framework_TestCase
{
/**
* Reset plugin path
*/
function setUp() {
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Test render_linklist hook.
*/
function testQrcodeLinklist()
{
$str = 'http://randomstr.com/test';
$data = array(
'title' => $str,
'links' => array(
array(
'url' => $str,
)
)
);
$data = hook_qrcode_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 render_footer hook.
*/
function testQrcodeFooter()
{
$str = 'stuff';
$data = array($str => $str);
$data['_PAGE_'] = Router::$PAGE_LINKLIST;
$data = hook_qrcode_render_footer($data);
$this->assertEquals($str, $data[$str]);
$this->assertEquals(1, count($data['js_files']));
$data = array($str => $str);
$data['_PAGE_'] = $str;
$this->assertEquals($str, $data[$str]);
$this->assertArrayNotHasKey('js_files', $data);
}
}

View file

@ -0,0 +1,100 @@
<?php
/**
* PluginPlayvideosTest.php
*/
require_once 'plugins/addlink_toolbar/addlink_toolbar.php';
require_once 'application/Router.php';
/**
* Class PluginAddlinkTest
* Unit test for the Addlink toolbar plugin
*/
class PluginAddlinkTest extends PHPUnit_Framework_TestCase
{
/**
* Reset plugin path.
*/
function setUp()
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Test render_header hook while logged in.
*/
function testAddlinkHeaderLoggedIn()
{
$str = 'stuff';
$data = array($str => $str);
$data['_PAGE_'] = Router::$PAGE_LINKLIST;
$data['_LOGGEDIN_'] = true;
$data = hook_addlink_toolbar_render_header($data);
$this->assertEquals($str, $data[$str]);
$this->assertEquals(1, count($data['fields_toolbar']));
$data = array($str => $str);
$data['_PAGE_'] = $str;
$data['_LOGGEDIN_'] = true;
$data = hook_addlink_toolbar_render_header($data);
$this->assertEquals($str, $data[$str]);
$this->assertArrayNotHasKey('fields_toolbar', $data);
}
/**
* Test render_header hook while logged out.
*/
function testAddlinkHeaderLoggedOut()
{
$str = 'stuff';
$data = array($str => $str);
$data['_PAGE_'] = Router::$PAGE_LINKLIST;
$data['_LOGGEDIN_'] = false;
$data = hook_addlink_toolbar_render_header($data);
$this->assertEquals($str, $data[$str]);
$this->assertArrayNotHasKey('fields_toolbar', $data);
}
/**
* Test render_includes hook while logged in.
*/
function testAddlinkIncludesLoggedIn()
{
$str = 'stuff';
$data = array($str => $str);
$data['_PAGE_'] = Router::$PAGE_LINKLIST;
$data['_LOGGEDIN_'] = true;
$data = hook_addlink_toolbar_render_includes($data);
$this->assertEquals($str, $data[$str]);
$this->assertEquals(1, count($data['css_files']));
$str = 'stuff';
$data = array($str => $str);
$data['_PAGE_'] = $str;
$data['_LOGGEDIN_'] = true;
$data = hook_addlink_toolbar_render_includes($data);
$this->assertEquals($str, $data[$str]);
$this->assertArrayNotHasKey('css_files', $data);
}
/**
* Test render_includes hook.
* Should not affect css files while logged out.
*/
function testAddlinkIncludesLoggedOut()
{
$str = 'stuff';
$data = array($str => $str);
$data['_PAGE_'] = Router::$PAGE_LINKLIST;
$data['_LOGGEDIN_'] = false;
$data = hook_addlink_toolbar_render_includes($data);
$this->assertEquals($str, $data[$str]);
$this->assertArrayNotHasKey('css_files', $data);
}
}

View file

@ -0,0 +1,48 @@
<?php
/**
* PluginArchiveorgTest.php
*/
require_once 'plugins/archiveorg/archiveorg.php';
/**
* Class PlugQrcodeTest
* Unit test for the QR-Code plugin
*/
class PluginArchiveorgTest extends PHPUnit_Framework_TestCase
{
/**
* Reset plugin path
*/
function setUp()
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Test render_linklist hook.
*/
function testArchiveorgLinklist()
{
$str = 'http://randomstr.com/test';
$data = array(
'title' => $str,
'links' => array(
array(
'url' => $str,
)
)
);
$data = hook_archiveorg_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));
}
}

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);
}
}

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);
}
}

View file

@ -0,0 +1,49 @@
<?php
/**
* PluginWallabagTest.php.php
*/
require_once 'plugins/wallabag/wallabag.php';
/**
* Class PluginWallabagTest
* Unit test for the Wallabag plugin
*/
class PluginWallabagTest extends PHPUnit_Framework_TestCase
{
/**
* Reset plugin path
*/
function setUp()
{
PluginManager::$PLUGINS_PATH = 'plugins';
}
/**
* Test render_linklist hook.
*/
function testWallabagLinklist()
{
$GLOBALS['plugins']['WALLABAG_URL'] = 'value';
$str = 'http://randomstr.com/test';
$data = array(
'title' => $str,
'links' => array(
array(
'url' => $str,
)
)
);
$data = hook_wallabag_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));
}
}

View file

@ -0,0 +1,21 @@
<?php
/**
* Hook for test.
*
* @param array $data - data passed to plugin.
*
* @return mixed altered data.
*/
function hook_test_random($data)
{
if (isset($data['_PAGE_']) && $data['_PAGE_'] == 'test') {
$data[1] = 'page test';
} else if (isset($data['_LOGGEDIN_']) && $data['_LOGGEDIN_'] === true) {
$data[1] = 'loggedin';
} else {
$data[1] = $data[0];
}
return $data;
}