From dea0ba28f950867532eae572e7bcda49e81bbcf0 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 18 Nov 2015 17:40:42 +0100 Subject: Fixes #378 - Plugin administration UI. --- tests/ConfigTest.php | 109 +++++++++++++++++++++++++++++++++++++++++++ tests/PluginManagerTest.php | 19 ++++++++ tests/plugins/test/test.meta | 2 + 3 files changed, 130 insertions(+) create mode 100644 tests/plugins/test/test.meta (limited to 'tests') diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index adebfcc3..492ddd3b 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -174,4 +174,113 @@ class ConfigTest extends PHPUnit_Framework_TestCase include self::$configFields['config']['CONFIG_FILE']; $this->assertEquals(self::$configFields['login'], $GLOBALS['login']); } + + /** + * Test save_plugin_config with valid data. + * + * @throws PluginConfigOrderException + */ + public function testSavePluginConfigValid() + { + $data = array( + 'order_plugin1' => 2, // no plugin related + 'plugin2' => 0, // new - at the end + 'plugin3' => 0, // 2nd + 'order_plugin3' => 8, + 'plugin4' => 0, // 1st + 'order_plugin4' => 5, + ); + + $expected = array( + 'plugin3', + 'plugin4', + 'plugin2', + ); + + $out = save_plugin_config($data); + $this->assertEquals($expected, $out); + } + + /** + * Test save_plugin_config with invalid data. + * + * @expectedException PluginConfigOrderException + */ + public function testSavePluginConfigInvalid() + { + $data = array( + 'plugin2' => 0, + 'plugin3' => 0, + 'order_plugin3' => 0, + 'plugin4' => 0, + 'order_plugin4' => 0, + ); + + save_plugin_config($data); + } + + /** + * Test save_plugin_config without data. + */ + public function testSavePluginConfigEmpty() + { + $this->assertEquals(array(), save_plugin_config(array())); + } + + /** + * Test validate_plugin_order with valid data. + */ + public function testValidatePluginOrderValid() + { + $data = array( + 'order_plugin1' => 2, + 'plugin2' => 0, + 'plugin3' => 0, + 'order_plugin3' => 1, + 'plugin4' => 0, + 'order_plugin4' => 5, + ); + + $this->assertTrue(validate_plugin_order($data)); + } + + /** + * Test validate_plugin_order with invalid data. + */ + public function testValidatePluginOrderInvalid() + { + $data = array( + 'order_plugin1' => 2, + 'order_plugin3' => 1, + 'order_plugin4' => 1, + ); + + $this->assertFalse(validate_plugin_order($data)); + } + + /** + * Test load_plugin_parameter_values. + */ + public function testLoadPluginParameterValues() + { + $plugins = array( + 'plugin_name' => array( + 'parameters' => array( + 'param1' => true, + 'param2' => false, + 'param3' => '', + ) + ) + ); + + $parameters = array( + 'param1' => 'value1', + 'param2' => 'value2', + ); + + $result = load_plugin_parameter_values($plugins, $parameters); + $this->assertEquals('value1', $result['plugin_name']['parameters']['param1']); + $this->assertEquals('value2', $result['plugin_name']['parameters']['param2']); + $this->assertEquals('', $result['plugin_name']['parameters']['param3']); + } } diff --git a/tests/PluginManagerTest.php b/tests/PluginManagerTest.php index df2614b5..348082c7 100644 --- a/tests/PluginManagerTest.php +++ b/tests/PluginManagerTest.php @@ -63,4 +63,23 @@ class PluginManagerTest extends PHPUnit_Framework_TestCase $pluginManager->load(array('nope', 'renope')); } + + /** + * Test plugin metadata loading. + */ + public function testGetPluginsMeta() + { + $pluginManager = PluginManager::getInstance(); + + PluginManager::$PLUGINS_PATH = self::$pluginPath; + $pluginManager->load(array(self::$pluginName)); + + $expectedParameters = array( + 'pop' => '', + 'hip' => '', + ); + $meta = $pluginManager->getPluginsMeta(); + $this->assertEquals('test plugin', $meta[self::$pluginName]['description']); + $this->assertEquals($expectedParameters, $meta[self::$pluginName]['parameters']); + } } \ No newline at end of file diff --git a/tests/plugins/test/test.meta b/tests/plugins/test/test.meta new file mode 100644 index 00000000..ab999ed4 --- /dev/null +++ b/tests/plugins/test/test.meta @@ -0,0 +1,2 @@ +description="test plugin" +parameters="pop;hip" \ No newline at end of file -- cgit v1.2.3