]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/ConfigTest.php
Bump version to v0.7.1
[github/shaarli/Shaarli.git] / tests / ConfigTest.php
index adebfcc31270fbe90a1388c2d074ebc17b9bb937..7200aae644e712dfdd4a394814e051f9249f4bd6 100644 (file)
@@ -134,44 +134,111 @@ class ConfigTest extends PHPUnit_Framework_TestCase
     }
 
     /**
-     * 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.
+     * Test save_plugin_config with valid data.
+     *
+     * @throws PluginConfigOrderException
      */
-    public function testMergeDeprecatedConfig()
+    public function testSavePluginConfigValid()
     {
-        // init
-        writeConfig(self::$configFields, true);
-        $configCopy = self::$configFields;
-        $invert = !$configCopy['privateLinkByDefault'];
-        $configCopy['privateLinkByDefault'] = $invert;
+        $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,
+        );
 
-        // Use writeConfig to create a options.php
-        $configCopy['config']['CONFIG_FILE'] = 'tests/options.php';
-        writeConfig($configCopy, true);
+        $expected = array(
+            'plugin3',
+            'plugin4',
+            'plugin2',
+        );
 
-        $this->assertTrue(is_file($configCopy['config']['CONFIG_FILE']));
+        $out = save_plugin_config($data);
+        $this->assertEquals($expected, $out);
+    }
 
-        // merge configs
-        mergeDeprecatedConfig(self::$configFields, true);
+    /**
+     * 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,
+        );
 
-        // 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']));
+        save_plugin_config($data);
     }
 
     /**
-     * Test mergeDeprecatedConfig while being logged in without options file.
+     * Test save_plugin_config without data.
      */
-    public function testMergeDeprecatedConfigNoFile()
+    public function testSavePluginConfigEmpty()
     {
-        writeConfig(self::$configFields, true);
-        mergeDeprecatedConfig(self::$configFields, true);
+        $this->assertEquals(array(), save_plugin_config(array()));
+    }
 
-        include self::$configFields['config']['CONFIG_FILE'];
-        $this->assertEquals(self::$configFields['login'], $GLOBALS['login']);
+    /**
+     * 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']);
     }
 }