From c61e9f391273e5f7f4b7aa91ee4174d47402cae9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 23 Jan 2015 10:50:25 +0100 Subject: Add a method to set/unset multiple config values in one call This reduces the number of file writes we do for config.php and therefor hopefully helps lowering the chances for empty config.php files --- tests/lib/config.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests') diff --git a/tests/lib/config.php b/tests/lib/config.php index 6adba356a1c..91154579ab5 100644 --- a/tests/lib/config.php +++ b/tests/lib/config.php @@ -71,6 +71,36 @@ class Test_Config extends \Test\TestCase { $this->assertEquals($expected, $content); } + public function testSetValues() { + $content = file_get_contents($this->configFile); + $this->assertEquals(self::TESTCONTENT, $content); + + // Changing configs to existing values and deleting non-existing once + // should not rewrite the config.php + $this->config->setValues([ + 'foo' => 'bar', + 'not_exists' => null, + ]); + + $this->assertAttributeEquals($this->initialConfig, 'cache', $this->config); + $content = file_get_contents($this->configFile); + $this->assertEquals(self::TESTCONTENT, $content); + + $this->config->setValues([ + 'foo' => 'moo', + 'alcohol_free' => null, + ]); + $expectedConfig = $this->initialConfig; + $expectedConfig['foo'] = 'moo'; + unset($expectedConfig['alcohol_free']); + $this->assertAttributeEquals($expectedConfig, 'cache', $this->config); + + $content = file_get_contents($this->configFile); + $expected = " 'moo',\n 'beers' => \n array (\n 0 => 'Appenzeller',\n " . + " 1 => 'Guinness',\n 2 => 'Kölsch',\n ),\n);\n"; + $this->assertEquals($expected, $content); + } + public function testDeleteKey() { $this->config->deleteKey('foo'); $expectedConfig = $this->initialConfig; -- cgit v1.2.3