]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/updater/UpdaterTest.php
Merge branch 'v0.11' into stable
[github/shaarli/Shaarli.git] / tests / updater / UpdaterTest.php
similarity index 95%
rename from tests/Updater/UpdaterTest.php
rename to tests/updater/UpdaterTest.php
index 608e331dac04a4c12da14fa920338c79d4f95110..738b7361553e7869be792cbb0fdd623f57380244 100644 (file)
@@ -1,17 +1,24 @@
 <?php
+namespace Shaarli\Updater;
+
+use DateTime;
+use Exception;
+use Shaarli\Bookmark\LinkDB;
 use Shaarli\Config\ConfigJson;
 use Shaarli\Config\ConfigManager;
 use Shaarli\Config\ConfigPhp;
 use Shaarli\Thumbnailer;
 
-require_once 'tests/Updater/DummyUpdater.php';
+require_once 'application/updater/UpdaterUtils.php';
+require_once 'tests/updater/DummyUpdater.php';
+require_once 'tests/utils/ReferenceLinkDB.php';
 require_once 'inc/rain.tpl.class.php';
 
 /**
  * Class UpdaterTest.
- * Runs unit tests against the Updater class.
+ * Runs unit tests against the updater class.
  */
-class UpdaterTest extends PHPUnit_Framework_TestCase
+class UpdaterTest extends \PHPUnit\Framework\TestCase
 {
     /**
      * @var string Path to test datastore.
@@ -153,7 +160,7 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
     /**
      * Test Update failed.
      *
-     * @expectedException UpdaterException
+     * @expectedException \Exception
      */
     public function testUpdateFailed()
     {
@@ -179,17 +186,17 @@ class UpdaterTest extends PHPUnit_Framework_TestCase
         $this->conf->setConfigFile('tests/utils/config/configPhp');
         $this->conf->reset();
 
-        $optionsFile = 'tests/Updater/options.php';
+        $optionsFile = 'tests/updater/options.php';
         $options = '<?php
 $GLOBALS[\'privateLinkByDefault\'] = true;';
         file_put_contents($optionsFile, $options);
 
         // tmp config file.
-        $this->conf->setConfigFile('tests/Updater/config');
+        $this->conf->setConfigFile('tests/updater/config');
 
         // merge configs
         $updater = new Updater(array(), array(), $this->conf, true);
-        // This writes a new config file in tests/Updater/config.php
+        // This writes a new config file in tests/updater/config.php
         $updater->updateMethodMergeDeprecatedConfigFile();
 
         // make sure updated field is changed
@@ -216,7 +223,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
      */
     public function testRenameDashTags()
     {
-        $refDB = new ReferenceLinkDB();
+        $refDB = new \ReferenceLinkDB();
         $refDB->write(self::$testDatastore);
         $linkDB = new LinkDB(self::$testDatastore, true, false);
 
@@ -280,17 +287,14 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
         $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');
     }
 
@@ -362,7 +366,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
                 'private' => true,
             ),
         );
-        $refDB = new ReferenceLinkDB();
+        $refDB = new \ReferenceLinkDB();
         $refDB->setLinks($links);
         $refDB->write(self::$testDatastore);
         $linkDB = new LinkDB(self::$testDatastore, true, false);
@@ -426,7 +430,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
      */
     public function testDatastoreIdsNothingToDo()
     {
-        $refDB = new ReferenceLinkDB();
+        $refDB = new \ReferenceLinkDB();
         $refDB->write(self::$testDatastore);
         $linkDB = new LinkDB(self::$testDatastore, true, false);
 
@@ -699,7 +703,6 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
     }
 
     /**
-<<<<<<< HEAD
      * Test updateMethodWebThumbnailer with thumbnails enabled.
      */
     public function testUpdateMethodWebThumbnailerEnabled()
@@ -762,7 +765,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
             1 => ['id' => 1] + $blank,
             2 => ['id' => 2] + $blank,
         ];
-        $refDB = new ReferenceLinkDB();
+        $refDB = new \ReferenceLinkDB();
         $refDB->setLinks($links);
         $refDB->write(self::$testDatastore);
         $linkDB = new LinkDB(self::$testDatastore, true, false);
@@ -793,7 +796,7 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
             1 => ['id' => 1, 'sticky' => true] + $blank,
             2 => ['id' => 2] + $blank,
         ];
-        $refDB = new ReferenceLinkDB();
+        $refDB = new \ReferenceLinkDB();
         $refDB->setLinks($links);
         $refDB->write(self::$testDatastore);
         $linkDB = new LinkDB(self::$testDatastore, true, false);
@@ -804,4 +807,19 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
         $linkDB = new LinkDB(self::$testDatastore, true, false);
         $this->assertTrue($linkDB[1]['sticky']);
     }
+
+    /**
+     * Test updateMethodRemoveRedirector().
+     */
+    public function testUpdateRemoveRedirector()
+    {
+        $sandboxConf = 'sandbox/config';
+        copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
+        $this->conf = new ConfigManager($sandboxConf);
+        $updater = new Updater([], null, $this->conf, true);
+        $this->assertTrue($updater->updateMethodRemoveRedirector());
+        $this->assertFalse($this->conf->exists('redirector'));
+        $this->conf = new ConfigManager($sandboxConf);
+        $this->assertFalse($this->conf->exists('redirector'));
+    }
 }