From 97703e7a0cd1c74e79b60d41e9a739d7cc10f164 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Wed, 5 Jun 2019 06:39:44 +0200 Subject: [PATCH] add a few tests for Settings Signed-off-by: Michael Kaufmann --- lib/Froxlor/Settings.php | 2 + tests/Froxlor/SettingsTest.php | 94 ++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 tests/Froxlor/SettingsTest.php diff --git a/lib/Froxlor/Settings.php b/lib/Froxlor/Settings.php index 88edf132..17dd0c43 100644 --- a/lib/Froxlor/Settings.php +++ b/lib/Froxlor/Settings.php @@ -263,6 +263,8 @@ class Settings self::init(); // empty update array self::$updatedata = array(); + // re-read in all settings + return self::readSettings(); } public static function loadSettingsInto(&$settings_data) diff --git a/tests/Froxlor/SettingsTest.php b/tests/Froxlor/SettingsTest.php new file mode 100644 index 00000000..b0f9922d --- /dev/null +++ b/tests/Froxlor/SettingsTest.php @@ -0,0 +1,94 @@ +assertEquals("dev.froxlor.org", $syshostname); + } + + public function testSettingGetNoSeparator() + { + $nullval = \Froxlor\Settings::Get('system'); + $this->assertNull($nullval); + } + + public function testSettingGetUnknown() + { + $nullval = \Froxlor\Settings::Get('thissetting.doesnotexist'); + $this->assertNull($nullval); + } + + public function testSettingsAddNew() + { + \Froxlor\Settings::AddNew('temp.setting', 'empty'); + $actval = \Froxlor\Settings::Get('temp.setting'); + $this->assertEquals("empty", $actval); + } + + public function testSettingsAddNewSettingExists() + { + $result = \Froxlor\Settings::AddNew('system.ipaddress', '127.0.0.1'); + $this->assertFalse($result); + } + + /** + * + * @depends testSettingsAddNew + */ + public function testSettingSetNoSave() + { + $actval = \Froxlor\Settings::Get('temp.setting'); + $this->assertEquals("empty", $actval); + \Froxlor\Settings::Set('temp.setting', 'temp-value', false); + $tmpval = \Froxlor\Settings::Get('temp.setting'); + $this->assertEquals("temp-value", $tmpval); + \Froxlor\Settings::Stash(); + $actval = \Froxlor\Settings::Get('temp.setting'); + $this->assertEquals("empty", $actval); + } + + /** + * + * @depends testSettingsAddNew + */ + public function testSettingsSetInstantSave() + { + \Froxlor\Settings::Set('temp.setting', 'temp-value'); + \Froxlor\Settings::Stash(); + $tmpval = \Froxlor\Settings::Get('temp.setting'); + $this->assertEquals("temp-value", $tmpval); + } + + /** + * + * @depends testSettingsAddNew + */ + public function testSettingsSetFlushSave() + { + \Froxlor\Settings::Set('temp.setting', 'another-temp-value', false); + \Froxlor\Settings::Flush(); + $actval = \Froxlor\Settings::Get('temp.setting'); + $this->assertEquals("another-temp-value", $actval); + } + + public function testSettingsIsInList() + { + $result = \Froxlor\Settings::IsInList("system.mysql_access_host", "localhost"); + $this->assertTrue($result); + $result = \Froxlor\Settings::IsInList("system.mysql_access_host", "my-super-domain.de"); + $this->assertFalse($result); + } +}