+
+ /**
+ * Convert old PHP config file to JSON config.
+ */
+ public function testConfigToJson()
+ {
+ $configFile = 'tests/utils/config/configPhp';
+ $this->conf->setConfigFile($configFile);
+ $this->conf->reset();
+
+ // The ConfigIO is initialized with ConfigPhp.
+ $this->assertTrue($this->conf->getConfigIO() instanceof ConfigPhp);
+
+ $updater = new Updater(array(), array(), $this->conf, false);
+ $done = $updater->updateMethodConfigToJson();
+ $this->assertTrue($done);
+
+ // The ConfigIO has been updated to ConfigJson.
+ $this->assertTrue($this->conf->getConfigIO() instanceof ConfigJson);
+ $this->assertTrue(file_exists($this->conf->getConfigFileExt()));
+
+ // Check JSON config data.
+ $this->conf->reload();
+ $this->assertEquals('root', $this->conf->get('credentials.login'));
+ $this->assertEquals('lala', $this->conf->get('redirector.url'));
+ $this->assertEquals('data/datastore.php', $this->conf->get('resource.datastore'));
+ $this->assertEquals('1', $this->conf->get('plugins.WALLABAG_VERSION'));
+
+ rename($configFile . '.save.php', $configFile . '.php');
+ unlink($this->conf->getConfigFileExt());
+ }
+
+ /**
+ * Launch config conversion update with an existing JSON file => nothing to do.
+ */
+ public function testConfigToJsonNothingToDo()
+ {
+ $filetime = filemtime($this->conf->getConfigFileExt());
+ $updater = new Updater(array(), array(), $this->conf, false);
+ $done = $updater->updateMethodConfigToJson();
+ $this->assertTrue($done);
+ $expected = filemtime($this->conf->getConfigFileExt());
+ $this->assertEquals($expected, $filetime);
+ }
+
+ /**
+ * Test escapeUnescapedConfig with valid data.
+ */
+ public function testEscapeConfig()
+ {
+ $sandbox = 'sandbox/config';
+ copy(self::$configFile .'.json.php', $sandbox .'.json.php');
+ $this->conf = new ConfigManager($sandbox);
+ $title = '<script>alert("title");</script>';
+ $headerLink = '<script>alert("header_link");</script>';
+ $redirectorUrl = '<script>alert("redirector");</script>';
+ $this->conf->set('general.title', $title);
+ $this->conf->set('general.header_link', $headerLink);
+ $this->conf->set('redirector.url', $redirectorUrl);
+ $updater = new Updater(array(), array(), $this->conf, true);
+ $done = $updater->updateMethodEscapeUnescapedConfig();
+ $this->assertTrue($done);
+ $this->conf->reload();
+ $this->assertEquals(escape($title), $this->conf->get('general.title'));
+ $this->assertEquals(escape($headerLink), $this->conf->get('general.header_link'));
+ $this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url'));
+ unlink($sandbox .'.json.php');
+ }