2014-04-22 13:00:03 +02:00
|
|
|
<?php
|
2015-02-03 16:27:59 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | http://www.gnu.org/licenses/gpl-2.0.txt */
|
2014-04-22 13:00:03 +02:00
|
|
|
|
|
|
|
namespace Tests\Icinga\User\Preferences\Store;
|
|
|
|
|
|
|
|
use Mockery;
|
2014-11-18 13:11:52 +01:00
|
|
|
use Icinga\Data\ConfigObject;
|
2014-04-22 13:00:03 +02:00
|
|
|
use Icinga\Test\BaseTestCase;
|
|
|
|
use Icinga\User\Preferences\Store\IniStore;
|
|
|
|
|
|
|
|
class IniStoreWithSetGetPreferencesAndEmptyWrite extends IniStore
|
|
|
|
{
|
|
|
|
public function write()
|
|
|
|
{
|
|
|
|
// Gets called by IniStore::save
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPreferences($preferences)
|
|
|
|
{
|
|
|
|
$this->preferences = $preferences;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPreferences()
|
|
|
|
{
|
|
|
|
return $this->preferences;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class IniStoreTest extends BaseTestCase
|
|
|
|
{
|
|
|
|
public function testWhetherPreferenceChangesAreApplied()
|
|
|
|
{
|
|
|
|
$store = $this->getStore();
|
2014-11-12 17:13:15 +01:00
|
|
|
$store->setPreferences(array('testsection' => array('key1' => '1')));
|
2014-04-22 13:00:03 +02:00
|
|
|
|
|
|
|
$store->save(
|
2014-11-12 17:13:15 +01:00
|
|
|
Mockery::mock('Icinga\User\Preferences', array(
|
|
|
|
'toArray' => array('testsection' => array('key1' => '11', 'key2' => '2'))
|
|
|
|
))
|
2014-04-22 13:00:03 +02:00
|
|
|
);
|
|
|
|
$this->assertEquals(
|
2014-11-12 17:13:15 +01:00
|
|
|
array('testsection' => array('key1' => '11', 'key2' => '2')),
|
2014-04-22 13:00:03 +02:00
|
|
|
$store->getPreferences(),
|
|
|
|
'IniStore::save does not properly apply changed preferences'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testWhetherPreferenceDeletionsAreApplied()
|
|
|
|
{
|
|
|
|
$store = $this->getStore();
|
2014-11-12 17:13:15 +01:00
|
|
|
$store->setPreferences(array('testsection' => array('key' => 'value')));
|
2014-04-22 13:00:03 +02:00
|
|
|
|
2014-11-12 17:13:15 +01:00
|
|
|
$store->save(Mockery::mock('Icinga\User\Preferences', array('toArray' => array('testsection' => array()))));
|
|
|
|
|
|
|
|
$result = $store->getPreferences();
|
|
|
|
|
|
|
|
$this->assertEmpty($result['testsection'], 'IniStore::save does not delete removed preferences');
|
2014-04-22 13:00:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getStore()
|
|
|
|
{
|
|
|
|
return new IniStoreWithSetGetPreferencesAndEmptyWrite(
|
2014-11-18 13:11:52 +01:00
|
|
|
new ConfigObject(
|
2014-04-22 13:00:03 +02:00
|
|
|
array(
|
|
|
|
'location' => 'some/Path/To/Some/Directory'
|
|
|
|
)
|
|
|
|
),
|
|
|
|
Mockery::mock('Icinga\User', array('getUsername' => 'unittest'))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|