add a few tests for Settings

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2019-06-05 06:39:44 +02:00
parent 13086d91d8
commit 97703e7a0c
2 changed files with 96 additions and 0 deletions

View File

@@ -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)

View File

@@ -0,0 +1,94 @@
<?php
use PHPUnit\Framework\TestCase;
/**
*
* @covers \Froxlor\Settings
*/
class SettingsTest extends TestCase
{
protected function setUp() {
// start fresh
\Froxlor\Settings::Stash();
}
public function testSettingGet()
{
$syshostname = \Froxlor\Settings::Get('system.hostname');
$this->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);
}
}