From 58b2e6c00f78a86199ed453c8804722665b543b3 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 12 Oct 2016 13:41:42 +0200 Subject: [PATCH] Add unit tests for the fixed IniWriter implementation refs #11743 --- .../library/Icinga/File/Ini/IniWriterTest.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/php/library/Icinga/File/Ini/IniWriterTest.php b/test/php/library/Icinga/File/Ini/IniWriterTest.php index 3148779ef..e4bfd2716 100644 --- a/test/php/library/Icinga/File/Ini/IniWriterTest.php +++ b/test/php/library/Icinga/File/Ini/IniWriterTest.php @@ -400,4 +400,53 @@ EOD; file_put_contents($this->tempFile, $config); return $this->tempFile; } + + public function testWhetherNullValuesGetPersisted() + { + $config = Config::fromArray(array()); + $section = $config->getSection('garbage'); + $section->foobar = null; + $config->setSection('garbage', $section); + + $iniWriter = new IniWriter($config, '/dev/null'); + $this->assertEquals( + 0, + preg_match('/foobar/', $iniWriter->render()), + 'IniWriter persists section keys with null values' + ); + } + + public function testWhetherEmptyValuesGetPersisted() + { + $config = Config::fromArray(array()); + $section = $config->getSection('garbage'); + $section->foobar = ''; + $config->setSection('garbage', $section); + + $iniWriter = new IniWriter($config, '/dev/null'); + $this->assertEquals( + 1, + preg_match('/foobar/', $iniWriter->render()), + 'IniWriter doesn\'t persist section keys with empty values' + ); + } + + public function testExplicitRemove() + { + $filename = tempnam(sys_get_temp_dir(), 'iw2'); + $config = Config::fromArray(array('garbage' => array('foobar' => 'lolcat'))); + $iniWriter = new IniWriter($config, $filename); + $iniWriter->write(); + + $section = $config->getSection('garbage'); + $section->foobar = null; + $iniWriter = new IniWriter($config, $filename); + $this->assertEquals( + 0, + preg_match('/foobar/', $iniWriter->render()), + 'IniWriter doesn\'t remove section keys with null values' + ); + + unlink($filename); + } }