X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FUpdater%2FUpdaterTest.php;h=39be88f944c1d10c39fce0273c8f1427a4cbb4a5;hb=e03761011521929a375ebb56f21adacb226a3a8d;hp=1d15cfaaace698d825a9b711258ee504f0927dc0;hpb=9977c418d6d0de9e22e4ec276e7d476e184b5d01;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/Updater/UpdaterTest.php b/tests/Updater/UpdaterTest.php index 1d15cfaa..39be88f9 100644 --- a/tests/Updater/UpdaterTest.php +++ b/tests/Updater/UpdaterTest.php @@ -466,4 +466,110 @@ $GLOBALS[\'privateLinkByDefault\'] = true;'; unlink('sandbox/'. $theme .'/linklist.html'); rmdir('sandbox/'. $theme); } + + /** + * Test updateMethodDefaultThemeVintage with the default theme enabled. + */ + public function testSetDefaultThemeToVintage() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + + $this->conf->set('resource.theme', 'default'); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodDefaultThemeVintage()); + $this->assertEquals('vintage', $this->conf->get('resource.theme')); + + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertEquals('vintage', $this->conf->get('resource.theme')); + } + + /** + * Test updateMethodDefaultThemeVintage with custom theme enabled => nothing to do. + */ + public function testSetDefaultThemeNothingToDo() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + + $theme = 'myawesometheme'; + $this->conf->set('resource.theme', $theme); + $this->conf->write(true); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodDefaultThemeVintage()); + $this->assertEquals($theme, $this->conf->get('resource.theme')); + + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertEquals($theme, $this->conf->get('resource.theme')); + } + + /** + * Test updateMethodEscapeMarkdown with markdown plugin enabled + * => setting markdown_escape set to false. + */ + public function testEscapeMarkdownSettingToFalse() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + + $this->conf->set('general.enabled_plugins', ['markdown']); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodEscapeMarkdown()); + $this->assertFalse($this->conf->get('security.markdown_escape')); + + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertFalse($this->conf->get('security.markdown_escape')); + } + + + /** + * Test updateMethodEscapeMarkdown with markdown plugin disabled + * => setting markdown_escape set to true. + */ + public function testEscapeMarkdownSettingToTrue() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + + $this->conf->set('general.enabled_plugins', []); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodEscapeMarkdown()); + $this->assertTrue($this->conf->get('security.markdown_escape')); + + // reload from file + $this->conf = new ConfigManager($sandboxConf); + $this->assertTrue($this->conf->get('security.markdown_escape')); + } + + /** + * Test updateMethodEscapeMarkdown with nothing to do (setting already enabled) + */ + public function testEscapeMarkdownSettingNothingToDoEnabled() + { + $sandboxConf = 'sandbox/config'; + copy(self::$configFile . '.json.php', $sandboxConf . '.json.php'); + $this->conf = new ConfigManager($sandboxConf); + $this->conf->set('security.markdown_escape', true); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodEscapeMarkdown()); + $this->assertTrue($this->conf->get('security.markdown_escape')); + } + + /** + * Test updateMethodEscapeMarkdown with nothing to do (setting already disabled) + */ + public function testEscapeMarkdownSettingNothingToDoDisabled() + { + $this->conf->set('security.markdown_escape', false); + $updater = new Updater([], [], $this->conf, true); + $this->assertTrue($updater->updateMethodEscapeMarkdown()); + $this->assertFalse($this->conf->get('security.markdown_escape')); + } }