From 59404d7909b21682ec0782778452a8a70e38b25e Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 18 May 2016 21:43:59 +0200 Subject: Introduce a configuration manager (not plugged yet) --- tests/config/ConfigPluginTest.php | 121 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 tests/config/ConfigPluginTest.php (limited to 'tests/config/ConfigPluginTest.php') diff --git a/tests/config/ConfigPluginTest.php b/tests/config/ConfigPluginTest.php new file mode 100644 index 00000000..716631b0 --- /dev/null +++ b/tests/config/ConfigPluginTest.php @@ -0,0 +1,121 @@ + 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']); + } +} -- cgit v1.2.3