diff --git a/application/Updater.php b/application/Updater.php index 27cb2f0a..fd7e2073 100644 --- a/application/Updater.php +++ b/application/Updater.php @@ -1,6 +1,7 @@ conf->exists('plugins.PIWIK_URL') || startsWith($this->conf->get('plugins.PIWIK_URL'), 'http')) { + return true; + } + + $this->conf->set('plugins.PIWIK_URL', 'http://'. $this->conf->get('plugins.PIWIK_URL')); + $this->conf->write($this->isLoggedIn); + return true; + } } /** diff --git a/plugins/piwik/piwik.html b/plugins/piwik/piwik.html new file mode 100644 index 00000000..0881d7c8 --- /dev/null +++ b/plugins/piwik/piwik.html @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/plugins/piwik/piwik.php b/plugins/piwik/piwik.php index 7c44909c..4a2b48a1 100644 --- a/plugins/piwik/piwik.php +++ b/plugins/piwik/piwik.php @@ -50,22 +50,13 @@ function hook_piwik_render_footer($data, $conf) } // Free elements at the end of the page. - $data['endofpage'][] = '' . -'' . -'' . -''; + $data['endofpage'][] = sprintf( + file_get_contents(PluginManager::$PLUGINS_PATH . '/piwik/piwik.html'), + $piwikUrl, + $piwikSiteid, + $piwikUrl, + $piwikSiteid + ); return $data; } - diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 448405a3..b522d616 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -574,4 +574,45 @@ public function testEscapeMarkdownSettingNothingToDoDisabled() $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')); + } }