]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/Updater/UpdaterTest.php
Add Piwik Plugin
[github/shaarli/Shaarli.git] / tests / Updater / UpdaterTest.php
index 5ed2df6caff8527877a594b0213eb49ec050b597..0d0ad92220cac1fef8fc954e645066854c7f555a 100644 (file)
@@ -38,7 +38,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
     public function testReadEmptyUpdatesFile()
     {
         $this->assertEquals(array(), read_updates_file(''));
-        $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt';
+        $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
         touch($updatesFile);
         $this->assertEquals(array(), read_updates_file($updatesFile));
         unlink($updatesFile);
@@ -49,7 +49,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
      */
     public function testReadWriteUpdatesFile()
     {
-        $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt';
+        $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
         $updatesMethods = array('m1', 'm2', 'm3');
 
         write_updates_file($updatesFile, $updatesMethods);
@@ -83,7 +83,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
      */
     public function testWriteUpdatesFileNotWritable()
     {
-        $updatesFile = $this->conf->get('path.data_dir') . '/updates.txt';
+        $updatesFile = $this->conf->get('resource.data_dir') . '/updates.txt';
         touch($updatesFile);
         chmod($updatesFile, 0444);
         try {
@@ -189,7 +189,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
 
         // make sure updated field is changed
         $this->conf->reload();
-        $this->assertTrue($this->conf->get('general.default_private_links'));
+        $this->assertTrue($this->conf->get('privacy.default_private_links'));
         $this->assertFalse(is_file($optionsFile));
         // Delete the generated file.
         unlink($this->conf->getConfigFileExt());
@@ -243,8 +243,8 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
         // Check JSON config data.
         $this->conf->reload();
         $this->assertEquals('root', $this->conf->get('credentials.login'));
-        $this->assertEquals('lala', $this->conf->get('extras.redirector'));
-        $this->assertEquals('data/datastore.php', $this->conf->get('path.datastore'));
+        $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');
@@ -263,4 +263,28 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
         $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');
+    }
 }