From c93159d287679af930b7a2f2e5b725bbe0721fad Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 22 Apr 2014 13:00:03 +0200 Subject: [PATCH] Add test for Icinga\User\Preferences\Store\IniStore refs #6011 --- .../User/Preferences/Store/IniStore.php | 2 +- .../Icinga/User/Store/IniStoreTest.php | 67 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 test/php/library/Icinga/User/Store/IniStoreTest.php diff --git a/library/Icinga/User/Preferences/Store/IniStore.php b/library/Icinga/User/Preferences/Store/IniStore.php index c3521b422..7363f2569 100644 --- a/library/Icinga/User/Preferences/Store/IniStore.php +++ b/library/Icinga/User/Preferences/Store/IniStore.php @@ -4,7 +4,7 @@ namespace Icinga\User\Preferences\Store; -use \Zend_Config; +use Zend_Config; use Icinga\Util\File; use Icinga\Config\PreservingIniWriter; use Icinga\Exception\NotReadableError; diff --git a/test/php/library/Icinga/User/Store/IniStoreTest.php b/test/php/library/Icinga/User/Store/IniStoreTest.php new file mode 100644 index 000000000..d6637d2f2 --- /dev/null +++ b/test/php/library/Icinga/User/Store/IniStoreTest.php @@ -0,0 +1,67 @@ +preferences = $preferences; + } + + public function getPreferences() + { + return $this->preferences; + } +} + +class IniStoreTest extends BaseTestCase +{ + public function testWhetherPreferenceChangesAreApplied() + { + $store = $this->getStore(); + $store->setPreferences(array('key1' => '1')); + + $store->save( + Mockery::mock('Icinga\User\Preferences', array('toArray' => array('key1' => '11', 'key2' => '2'))) + ); + $this->assertEquals( + array('key1' => '11', 'key2' => '2'), + $store->getPreferences(), + 'IniStore::save does not properly apply changed preferences' + ); + } + + public function testWhetherPreferenceDeletionsAreApplied() + { + $store = $this->getStore(); + $store->setPreferences(array('key' => 'value')); + + $store->save(Mockery::mock('Icinga\User\Preferences', array('toArray' => array()))); + $this->assertEmpty($store->getPreferences(), 'IniStore::save does not delete removed preferences'); + } + + protected function getStore() + { + return new IniStoreWithSetGetPreferencesAndEmptyWrite( + new Zend_Config( + array( + 'location' => 'some/Path/To/Some/Directory' + ) + ), + Mockery::mock('Icinga\User', array('getUsername' => 'unittest')) + ); + } +}