2015-07-15 11:42:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin Manager tests
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once 'application/PluginManager.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unit tests for Plugins
|
|
|
|
*/
|
|
|
|
class PluginManagerTest extends PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Path to tests plugin.
|
2015-07-16 13:53:39 +02:00
|
|
|
* @var string $pluginPath
|
2015-07-15 11:42:15 +02:00
|
|
|
*/
|
2015-07-16 13:53:39 +02:00
|
|
|
private static $pluginPath = 'tests/plugins';
|
2015-07-15 11:42:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test plugin.
|
2015-07-16 13:53:39 +02:00
|
|
|
* @var string $pluginName
|
2015-07-15 11:42:15 +02:00
|
|
|
*/
|
2015-07-16 13:53:39 +02:00
|
|
|
private static $pluginName = 'test';
|
2015-07-15 11:42:15 +02:00
|
|
|
|
2016-06-09 20:04:32 +02:00
|
|
|
/**
|
|
|
|
* @var PluginManager $pluginManager Plugin Mananger instance.
|
|
|
|
*/
|
|
|
|
protected $pluginManager;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$conf = new ConfigManager('');
|
|
|
|
$this->pluginManager = new PluginManager($conf);
|
|
|
|
}
|
|
|
|
|
2015-07-15 11:42:15 +02:00
|
|
|
/**
|
|
|
|
* Test plugin loading and hook execution.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPlugin()
|
|
|
|
{
|
2015-07-16 13:53:39 +02:00
|
|
|
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
2016-06-09 20:04:32 +02:00
|
|
|
$this->pluginManager->load(array(self::$pluginName));
|
2015-07-15 11:42:15 +02:00
|
|
|
|
|
|
|
$this->assertTrue(function_exists('hook_test_random'));
|
|
|
|
|
|
|
|
$data = array(0 => 'woot');
|
2016-06-09 20:04:32 +02:00
|
|
|
$this->pluginManager->executeHooks('random', $data);
|
2015-07-15 11:42:15 +02:00
|
|
|
$this->assertEquals('woot', $data[1]);
|
|
|
|
|
|
|
|
$data = array(0 => 'woot');
|
2016-06-09 20:04:32 +02:00
|
|
|
$this->pluginManager->executeHooks('random', $data, array('target' => 'test'));
|
2015-07-15 11:42:15 +02:00
|
|
|
$this->assertEquals('page test', $data[1]);
|
|
|
|
|
|
|
|
$data = array(0 => 'woot');
|
2016-06-09 20:04:32 +02:00
|
|
|
$this->pluginManager->executeHooks('random', $data, array('loggedin' => true));
|
2015-07-15 11:42:15 +02:00
|
|
|
$this->assertEquals('loggedin', $data[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test missing plugin loading.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testPluginNotFound()
|
|
|
|
{
|
2016-06-09 20:04:32 +02:00
|
|
|
$this->pluginManager->load(array());
|
|
|
|
$this->pluginManager->load(array('nope', 'renope'));
|
2015-07-15 11:42:15 +02:00
|
|
|
}
|
2015-11-18 17:40:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test plugin metadata loading.
|
|
|
|
*/
|
|
|
|
public function testGetPluginsMeta()
|
|
|
|
{
|
|
|
|
PluginManager::$PLUGINS_PATH = self::$pluginPath;
|
2016-06-09 20:04:32 +02:00
|
|
|
$this->pluginManager->load(array(self::$pluginName));
|
2015-11-18 17:40:42 +01:00
|
|
|
|
|
|
|
$expectedParameters = array(
|
2016-08-02 11:02:20 +02:00
|
|
|
'pop' => array(
|
|
|
|
'value' => '',
|
|
|
|
'desc' => 'pop description',
|
|
|
|
),
|
|
|
|
'hip' => array(
|
|
|
|
'value' => '',
|
|
|
|
'desc' => '',
|
|
|
|
),
|
2015-11-18 17:40:42 +01:00
|
|
|
);
|
2016-06-09 20:04:32 +02:00
|
|
|
$meta = $this->pluginManager->getPluginsMeta();
|
2015-11-18 17:40:42 +01:00
|
|
|
$this->assertEquals('test plugin', $meta[self::$pluginName]['description']);
|
|
|
|
$this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']);
|
|
|
|
}
|
2015-07-15 11:42:15 +02:00
|
|
|
}
|