]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tests/Updater/UpdaterTest.php
Fix #773: set Piwik URL protocol
[github/shaarli/Shaarli.git] / tests / Updater / UpdaterTest.php
index 39be88f944c1d10c39fce0273c8f1427a4cbb4a5..b522d616b4dc658ab72d285234f9e4354af58633 100644 (file)
@@ -1,6 +1,8 @@
 <?php
+use Shaarli\Config\ConfigJson;
+use Shaarli\Config\ConfigManager;
+use Shaarli\Config\ConfigPhp;
 
-require_once 'application/config/ConfigManager.php';
 require_once 'tests/Updater/DummyUpdater.php';
 require_once 'inc/rain.tpl.class.php';
 
@@ -572,4 +574,45 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
         $this->assertTrue($updater->updateMethodEscapeMarkdown());
         $this->assertFalse($this->conf->get('security.markdown_escape'));
     }
+
+    /**
+     * Test updateMethodPiwikUrl with valid data
+     */
+    public function testUpdatePiwikUrlValid()
+    {
+        $sandboxConf = 'sandbox/config';
+        copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
+        $this->conf = new ConfigManager($sandboxConf);
+        $url = 'mypiwik.tld';
+        $this->conf->set('plugins.PIWIK_URL', $url);
+        $updater = new Updater([], [], $this->conf, true);
+        $this->assertTrue($updater->updateMethodPiwikUrl());
+        $this->assertEquals('http://'. $url, $this->conf->get('plugins.PIWIK_URL'));
+
+        // reload from file
+        $this->conf = new ConfigManager($sandboxConf);
+        $this->assertEquals('http://'. $url, $this->conf->get('plugins.PIWIK_URL'));
+    }
+
+    /**
+     * Test updateMethodPiwikUrl without setting
+     */
+    public function testUpdatePiwikUrlEmpty()
+    {
+        $updater = new Updater([], [], $this->conf, true);
+        $this->assertTrue($updater->updateMethodPiwikUrl());
+        $this->assertEmpty($this->conf->get('plugins.PIWIK_URL'));
+    }
+
+    /**
+     * Test updateMethodPiwikUrl: valid URL, nothing to do
+     */
+    public function testUpdatePiwikUrlNothingToDo()
+    {
+        $url = 'https://mypiwik.tld';
+        $this->conf->set('plugins.PIWIK_URL', $url);
+        $updater = new Updater([], [], $this->conf, true);
+        $this->assertTrue($updater->updateMethodPiwikUrl());
+        $this->assertEquals($url, $this->conf->get('plugins.PIWIK_URL'));
+    }
 }