PluginManager no longer uses singleton pattern
This commit is contained in:
parent
278d9ee283
commit
51def0d849
9 changed files with 63 additions and 94 deletions
|
@ -23,6 +23,17 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
private static $pluginName = 'test';
|
||||
|
||||
/**
|
||||
* @var PluginManager $pluginManager Plugin Mananger instance.
|
||||
*/
|
||||
protected $pluginManager;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$conf = new ConfigManager('');
|
||||
$this->pluginManager = new PluginManager($conf);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test plugin loading and hook execution.
|
||||
*
|
||||
|
@ -30,23 +41,21 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testPlugin()
|
||||
{
|
||||
$pluginManager = PluginManager::getInstance();
|
||||
|
||||
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
||||
$pluginManager->load(array(self::$pluginName));
|
||||
$this->pluginManager->load(array(self::$pluginName));
|
||||
|
||||
$this->assertTrue(function_exists('hook_test_random'));
|
||||
|
||||
$data = array(0 => 'woot');
|
||||
$pluginManager->executeHooks('random', $data);
|
||||
$this->pluginManager->executeHooks('random', $data);
|
||||
$this->assertEquals('woot', $data[1]);
|
||||
|
||||
$data = array(0 => 'woot');
|
||||
$pluginManager->executeHooks('random', $data, array('target' => 'test'));
|
||||
$this->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->pluginManager->executeHooks('random', $data, array('loggedin' => true));
|
||||
$this->assertEquals('loggedin', $data[1]);
|
||||
}
|
||||
|
||||
|
@ -57,11 +66,8 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testPluginNotFound()
|
||||
{
|
||||
$pluginManager = PluginManager::getInstance();
|
||||
|
||||
$pluginManager->load(array());
|
||||
|
||||
$pluginManager->load(array('nope', 'renope'));
|
||||
$this->pluginManager->load(array());
|
||||
$this->pluginManager->load(array('nope', 'renope'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,16 +75,14 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
public function testGetPluginsMeta()
|
||||
{
|
||||
$pluginManager = PluginManager::getInstance();
|
||||
|
||||
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
||||
$pluginManager->load(array(self::$pluginName));
|
||||
$this->pluginManager->load(array(self::$pluginName));
|
||||
|
||||
$expectedParameters = array(
|
||||
'pop' => '',
|
||||
'hip' => '',
|
||||
);
|
||||
$meta = $pluginManager->getPluginsMeta();
|
||||
$meta = $this->pluginManager->getPluginsMeta();
|
||||
$this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
|
||||
$this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
* PluginReadityourselfTest.php.php
|
||||
*/
|
||||
|
||||
// FIXME! add an init method.
|
||||
$conf = new ConfigManager('');
|
||||
require_once 'plugins/readityourself/readityourself.php';
|
||||
|
||||
/**
|
||||
|
@ -25,7 +27,7 @@ class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
function testReadityourselfLinklist()
|
||||
{
|
||||
$conf = ConfigManager::getInstance();
|
||||
$conf = new ConfigManager('');
|
||||
$conf->set('plugins.READITYOUSELF_URL', 'value');
|
||||
$str = 'http://randomstr.com/test';
|
||||
$data = array(
|
||||
|
@ -37,7 +39,7 @@ class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
|
|||
)
|
||||
);
|
||||
|
||||
$data = hook_readityourself_render_linklist($data);
|
||||
$data = hook_readityourself_render_linklist($data, $conf);
|
||||
$link = $data['links'][0];
|
||||
// data shouldn't be altered
|
||||
$this->assertEquals($str, $data['title']);
|
||||
|
@ -53,7 +55,7 @@ class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
function testReadityourselfLinklistWithoutConfig()
|
||||
{
|
||||
$conf = ConfigManager::getInstance();
|
||||
$conf = new ConfigManager('');
|
||||
$conf->set('plugins.READITYOUSELF_URL', null);
|
||||
$str = 'http://randomstr.com/test';
|
||||
$data = array(
|
||||
|
@ -65,7 +67,7 @@ class PluginReadityourselfTest extends PHPUnit_Framework_TestCase
|
|||
)
|
||||
);
|
||||
|
||||
$data = hook_readityourself_render_linklist($data);
|
||||
$data = hook_readityourself_render_linklist($data, $conf);
|
||||
$link = $data['links'][0];
|
||||
// data shouldn't be altered
|
||||
$this->assertEquals($str, $data['title']);
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
* PluginWallabagTest.php.php
|
||||
*/
|
||||
|
||||
// FIXME! add an init method.
|
||||
$conf = new ConfigManager('');
|
||||
require_once 'plugins/wallabag/wallabag.php';
|
||||
|
||||
/**
|
||||
|
@ -25,7 +27,7 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase
|
|||
*/
|
||||
function testWallabagLinklist()
|
||||
{
|
||||
$conf = ConfigManager::getInstance();
|
||||
$conf = new ConfigManager('');
|
||||
$conf->set('plugins.WALLABAG_URL', 'value');
|
||||
$str = 'http://randomstr.com/test';
|
||||
$data = array(
|
||||
|
@ -37,7 +39,7 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase
|
|||
)
|
||||
);
|
||||
|
||||
$data = hook_wallabag_render_linklist($data);
|
||||
$data = hook_wallabag_render_linklist($data, $conf);
|
||||
$link = $data['links'][0];
|
||||
// data shouldn't be altered
|
||||
$this->assertEquals($str, $data['title']);
|
||||
|
@ -49,4 +51,3 @@ class PluginWallabagTest extends PHPUnit_Framework_TestCase
|
|||
$this->assertNotFalse(strpos($link['link_plugin'][0], $conf->get('plugins.WALLABAG_URL')));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue