It also includes all of the functions for retrieving, storing, and checking preference values.
Author: Jon Parise (jon@horde.org)
Inheritance: implements ArrayAccess
Esempio n. 1
0
 public function testModifyPreferences()
 {
     $p = new Horde_Prefs('horde', array(self::$prefs));
     $p['theme'] = "barbie";
     $p->store();
     $this->assertEquals("barbie", $this->_readValue(self::$db->selectValue('SELECT pref_value FROM horde_prefs WHERE pref_uid = ? AND pref_scope = ? AND pref_name = ?', array('joe', 'horde', 'theme'))));
 }
Esempio n. 2
0
 public function testLargePreferences()
 {
     $p = new Horde_Prefs('test', array(self::$prefs, new Horde_Prefs_Stub_Storage('test')));
     $value = str_repeat('x', 4001);
     $p['a'] = $value;
     $p->store();
     $this->assertEquals($value, $this->_readValue(self::$db->selectValue('SELECT pref_value FROM horde_prefs WHERE pref_uid = ? AND pref_scope = ? AND pref_name = ?', array('joe', 'test', 'a'))));
 }
Esempio n. 3
0
 public function testCreateFolder()
 {
     $this->markTestIncomplete('The mock driver confuses user/test/Preferences with INBOX/Preferences');
     setlocale(LC_MESSAGES, 'C');
     $p = new Horde_Prefs('test', array(new Horde_Prefs_Storage_KolabImap('test', array('kolab' => $this->_createStorage())), new Horde_Prefs_Stub_Storage('test')));
     $p['a'] = 'c';
     $p->store();
     $this->assertLogContains('Horde_Prefs_Storage_KolabImap: Created default Kolab preferences folder "Preferences".');
 }
Esempio n. 4
0
 public function testModifyPreferences()
 {
     $storage = $this->_createDefaultStorage();
     $p = new Horde_Prefs('horde', array(new Horde_Prefs_Storage_KolabImap('*****@*****.**', array('kolab' => $storage))));
     $p['theme'] = 'barbie';
     $p->store();
     $objects = $storage->getData('INBOX/Preferences')->getObjects();
     $object = array_pop($objects);
     $this->assertContains('theme:YmFyYmll', $object['pref']);
     $p->cleanup(true);
 }
Esempio n. 5
0
 /**
  * Returns true if all properties are locked and therefore nothing in the
  * identities can be changed.
  *
  * @return boolean  True if all properties are locked, false otherwise.
  */
 public function isLocked()
 {
     foreach ($this->_prefnames['properties'] as $key) {
         if (!$this->_prefs->isLocked($key)) {
             return false;
         }
     }
     return true;
 }
Esempio n. 6
0
 /**
  * Upgrades the given preferences from the old H3 way of storing
  * serialized data.
  * OLD method: convert charset, serialize, store.
  * NEW method: serialize, convert charset, store.
  *
  * @param Horde_Prefs $prefs_ob  The preferences object.
  * @param array $names           The list of names to upgrade.
  */
 public function upgradeSerialized($prefs_ob, array $names)
 {
     /* Only do upgrade for SQL driver. */
     foreach ($prefs_ob->getStorage() as $storage) {
         if ($storage instanceof Horde_Prefs_Storage_Sql) {
             break;
         }
     }
     if (!$storage instanceof Horde_Prefs_Storage_Sql) {
         return;
     }
     /* Only do upgrade if charset is not UTF-8. */
     $charset = $storage->getCharset();
     if (strcasecmp($charset, 'UTF-8') === 0) {
         return;
     }
     foreach ($names as $name) {
         if (!$prefs_ob->isDefault($name)) {
             $data = $prefs_ob->getValue($name);
             /* Need to convert only if unserialize fails. If it succeeds,
              * the data has already been converted or there is no need
              * to convert. */
             if (@unserialize($data) === false) {
                 /* Re-convert to original charset. */
                 $data = Horde_String::convertCharset($data, 'UTF-8', $charset);
                 /* Unserialize. If we fail here, remove the value
                  * outright since it is invalid and can not be fixed. */
                 if (($data = @unserialize($data)) !== false) {
                     $data = Horde_String::convertCharset($data, $charset, 'UTF-8');
                     /* Re-save in the prefs backend in the new format. */
                     $prefs_ob->setValue($name, serialize($data));
                 }
             }
         }
     }
 }