From 1aa95b054cc65b127162d767f770dd9ffc718731 Mon Sep 17 00:00:00 2001 From: Matthias Jentsch Date: Tue, 26 Aug 2014 18:24:31 +0200 Subject: [PATCH] Add unit tests for nested-key handling in the PreservingIniWriter fixes #6381 --- .../Icinga/Config/PreservingIniWriterTest.php | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/test/php/library/Icinga/Config/PreservingIniWriterTest.php b/test/php/library/Icinga/Config/PreservingIniWriterTest.php index b69bc4d1c..da7e9674d 100644 --- a/test/php/library/Icinga/Config/PreservingIniWriterTest.php +++ b/test/php/library/Icinga/Config/PreservingIniWriterTest.php @@ -12,12 +12,14 @@ use Icinga\Config\PreservingIniWriter; class PreservingIniWriterTest extends BaseTestCase { protected $tempFile; + protected $tempFile2; public function setUp() { parent::setUp(); $this->tempFile = tempnam(sys_get_temp_dir(), 'icinga-ini-writer-test'); + $this->tempFile2 = tempnam(sys_get_temp_dir(), 'icinga-ini-writer-test-2'); } public function tearDown() @@ -25,6 +27,7 @@ class PreservingIniWriterTest extends BaseTestCase parent::tearDown(); unlink($this->tempFile); + unlink($this->tempFile2); } public function testWhetherSimplePropertiesAreInsertedInEmptyFiles() @@ -299,7 +302,7 @@ EOD ); $this->assertEquals( '1', - $newConfig->get('bar')->get('key1'), + $newConfig->get('foo')->get('key1'), 'PreservingIniWriter does not properly define extending sections' ); } @@ -678,6 +681,44 @@ EOD; ); } + public function testKeyNormalization() + { + $normalKeys = new PreservingIniWriter( + array ( + 'config' => new Zend_Config(array ( + 'foo' => 'bar', + 'nest' => array ( + 'nested' => array ( + 'stuff' => 'nested configuration element' + ) + ), + 'preserving' => array ( + 'ini' => array( + 'writer' => 'n' + ), + 'foo' => 'this should not be overwritten' + ) + )), + 'filename' => $this->tempFile + ) + + ); + + $nestedKeys = new PreservingIniWriter( + array ( + 'config' => new Zend_Config(array ( + 'foo' => 'bar', + 'nest.nested.stuff' => 'nested configuration element', + 'preserving.ini.writer' => 'n', + 'preserving.foo' => 'this should not be overwritten' + )), + 'filename' => $this->tempFile2 + ) + + ); + $this->assertEquals($normalKeys->render(), $nestedKeys->render()); + } + /** * Write a INI-configuration string to a temporary file and return it's path *