parent
be410a685b
commit
d44aaeb8d7
|
@ -44,8 +44,6 @@ use Countable;
|
|||
*
|
||||
* $preferences = new Preferences(array('aPreference' => 'value')); // Start with initial preferences
|
||||
*
|
||||
* $prefrences = $user->getPreferences(); // Retrieve preferences from a \Icinga\User instance
|
||||
*
|
||||
* $preferences->aNewPreference = 'value'; // Set a preference
|
||||
*
|
||||
* unset($preferences->aPreference); // Unset a preference
|
||||
|
@ -60,7 +58,7 @@ class Preferences implements Countable
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
private $preferences = array();
|
||||
protected $preferences = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
@ -118,6 +116,7 @@ class Preferences implements Countable
|
|||
if (array_key_exists($name, $this->preferences)) {
|
||||
return $this->preferences[$name];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
|
@ -147,6 +146,7 @@ class Preferences implements Countable
|
|||
* Determine if a preference is set and is not NULL
|
||||
*
|
||||
* @param string $name Preference name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name)
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\User;
|
||||
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
class PreferfencesTest extends BaseTestCase
|
||||
{
|
||||
public function testWhetherPreferencesCanBeSet()
|
||||
{
|
||||
$prefs = new Preferences();
|
||||
|
||||
$prefs->key = 'value';
|
||||
$this->assertTrue(isset($prefs->key));
|
||||
$this->assertEquals('value', $prefs->key);
|
||||
}
|
||||
|
||||
public function testWhetherPreferencesCanBeAccessed()
|
||||
{
|
||||
$prefs = new Preferences(array('key' => 'value'));
|
||||
|
||||
$this->assertTrue($prefs->has('key'));
|
||||
$this->assertEquals('value', $prefs->get('key'));
|
||||
}
|
||||
|
||||
public function testWhetherPreferencesCanBeRemoved()
|
||||
{
|
||||
$prefs = new Preferences(array('key' => 'value'));
|
||||
|
||||
unset($prefs->key);
|
||||
$this->assertFalse(isset($prefs->key));
|
||||
|
||||
$prefs->key = 'value';
|
||||
$prefs->remove('key');
|
||||
$this->assertFalse($prefs->has('key'));
|
||||
}
|
||||
|
||||
public function testWhetherPreferencesAreCountable()
|
||||
{
|
||||
$prefs = new Preferences(array('key1' => '1', 'key2' => '2'));
|
||||
|
||||
$this->assertEquals(2, count($prefs));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue