fixes app default config handling
[tine20] / tests / tine20 / Tinebase / Frontend / JsonTest.php
1 <?php
2 /**
3  * Tine 2.0
4  *
5  * @package     Tinebase
6  * @subpackage  Json
7  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
8  * @author      Philipp Schüle <p.schuele@metaways.de>
9  * @copyright   Copyright (c) 2007-2014 Metaways Infosystems GmbH (http://www.metaways.de)
10  *
11  */
12
13 /**
14  * Test helper
15  */
16 require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
17
18 /**
19  * Test class for Tinebase_Frontend_Json
20  */
21 class Tinebase_Frontend_JsonTest extends TestCase
22 {
23     /**
24      * unit under test (UIT)
25      * @var Tinebase_Frontend_Json
26      */
27     protected $_instance;
28
29     /**
30      * @var array test objects
31      */
32     protected $_objects = array();
33     
34     /**
35      * set up tests
36      *
37      */
38     public function setUp()
39     {
40         parent::setUp();
41         
42         $this->_instance = new Tinebase_Frontend_Json();
43         
44         $this->_objects['record'] = array(
45             'id'        => 1,
46             'model'     => 'Addressbook_Model_Contact',
47             'backend'    => 'Sql',
48         );
49
50         $this->_objects['group'] = new Tinebase_Model_Group(array(
51             'name'            => 'phpunit test group',
52             'description'    => 'phpunit test group'
53         ));
54
55         $this->_objects['role'] = new Tinebase_Model_Role(array(
56             'name'            => 'phpunit test role',
57             'description'    => 'phpunit test role'
58         ));
59
60         $this->_objects['note'] = new Tinebase_Model_Note(array(
61             'note_type_id'      => 1,
62             'note'              => 'phpunit test note',
63             'record_model'      => $this->_objects['record']['model'],
64             'record_backend'    => $this->_objects['record']['backend'],
65         ));
66     }
67     
68     /**
69      * tear down
70      */
71     public function tearDown()
72     {
73         parent::tearDown();
74         
75         // reset tz in core
76         Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, Tinebase_Core::getPreference()->getValue(Tinebase_Preference::TIMEZONE));
77     }
78     
79     /**
80      * try to add a note type
81      */
82     public function testSearchNotes()
83     {
84         $contact = Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array('n_family' => 'Schulz')));
85         $note = $this->_objects['note'];
86         $note->record_id = $contact->getId();
87         Tinebase_Notes::getInstance()->addNote($note);
88
89         $filter = array(array(
90             'field' => 'query',
91             'operator' => 'contains',
92             'value' => 'phpunit'
93         ), array(
94             'field' => "record_model",
95             'operator' => "equals",
96             'value' => $this->_objects['record']['model']
97         ), array(
98             'field' => 'record_id',
99             'operator' => 'equals',
100             'value' => $contact->getId()
101         ));
102         $paging = array();
103         
104         $notes = $this->_instance->searchNotes($filter, $paging);
105         
106         $this->assertGreaterThan(0, $notes['totalcount']);
107         $found = false;
108         foreach ($notes['results'] as $note) {
109             if ($this->_objects['note']->note === $note['note']) {
110                 $found = true;
111             }
112         }
113         $this->assertTrue($found, 'note not found in notes: ' . print_r($notes['results'], true));
114         
115         // delete note
116         Tinebase_Notes::getInstance()->deleteNotesOfRecord(
117             $this->_objects['record']['model'],
118             $this->_objects['record']['backend'],
119             $contact->getId()
120         );
121     }
122     
123     /**
124      * try to delete role and then search
125      */
126     public function testSearchRoles()
127     {
128         $role = Tinebase_Acl_Roles::getInstance()->createRole($this->_objects['role']);
129         
130         $filter = array(array(
131             'field'     => 'query',
132             'operator'     => 'contains',
133             'value'     => 'phpunit test role'
134         ));
135         $paging = array(
136             'start'    => 0,
137             'limit'    => 1
138         );
139         
140         $roles = $this->_instance->searchRoles($filter, $paging);
141         
142         $this->assertGreaterThan(0, $roles['totalcount']);
143         $this->assertEquals($this->_objects['role']->name, $roles['results'][0]['name']);
144         
145         // delete role
146         Tinebase_Acl_Roles::getInstance()->deleteRoles($role->id);
147     }
148     
149     /**
150      * test getCountryList
151      *
152      */
153     public function testGetCountryList()
154     {
155         $list = $this->_instance->getCountryList();
156         $this->assertTrue(count($list['results']) > 200);
157     }
158     
159     /**
160      * test get translations
161      *
162      */
163     public function testGetAvailableTranslations()
164     {
165         $list = $this->_instance->getAvailableTranslations();
166         $this->assertTrue(count($list['results']) > 3);
167     }
168     
169     /**
170      * tests locale fallback
171      */
172     public function testSetLocaleFallback()
173     {
174         // de_LU -> de
175         $this->_instance->setLocale('de_LU', FALSE, FALSE);
176         $this->assertEquals('de', (string)Zend_Registry::get('locale'), 'Fallback to generic german did not succseed');
177         
178         $this->_instance->setLocale('zh', FALSE, FALSE);
179         $this->assertEquals('zh_CN', (string)Zend_Registry::get('locale'), 'Fallback to simplified chinese did not succseed');
180         
181         $this->_instance->setLocale('foo_bar', FALSE, FALSE);
182         $this->assertEquals('en', (string)Zend_Registry::get('locale'), 'Exception fallback to english did not succseed');
183     }
184     
185     /**
186      * test set locale and save it in db
187      */
188     public function testSetLocaleAsPreference()
189     {
190         $oldPreference = Tinebase_Core::getPreference()->{Tinebase_Preference::LOCALE};
191         
192         $locale = 'de';
193         $result = $this->_instance->setLocale($locale, TRUE, FALSE);
194         
195         // get config setting from db
196         $preference = Tinebase_Core::getPreference()->{Tinebase_Preference::LOCALE};
197         $this->assertEquals($locale, $preference, "Didn't get right locale preference.");
198         
199         // restore old setting
200         Tinebase_Core::getPreference()->{Tinebase_Preference::LOCALE} = $oldPreference;
201     }
202
203     /**
204      * test set timezone and save it in db
205      */
206     public function testSetTimezoneAsPreference()
207     {
208         $oldPreference = Tinebase_Core::getPreference()->{Tinebase_Preference::TIMEZONE};
209         
210         $timezone = 'America/Vancouver';
211         $result = $this->_instance->setTimezone($timezone, true);
212         
213         // check json result
214         $this->assertEquals($timezone, $result);
215         
216         // get config setting from db
217         $preference = Tinebase_Core::getPreference()->{Tinebase_Preference::TIMEZONE};
218         $this->assertEquals($timezone, $preference, "Didn't get right timezone preference.");
219         
220         // restore old settings
221         Tinebase_Core::set(Tinebase_Core::USERTIMEZONE, $oldPreference);
222         Tinebase_Core::getPreference()->{Tinebase_Preference::TIMEZONE} = $oldPreference;
223     }
224     
225     /**
226      * get notes types
227      */
228     public function testGetNotesTypes()
229     {
230         $noteTypes = $this->_instance->getNoteTypes();
231         $this->assertTrue($noteTypes['totalcount'] >= 5);
232     }
233     
234     /**
235      * search preferences by application
236      *
237      */
238     public function testSearchPreferences()
239     {
240         // search prefs
241         $result = $this->_instance->searchPreferencesForApplication('Tinebase', $this->_getPreferenceFilter());
242         
243         // check results
244         $this->assertTrue(isset($result['results']));
245         $this->assertGreaterThan(2, $result['totalcount']);
246         
247         //check locale/timezones options
248         foreach ($result['results'] as $pref) {
249             switch($pref['name']) {
250                 case Tinebase_Preference::LOCALE:
251                     $this->assertGreaterThan(10, count($pref['options']));
252                     break;
253                 case Tinebase_Preference::TIMEZONE:
254                     $this->assertGreaterThan(100, count($pref['options']));
255                     break;
256             }
257             // check label and description
258             $this->assertTrue(isset($pref['label']) && !empty($pref['label']));
259             $this->assertTrue(isset($pref['description']) && !empty($pref['description']));
260         }
261     }
262
263     /**
264      * search preferences by application
265      *
266      */
267     public function testSearchPreferencesWithOptions()
268     {
269         // add new default pref
270         $pref = $this->_getPreferenceWithOptions();
271         $pref = Tinebase_Core::getPreference()->create($pref);
272         
273         // search prefs
274         $results = $this->_instance->searchPreferencesForApplication('Tinebase', $this->_getPreferenceFilter());
275         
276         // check results
277         $this->assertTrue(isset($results['results']));
278         $this->assertGreaterThan(3, $results['totalcount']);
279         
280         foreach ($results['results'] as $result) {
281             if ($result['name'] == 'defaultapp') {
282                 $this->assertEquals(Tinebase_Model_Preference::DEFAULT_VALUE, $result['value']);
283                 $this->assertTrue(is_array($result['options']));
284                 $this->assertEquals(3, count($result['options']));
285                 $this->assertContains('option1', $result['options'][1][1]);
286             } else if ($result['name'] == Tinebase_Preference::TIMEZONE) {
287                 $this->assertTrue(is_array($result['options'][0]), 'options should be arrays');
288             }
289         }
290         
291         Tinebase_Core::getPreference()->delete($pref);
292     }
293     
294     /**
295      * search preferences of another user
296      *
297      * @todo add check for the case that searching user has no admin rights
298      */
299     public function testSearchPreferencesOfOtherUsers()
300     {
301         // add new default pref
302         $pref = $this->_getPreferenceWithOptions();
303         $pref->account_id   = '2';
304         $pref->account_type = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER;
305         $pref = Tinebase_Core::getPreference()->create($pref);
306         
307         // search prefs
308         $results = $this->_instance->searchPreferencesForApplication('Tinebase', $this->_getPreferenceFilter(TRUE, FALSE, '2'));
309         
310         // check results
311         $this->assertTrue(isset($results['results']));
312         $this->assertEquals(1, $results['totalcount']);
313     }
314     
315     /**
316      * save preferences for user
317      *
318      * @todo add test for saving of other users prefs and acl check
319      */
320     public function testSavePreferences()
321     {
322         $prefData = $this->_getUserPreferenceData();
323         $this->_instance->savePreferences($prefData, false);
324
325         // search saved prefs
326         $results = $this->_instance->searchPreferencesForApplication('Tinebase', $this->_getPreferenceFilter(FALSE));
327         
328         // check results
329         $this->assertTrue(isset($results['results']));
330         $this->assertGreaterThan(2, $results['totalcount']);
331         
332         $savedPrefData = array();
333         foreach ($results['results'] as $result) {
334             if ($result['name'] == 'timezone') {
335                 $savedPrefData['Tinebase'][$result['name']] = array('value' => $result['value']);
336             
337                 $this->assertTrue(is_array($result['options']), 'options missing');
338                 $this->assertGreaterThan(100, count($result['options']));
339             }
340         }
341         $this->assertEquals($prefData, $savedPrefData);
342     }
343     
344     /**
345      * tests if 'use default' appears in options and if it can be selected and if it changes if default changes
346      */
347     public function testGetSetChangeDefaultPref()
348     {
349         $locale = $this->_getLocalePref();
350         foreach ($locale['options'] as $option) {
351             if ($option[0] == Tinebase_Model_Preference::DEFAULT_VALUE) {
352                 $result = $option;
353                 $defaultString = $option[1];
354             }
355         }
356         
357         $this->assertTrue(isset($defaultString));
358         $this->assertContains('(auto)', $defaultString);
359
360         // set user pref to en first then to 'use default'
361         Tinebase_Core::getPreference()->{Tinebase_Preference::LOCALE} = 'en';
362         Tinebase_Core::getPreference()->{Tinebase_Preference::LOCALE} = Tinebase_Model_Preference::DEFAULT_VALUE;
363         $this->assertEquals('auto', Tinebase_Core::getPreference()->{Tinebase_Preference::LOCALE});
364         
365         // set new default locale
366         $prefData['Tinebase']['default' . $locale['id']] = array('value' => 'de', 'type' => 'default', 'name' => Tinebase_Preference::LOCALE);
367         $this->_instance->savePreferences($prefData, true);
368         
369         $updatedLocale = $this->_getLocalePref();
370         foreach ($updatedLocale['options'] as $option) {
371             if ($option[0] == Tinebase_Model_Preference::DEFAULT_VALUE) {
372                 $result = $option;
373                 $defaultString = $option[1];
374             }
375         }
376         $this->assertEquals(count($locale['options']), count($updatedLocale['options']), 'option count has to be equal');
377         $this->assertContains('(Deutsch)', $defaultString);
378         $this->assertEquals('de', Tinebase_Core::getPreference()->{Tinebase_Preference::LOCALE});
379     }
380     
381     /**
382      * get locale pref
383      */
384     protected function _getLocalePref()
385     {
386         $results = $this->_instance->searchPreferencesForApplication('Tinebase', $this->_getPreferenceFilter());
387         foreach ($results['results'] as $result) {
388             if ($result['name'] == Tinebase_Preference::LOCALE) {
389                 $locale = $result;
390             }
391         }
392         
393         $this->assertTrue(isset($locale));
394         
395         return $locale;
396     }
397
398     /**
399      * get admin prefs
400      */
401     public function testGetAdminPreferences()
402     {
403         $this->testGetSetChangeDefaultPref();
404         
405         // set new default locale
406         $locale = $this->_getLocalePref();
407         $prefData['Tinebase'][$locale['id']] = array('value' => 'de', 'type' => 'default', 'name' => Tinebase_Preference::LOCALE);
408         $this->_instance->savePreferences($prefData, true);
409         
410         // check as admin
411         $results = $this->_instance->searchPreferencesForApplication('Tinebase', $this->_getPreferenceFilter(FALSE, TRUE));
412         foreach ($results['results'] as $pref) {
413             if ($pref['name'] !== Tinebase_Preference::LOCALE) {
414                 $this->assertEquals(Tinebase_Model_Preference::DEFAULT_VALUE, $pref['value']);
415             } else {
416                 $this->assertEquals(Tinebase_Model_Preference::TYPE_ADMIN, $pref['type']);
417                 $this->assertEquals('de', $pref['value'], print_r($pref, TRUE));
418             }
419         }
420
421         // check as user
422         $locale = $this->_getLocalePref();
423         $this->assertEquals(Tinebase_Model_Preference::TYPE_ADMIN, $locale['type'], 'pref should be of type admin: ' . print_r($locale, TRUE));
424         $this->assertEquals(Tinebase_Model_Preference::DEFAULT_VALUE, $locale['value'], 'pref should be default value: ' . print_r($locale, TRUE));
425     }
426     
427     /**
428      * save admin prefs
429      *
430      */
431     public function testSaveAdminPreferences()
432     {
433         // add new default pref
434         $pref = $this->_getPreferenceWithOptions();
435         $pref = Tinebase_Core::getPreference()->create($pref);
436         
437         $prefData = array();
438         $prefData['Tinebase'][$pref->getId()] = array('value' => 'test', 'type' => 'forced');
439         $this->_instance->savePreferences($prefData, true);
440
441         // search saved prefs
442         $results = $this->_instance->searchPreferencesForApplication('Tinebase', $this->_getPreferenceFilter(TRUE));
443         
444         // check results
445         $this->assertTrue(isset($results['results']));
446         $this->assertEquals(1, $results['totalcount']);
447         $this->assertEquals($prefData['Tinebase'][$pref->getId()]['value'], $results['results'][0]['value']);
448         $this->assertEquals($prefData['Tinebase'][$pref->getId()]['type'], $results['results'][0]['type']);
449     }
450     
451     /**
452      * save state and load it with registry data
453      */
454     public function testSaveAndGetState()
455     {
456         $testData = array(
457             'bla'   => 'blubb',
458             'zzing' => 'zzang'
459         );
460         
461         foreach ($testData as $key => $value) {
462             Tinebase_State::getInstance()->setState($key, $value);
463         }
464         
465         $stateInfo = Tinebase_State::getInstance()->loadStateInfo();
466         
467         $this->assertEquals($testData, $stateInfo);
468     }
469     
470     /**
471      * test get all registry data
472      *
473      * @return void
474      *
475      * @see 0007934: change pw button active even if it is not allowed
476      * @see 0008310: apps should be sorted the other way round in menu
477      * @see 0009130: Can't open login page on Ubuntu "due to a temporary overloading"
478      */
479     public function testGetAllRegistryData()
480     {
481         $registryData = $this->_instance->getAllRegistryData();
482         $currentUser = Tinebase_Core::getUser();
483         
484         $this->assertEquals($currentUser->toArray(), $registryData['Tinebase']['currentAccount']);
485         $this->assertEquals(
486             Addressbook_Controller_Contact::getInstance()->getContactByUserId($currentUser->getId())->toArray(),
487             $registryData['Tinebase']['userContact']
488         );
489         $this->assertEquals(TRUE, $registryData['Tinebase']['config']['changepw']['value'], 'changepw should be TRUE');
490         
491         Tinebase_Config::getInstance()->set('changepw', 0);
492         $registryData = $this->_instance->getAllRegistryData();
493         $changepwValue = $registryData['Tinebase']['config']['changepw']['value'];
494         $this->assertEquals(FALSE, $changepwValue, 'changepw should be (bool) false');
495         $this->assertTrue(is_bool($changepwValue), 'changepw should be (bool) false: ' . var_export($changepwValue, TRUE));
496         
497         $userApps = $registryData['Tinebase']['userApplications'];
498         $this->assertEquals('Admin', $userApps[0]['name'], 'first app should be Admin: ' . print_r($userApps, TRUE));
499         
500         $locale = Tinebase_Core::getLocale();
501         $symbols = Zend_Locale::getTranslationList('symbols', $locale);
502         $this->assertEquals($symbols['decimal'], $registryData['Tinebase']['decimalSeparator']);
503
504         if (Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE)) {
505             $configuredSalesModels = array_keys($registryData['Sales']['models']);
506             $this->assertTrue(in_array('Invoice', $configuredSalesModels), 'Invoices is missing from configured models: '
507                 . print_r($configuredSalesModels, true));
508         }
509     }
510
511     /**
512      * test get all registry data with persistent filters
513      * 
514      * @return void
515      * 
516      * @see 0009610: shared favorites acl
517      */
518     public function testGetAllPersistentFilters()
519     {
520         $this->markTestSkipped('@see 0010192: fix persistent filter tests');
521         
522         $registryData = $this->_instance->getAllRegistryData();
523         
524         $filterData = $registryData['Tinebase']['persistentFilters'];
525         $this->assertTrue($filterData['totalcount'] > 10);
526         $this->assertTrue(isset($filterData['results'][0]['grants']), 'grants are missing');
527         $grants = $filterData['results'][0]['grants'];
528         $this->assertTrue($grants[0]['readGrant']);
529         
530         // check if accounts are resolved
531         $this->assertTrue(is_array($grants[0]['account_name']), 'account should be resolved: ' . print_r($grants[0], true));
532     }
533     
534     /**
535      * testGetUserProfile
536      */
537     public function testGetUserProfile()
538     {
539         $profile = $this->_instance->getUserProfile(Tinebase_Core::getUser()->getId());
540
541         $this->assertTrue(is_array($profile));
542         $this->assertTrue((isset($profile['userProfile']) || array_key_exists('userProfile', $profile)));
543         $this->assertTrue(is_array($profile['userProfile']));
544         $this->assertTrue((isset($profile['readableFields']) || array_key_exists('readableFields', $profile)));
545         $this->assertTrue(is_array($profile['readableFields']));
546         $this->assertTrue((isset($profile['updateableFields']) || array_key_exists('updateableFields', $profile)));
547         $this->assertTrue(is_array($profile['updateableFields']));
548         
549         // try to get user profile of different user
550         $this->setExpectedException('Tinebase_Exception_AccessDenied');
551         
552         $sclever = Tinebase_Helper::array_value('sclever',Zend_Registry::get('personas'));
553         $this->_instance->getUserProfile($sclever->getId());
554     }
555     
556     /**
557      * testGetUserProfileConfig
558      */
559     public function testGetUserProfileConfig()
560     {
561         $config = $this->_instance->getUserProfileConfig();
562         
563         $this->assertTrue(is_array($config));
564         $this->assertTrue((isset($config['possibleFields']) || array_key_exists('possibleFields', $config)));
565         $this->assertTrue(is_array($config['possibleFields']));
566         $this->assertTrue((isset($config['readableFields']) || array_key_exists('readableFields', $config)));
567         $this->assertTrue(is_array($config['readableFields']));
568         $this->assertTrue((isset($config['updateableFields']) || array_key_exists('updateableFields', $config)));
569         $this->assertTrue(is_array($config['updateableFields']));
570     }
571     
572     /**
573      * testSetUserProfileConfig
574      */
575     public function testSetUserProfileConfig()
576     {
577         $config = $this->_instance->getUserProfileConfig();
578         
579         $idx = array_search('n_prefix', $config['readableFields']);
580         if ($idx !== false) {
581             unset ($config['readableFields'][$idx]);
582         }
583         
584         $idx = array_search('tel_home', $config['updateableFields']);
585         if ($idx !== false) {
586             unset ($config['updateableFields'][$idx]);
587         }
588         
589         $this->_instance->setUserProfileConfig($config);
590     }
591     
592     /**
593      * testupdateUserProfile
594      */
595     public function testUpdateUserProfile()
596     {
597         $profile = $this->_instance->getUserProfile(Tinebase_Core::getUser()->getId());
598         $profileData = $profile['userProfile'];
599         
600         $this->assertFalse(array_search('n_prefix', $profileData));
601         
602         $profileData['tel_home'] = 'mustnotchange';
603         $profileData['email_home'] = 'email@userprofile.set';
604         
605         $this->_instance->updateUserProfile($profileData);
606         
607         $updatedProfile = $this->_instance->getUserProfile(Tinebase_Core::getUser()->getId());
608         $updatedProfileData = $updatedProfile['userProfile'];
609         $this->assertNotEquals('mustnotchange', $updatedProfileData['tel_home']);
610         $this->assertEquals('email@userprofile.set', $updatedProfileData['email_home']);
611     }
612     
613     /**
614      * testGetSaveApplicationConfig
615      */
616     public function testGetSaveApplicationConfig()
617     {
618         $config = $this->_instance->getConfig('Admin');
619         $this->assertGreaterThan(0, count($config));
620         
621         $data = array(
622             'id'        => 'Admin',
623             'settings'  => Admin_Controller::getInstance()->getConfigSettings(),
624         );
625         
626         $newConfig = $this->_instance->saveConfig($data);
627         
628         $this->assertEquals($config, $newConfig);
629     }
630     
631     /**
632      * testChangeUserAccount
633      * 
634      * @see 0009984: allow to change user role
635      */
636     public function testChangeUserAccount()
637     {
638         // allow test user to sign in as sclever
639         Tinebase_Config::getInstance()->set(Tinebase_Config::ROLE_CHANGE_ALLOWED, new Tinebase_Config_Struct(array(
640             Tinebase_Core::getUser()->accountLoginName => array('sclever')
641         )));
642         
643         $sclever = $this->_personas['sclever'];
644         $result = $this->_instance->changeUserAccount('sclever');
645         
646         $this->assertEquals(array('success' => true), $result);
647         
648         // make sure, we are sclever
649         $this->assertEquals('sclever', Tinebase_Core::getUser()->accountLoginName);
650         $this->assertEquals('sclever', Tinebase_Session::getSessionNamespace()->currentAccount->accountLoginName);
651         
652         Tinebase_Controller::getInstance()->initUser($this->_originalTestUser, /* $fixCookieHeader = */ false);
653     }
654     
655     /******************** protected helper funcs ************************/
656     
657     /**
658      * get preference filter
659      *
660      * @param bool $_savedPrefs
661      * @return array
662      */
663     protected function _getPreferenceFilter($_savedPrefs = FALSE, $_adminPrefs = FALSE, $_userId = NULL)
664     {
665         if ($_userId === NULL) {
666             $_userId = Tinebase_Core::getUser()->getId();
667         }
668         
669         $result = array(
670             array(
671                 'field' => 'account',
672                 'operator' => 'equals',
673                 'value' => array(
674                     'accountId'     => ($_adminPrefs) ? 0 : $_userId,
675                     'accountType'   => ($_adminPrefs)
676                         ? Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE
677                         : Tinebase_Acl_Rights::ACCOUNT_TYPE_USER
678                 )
679             )
680         );
681
682         if ($_savedPrefs) {
683             $result[] = array(
684                 'field' => 'name',
685                 'operator' => 'contains',
686                 'value' => 'defaultapp'
687             );
688         }
689         
690         return $result;
691     }
692
693     /**
694      * get preference data for testSavePreferences()
695      *
696      * @return array
697      */
698     protected function _getUserPreferenceData()
699     {
700         return array(
701             'Tinebase' => array(
702                 'timezone' => array('value' => 'Europe/Amsterdam'),
703             )
704         );
705     }
706     
707     /**
708      * get preference with options
709      *
710      * @return Tinebase_Model_Preference
711      */
712     protected function _getPreferenceWithOptions()
713     {
714         return new Tinebase_Model_Preference(array(
715             'application_id'    => Tinebase_Application::getInstance()->getApplicationByName('Tinebase')->getId(),
716             'name'              => 'defaultapp',
717             'value'             => 'value1',
718             'account_id'        => '0',
719             'account_type'      => Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE,
720             'type'              => Tinebase_Model_Preference::TYPE_ADMIN,
721             'options'           => '<?xml version="1.0" encoding="UTF-8"?>
722                 <options>
723                     <option>
724                         <label>option1</label>
725                         <value>value1</value>
726                     </option>
727                     <option>
728                         <label>option2</label>
729                         <value>value2</value>
730                     </option>
731                 </options>'
732         ));
733     }
734 }