public function testSetAndGetPreference()
 {
     global $sugar_config;
     $user = new User();
     $user->retrieve('1');
     $userPreference = new UserPreference($user);
     //test setPreference method
     $userPreference->setPreference('test', 'test val', 'test_category');
     $result = $_SESSION[$user->user_name . '_PREFERENCES']['test_category']['test'];
     $this->assertEquals('test val', $result);
     //test getPreference method
     $result = $userPreference->getPreference('test', 'test_category');
     $this->assertEquals('test val', $result);
     $result = $userPreference->getPreference('chartEngine');
     $this->assertEquals($sugar_config['chartEngine'], $result);
 }
 /**
  * Delete a filter from previously used
  * @param RestService $api 
  * @param array $args 
  * @return array of formatted Beans
  */
 public function deleteUsed($api, $args)
 {
     $data = array();
     $user_preference = new UserPreference($GLOBALS['current_user']);
     $used_filters = $user_preference->getPreference($args['module_name'], 'filters');
     if (isset($args['record']) && !empty($args['record'])) {
         // if the record exists unset it
         $key = array_search($args['record'], $used_filters);
         if ($key !== false) {
             unset($used_filters[$key]);
         }
     } else {
         // delete them all
         $used_filters = array();
     }
     $user_preference->setPreference($args['module_name'], $used_filters, 'filters');
     $user_preference->savePreferencesToDB(true);
     if (!empty($used_filters)) {
         $beans = $this->loadFilters($used_filters);
         $data = $this->formatBeans($api, $args, $beans);
     }
     return $data;
 }
 /**
  * Alias for setPreference in modules/UserPreferences/UserPreference.php
  *    
  */
 function getPreference($name, $category = 'global', $user = null)
 {
     if (isset($user)) {
         return UserPreference::getPreference($name, $category, $user);
     } else {
         return UserPreference::getPreference($name, $category, $this);
     }
 }