[icinga-checkins] icinga.org: icingaweb2/master: Add unit tests for the fixed IniWriter implementation

git at icinga.org git at icinga.org
Tue Oct 18 14:22:24 CEST 2016


Module: icingaweb2
Branch: master
Commit: 58b2e6c00f78a86199ed453c8804722665b543b3
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=58b2e6c00f78a86199ed453c8804722665b543b3

Author: Alexander A. Klimov <alexander.klimov at netways.de>
Date:   Wed Oct 12 13:41:42 2016 +0200

Add unit tests for the fixed IniWriter implementation

refs #11743

---

 test/php/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 3148779..e4bfd27 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);
+    }
 }



More information about the icinga-checkins mailing list