Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
232624b1 | 4 | | CiviCRM version 4.4 | |
6a488035 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | ||
31 | /** | |
32 | * Test APIv3 civicrm_setting_* functions | |
33 | * | |
34 | * @package CiviCRM_APIv3 | |
35 | * @subpackage API_Core | |
36 | */ | |
37 | ||
38 | /** | |
39 | * Class contains api test cases for civicrm settings | |
40 | * | |
41 | */ | |
42 | class api_v3_SettingTest extends CiviUnitTestCase { | |
43 | ||
44 | protected $_apiversion = 3; | |
45 | protected $_contactID; | |
46 | protected $_params; | |
47 | protected $_currentDomain; | |
48 | protected $_domainID2; | |
49 | protected $_domainID3; | |
50 | public $_eNoticeCompliant = TRUE; | |
51 | function __construct() { | |
52 | parent::__construct(); | |
53 | ||
54 | } | |
55 | ||
56 | function get_info() { | |
57 | return array( | |
58 | 'name' => 'Settings Tests', | |
59 | 'description' => 'Settings API', | |
60 | 'group' => 'CiviCRM API Tests', | |
61 | ); | |
62 | } | |
63 | ||
64 | function setUp() { | |
65 | parent::setUp(); | |
66 | $params = array( | |
67 | 'name' => 'Default Domain Name', | |
7fbb4198 | 68 | ); |
69 | $result = $this->callAPISuccess( 'domain','get',$params); | |
6a488035 | 70 | if(empty($result['id'])){ |
7fbb4198 | 71 | $result = $this->callAPISuccess( 'domain','create',$params ); |
6a488035 TO |
72 | } |
73 | ||
74 | $params['name'] = 'Second Domain'; | |
7fbb4198 | 75 | $result = $this->callAPISuccess( 'domain','get',$params); |
6a488035 | 76 | if(empty($result['id'])){ |
7fbb4198 | 77 | $result = $this->callAPISuccess( 'domain','create',$params ); |
6a488035 TO |
78 | } |
79 | $this->_domainID2 = $result['id']; | |
80 | $params['name'] = 'A-team domain'; | |
7fbb4198 | 81 | $result = $this->callAPISuccess( 'domain','get',$params); |
6a488035 | 82 | if(empty($result['id'])){ |
7fbb4198 | 83 | $result = $this->callAPISuccess( 'domain','create',$params ); |
6a488035 TO |
84 | } |
85 | $this->_domainID3 = $result['id']; | |
86 | $this->_currentDomain = CRM_Core_Config::domainID(); | |
87 | } | |
88 | ||
89 | function tearDown() { | |
90 | parent::tearDown(); | |
7fbb4198 | 91 | $this->callAPISuccess('system','flush', array()); |
6a488035 | 92 | $this->quickCleanup(array('civicrm_domain')); |
6a488035 TO |
93 | } |
94 | ||
95 | /** | |
96 | * check getfields works | |
97 | */ | |
98 | function testGetFields() { | |
6a488035 | 99 | $description = 'Demonstrate return from getfields - see subfolder for variants'; |
7fbb4198 | 100 | $result = $this->callAPIAndDocument('setting', 'getfields', array(), __FUNCTION__, __FILE__, $description); |
6a488035 TO |
101 | $this->assertArrayHasKey('customCSSURL', $result['values']); |
102 | ||
103 | $description = 'Demonstrate return from getfields'; | |
7fbb4198 | 104 | $result = $this->callAPISuccess('setting', 'getfields', array()); |
6a488035 | 105 | $this->assertArrayHasKey('customCSSURL', $result['values']); |
7fbb4198 | 106 | $this->callAPISuccess('system','flush', array()); |
6a488035 TO |
107 | } |
108 | ||
109 | /** | |
110 | * let's check it's loading from cache by meddling with the cache | |
111 | */ | |
112 | function testGetFieldsCaching() { | |
113 | $settingsMetadata = array(); | |
114 | CRM_Core_BAO_Cache::setItem($settingsMetadata,'CiviCRM setting Specs', 'settingsMetadata__'); | |
115 | CRM_Core_BAO_Cache::setItem($settingsMetadata,'CiviCRM setting Spec', 'All'); | |
7fbb4198 | 116 | $result = $this->callAPISuccess('setting', 'getfields', array()); |
6a488035 TO |
117 | $this->assertArrayNotHasKey('customCSSURL', $result['values']); |
118 | $this->quickCleanup(array('civicrm_cache')); | |
119 | } | |
120 | ||
121 | function testGetFieldsFilters() { | |
7fbb4198 | 122 | $params = array('name' => 'advanced_search_options'); |
123 | $result = $this->callAPISuccess('setting', 'getfields', $params); | |
6a488035 TO |
124 | $this->assertArrayNotHasKey('customCSSURL', $result['values']); |
125 | $this->assertArrayHasKey('advanced_search_options',$result['values']); | |
126 | } | |
076d8c82 TO |
127 | |
128 | /** | |
129 | * Ensure that on_change callbacks fire. | |
130 | * | |
131 | * Note: api_v3_SettingTest::testOnChange and CRM_Core_BAO_SettingTest::testOnChange | |
132 | * are very similar, but they exercise different codepaths. The first uses the API | |
133 | * and setItems [plural]; the second uses setItem [singular]. | |
134 | */ | |
135 | function testOnChange() { | |
136 | global $_testOnChange_hookCalls; | |
137 | $this->setMockSettingsMetaData(array( | |
138 | 'onChangeExample' => array( | |
139 | 'group_name' => 'CiviCRM Preferences', | |
140 | 'group' => 'core', | |
141 | 'name' => 'onChangeExample', | |
142 | 'type' => 'Array', | |
143 | 'quick_form_type' => 'Element', | |
144 | 'html_type' => 'advmultiselect', | |
145 | 'default' => array('CiviEvent', 'CiviContribute'), | |
146 | 'add' => '4.4', | |
147 | 'title' => 'List of Components', | |
148 | 'is_domain' => '1', | |
149 | 'is_contact' => 0, | |
150 | 'description' => NULL, | |
151 | 'help_text' => NULL, | |
152 | 'on_change' => array( // list of callbacks | |
153 | array(__CLASS__, '_testOnChange_onChangeExample') | |
154 | ), | |
155 | ), | |
156 | )); | |
157 | ||
158 | // set initial value | |
159 | $_testOnChange_hookCalls = array('count' => 0); | |
160 | $this->callAPISuccess('setting', 'create', array( | |
161 | 'onChangeExample' => array('First', 'Value'), | |
162 | )); | |
163 | $this->assertEquals(1, $_testOnChange_hookCalls['count']); | |
164 | $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['newValue']); | |
165 | $this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']); | |
166 | ||
167 | // change value | |
168 | $_testOnChange_hookCalls = array('count' => 0); | |
169 | $this->callAPISuccess('setting', 'create', array( | |
170 | 'onChangeExample' => array('Second', 'Value'), | |
171 | )); | |
172 | $this->assertEquals(1, $_testOnChange_hookCalls['count']); | |
173 | $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['oldValue']); | |
174 | $this->assertEquals(array('Second', 'Value'), $_testOnChange_hookCalls['newValue']); | |
175 | $this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']); | |
176 | } | |
177 | ||
178 | /** | |
179 | * Mock callback for a setting's on_change handler | |
180 | * | |
181 | * @param $oldValue | |
182 | * @param $newValue | |
183 | * @param $metadata | |
184 | */ | |
185 | static function _testOnChange_onChangeExample($oldValue, $newValue, $metadata) { | |
186 | global $_testOnChange_hookCalls; | |
187 | $_testOnChange_hookCalls['count']++; | |
188 | $_testOnChange_hookCalls['oldValue'] = $oldValue; | |
189 | $_testOnChange_hookCalls['newValue'] = $newValue; | |
190 | $_testOnChange_hookCalls['metadata'] = $metadata; | |
191 | } | |
192 | ||
6a488035 TO |
193 | /** |
194 | * check getfields works | |
195 | */ | |
196 | function testCreateSetting() { | |
7fbb4198 | 197 | $description = "shows setting a variable for a given domain - if no domain is set current is assumed"; |
6a488035 | 198 | |
7fbb4198 | 199 | $params = array( |
6a488035 TO |
200 | 'domain_id' => $this->_domainID2, |
201 | 'uniq_email_per_site' => 1, | |
202 | ); | |
7fbb4198 | 203 | $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 | 204 | |
7fbb4198 | 205 | $params = array('uniq_email_per_site' => 1,); |
6a488035 | 206 | $description = "shows setting a variable for a current domain"; |
7fbb4198 | 207 | $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateSettingCurrentDomain'); |
6a488035 TO |
208 | $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); |
209 | } | |
210 | ||
211 | /** | |
212 | * check getfields works | |
213 | */ | |
214 | function testCreateInvalidSettings() { | |
215 | ||
7fbb4198 | 216 | $params = array( |
6a488035 TO |
217 | 'domain_id' => $this->_domainID2, |
218 | 'invalid_key' => 1, | |
219 | ); | |
d0e1eff2 | 220 | $result = $this->callAPIFailure('setting', 'create', $params); |
6a488035 TO |
221 | } |
222 | ||
223 | /** | |
224 | * check invalid settings rejected - | |
225 | */ | |
226 | ||
227 | function testCreateInvalidURLSettings() { | |
228 | ||
7fbb4198 | 229 | $params = array( |
6a488035 TO |
230 | 'domain_id' => $this->_domainID2, |
231 | 'userFrameworkResourceURL' => 'dfhkdhfd', | |
232 | ); | |
d0e1eff2 | 233 | $result = $this->callAPIFailure('setting', 'create', $params); |
7fbb4198 | 234 | $params = array( |
6a488035 TO |
235 | 'domain_id' => $this->_domainID2, |
236 | 'userFrameworkResourceURL' => 'http://blah.com', | |
237 | ); | |
7fbb4198 | 238 | $result = $this->callAPISuccess('setting', 'create', $params); |
6a488035 TO |
239 | } |
240 | ||
241 | /** | |
242 | * check getfields works | |
243 | */ | |
244 | function testCreateInvalidBooleanSettings() { | |
245 | ||
7fbb4198 | 246 | $params = array( |
6a488035 TO |
247 | 'domain_id' => $this->_domainID2, |
248 | 'track_civimail_replies' => 'dfhkdhfd', | |
249 | ); | |
d0e1eff2 | 250 | $result = $this->callAPIFailure('setting', 'create', $params); |
6a488035 | 251 | |
7fbb4198 | 252 | $params = array('track_civimail_replies' => '0',); |
253 | $result = $this->callAPISuccess('setting', 'create', $params); | |
254 | $getResult = $this->callAPISuccess('setting','get',$params); | |
6a488035 TO |
255 | $this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']); |
256 | ||
7fbb4198 | 257 | $getResult = $this->callAPISuccess('setting','get',$params); |
6a488035 | 258 | $this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']); |
7fbb4198 | 259 | $params = array( 'domain_id' => $this->_domainID2, |
6a488035 TO |
260 | 'track_civimail_replies' => '1', |
261 | ); | |
7fbb4198 | 262 | $result = $this->callAPISuccess('setting', 'create', $params); |
263 | $getResult = $this->callAPISuccess('setting','get',$params); | |
6a488035 TO |
264 | $this->assertEquals(1, $getResult['values'][$this->_domainID2]['track_civimail_replies']); |
265 | ||
7fbb4198 | 266 | $params = array( |
6a488035 TO |
267 | 'domain_id' => $this->_domainID2, |
268 | 'track_civimail_replies' => 'TRUE', | |
269 | ); | |
7fbb4198 | 270 | $result = $this->callAPISuccess('setting', 'create', $params); |
271 | $getResult = $this->callAPISuccess('setting','get',$params); | |
6a488035 TO |
272 | |
273 | $this->assertEquals(1, $getResult['values'][$this->_domainID2]['track_civimail_replies'], "check TRUE is converted to 1"); | |
274 | ||
275 | ||
276 | } | |
277 | ||
278 | /** | |
279 | * check getfields works | |
280 | */ | |
281 | function testCreateSettingMultipleDomains() { | |
7fbb4198 | 282 | $description = "shows setting a variable for all domains"; |
6a488035 | 283 | |
7fbb4198 | 284 | $params = array( |
6a488035 TO |
285 | 'domain_id' => 'all', |
286 | 'uniq_email_per_site' => 1, | |
6a488035 | 287 | ); |
7fbb4198 | 288 | $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__,$description, 'CreateAllDomains'); |
289 | ||
6a488035 TO |
290 | $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); |
291 | $this->assertEquals(1, $result['values'][1]['uniq_email_per_site']); | |
292 | $this->assertArrayHasKey(3, $result['values'], 'Domain create probably failed Debug this IF domain test is passing'); | |
293 | $this->assertEquals(1, $result['values'][3]['uniq_email_per_site'], 'failed to set setting for domain 3.'); | |
294 | ||
7fbb4198 | 295 | $params = array( |
6a488035 TO |
296 | 'domain_id' => 'all', |
297 | 'return' => 'uniq_email_per_site' | |
298 | ); | |
299 | // we'll check it with a 'get' | |
6a488035 | 300 | $description = "shows getting a variable for all domains"; |
7fbb4198 | 301 | $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__,$description, 'GetAllDomains', 'Get'); |
302 | ||
6a488035 TO |
303 | $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); |
304 | $this->assertEquals(1, $result['values'][1]['uniq_email_per_site']); | |
305 | $this->assertEquals(1, $result['values'][3]['uniq_email_per_site']); | |
306 | ||
7fbb4198 | 307 | $params = array( |
6a488035 TO |
308 | 'domain_id' => array(1,3), |
309 | 'uniq_email_per_site' => 0, | |
310 | ); | |
6a488035 | 311 | $description = "shows setting a variable for specified domains"; |
7fbb4198 | 312 | $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__,$description, 'CreateSpecifiedDomains'); |
313 | ||
6a488035 TO |
314 | $this->assertEquals(0, $result['values'][3]['uniq_email_per_site']); |
315 | $this->assertEquals(0, $result['values'][1]['uniq_email_per_site']); | |
7fbb4198 | 316 | $params = array( |
6a488035 TO |
317 | 'domain_id' => array(1,2), |
318 | 'return' => array('uniq_email_per_site'), | |
319 | ); | |
6a488035 | 320 | $description = "shows getting a variable for specified domains"; |
7fbb4198 | 321 | $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__,$description, 'GetSpecifiedDomains', 'Get'); |
6a488035 TO |
322 | $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); |
323 | $this->assertEquals(0, $result['values'][1]['uniq_email_per_site']); | |
324 | ||
325 | } | |
326 | ||
327 | function testGetSetting() { | |
328 | ||
7fbb4198 | 329 | $params = array( |
330 | 'domain_id' => $this->_domainID2, | |
331 | 'return' => 'uniq_email_per_site', | |
6a488035 | 332 | ); |
6a488035 | 333 | $description = "shows get setting a variable for a given domain - if no domain is set current is assumed"; |
7fbb4198 | 334 | |
335 | $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__); | |
6a488035 TO |
336 | |
337 | $params = array( | |
6a488035 TO |
338 | 'return' => 'uniq_email_per_site', |
339 | ); | |
6a488035 | 340 | $description = "shows getting a variable for a current domain"; |
7fbb4198 | 341 | $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__, $description, 'GetSettingCurrentDomain'); |
6a488035 TO |
342 | $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); |
343 | } | |
344 | /** | |
345 | * setting api should set & fetch settings stored in config as well as those in settings table | |
346 | */ | |
347 | function testSetConfigSetting() { | |
348 | $config = CRM_Core_Config::singleton(); | |
349 | $this->assertFalse($config->debug == 1); | |
7fbb4198 | 350 | $params = array( |
6a488035 TO |
351 | 'domain_id' => $this->_domainID2, |
352 | 'debug_enabled' => 1, | |
353 | ); | |
7fbb4198 | 354 | $result = $this->callAPISuccess('setting', 'create', $params); |
5b887f26 | 355 | CRM_Core_BAO_Domain::setDomain($this->_domainID2); |
356 | $config = CRM_Core_Config::singleton(TRUE, TRUE); | |
357 | CRM_Core_BAO_Domain::resetDomain(); | |
6a488035 TO |
358 | $this->assertTrue($config->debug == 1); |
359 | // this should NOT be stored in the settings table now - only in config | |
360 | $sql = " SELECT count(*) as c FROM civicrm_setting WHERE name LIKE '%debug%'"; | |
361 | $dao = CRM_Core_DAO::executeQuery($sql); | |
362 | $dao->fetch(); | |
363 | $this->assertEquals($dao->c, 0); | |
364 | } | |
365 | /** | |
366 | * setting api should set & fetch settings stored in config as well as those in settings table | |
367 | */ | |
368 | function testGetConfigSetting() { | |
7fbb4198 | 369 | $settings = $this->callAPISuccess('setting', 'get', array( |
370 | 'name' => 'defaultCurrency', 'sequential' => 1,) | |
6a488035 | 371 | ); |
6a488035 TO |
372 | $this->assertEquals('USD', $settings['values'][0]['defaultCurrency']); |
373 | } | |
2ba45310 | 374 | |
375 | /** | |
376 | * setting api should set & fetch settings stored in config as well as those in settings table | |
377 | */ | |
378 | function testGetSetConfigSettingMultipleDomains() { | |
7fbb4198 | 379 | $settings = $this->callAPISuccess('setting', 'create', array( |
380 | 'defaultCurrency' => 'USD', 'domain_id' => $this->_currentDomain) | |
2ba45310 | 381 | ); |
7fbb4198 | 382 | $settings = $this->callAPISuccess('setting', 'create', array( |
383 | 'defaultCurrency' => 'CAD', 'domain_id' => $this->_domainID2) | |
2ba45310 | 384 | ); |
7fbb4198 | 385 | $settings = $this->callAPISuccess('setting', 'get', array( |
386 | 'return' => 'defaultCurrency', 'domain_id' => 'all', | |
2ba45310 | 387 | ) |
388 | ); | |
389 | $this->assertEquals('USD', $settings['values'][$this->_currentDomain]['defaultCurrency']); | |
390 | $this->assertEquals('CAD', $settings['values'][$this->_domainID2]['defaultCurrency'], | |
391 | "second domain (id {$this->_domainID2} ) should be set to CAD. First dom was {$this->_currentDomain} & was USD"); | |
392 | ||
393 | } | |
394 | ||
6a488035 TO |
395 | /* |
396 | * Use getValue against a config setting | |
397 | */ | |
398 | function testGetValueConfigSetting() { | |
7fbb4198 | 399 | $params = array( 'name' => 'monetaryThousandSeparator', |
6a488035 TO |
400 | 'group' => 'Localization Setting', |
401 | ); | |
7fbb4198 | 402 | $result = $this->callAPISuccess('setting', 'getvalue', $params); |
6a488035 TO |
403 | $this->assertEquals(',', $result); |
404 | } | |
405 | ||
406 | function testGetValue() { | |
7fbb4198 | 407 | $params = array( 'name' => 'petition_contacts', |
6a488035 TO |
408 | 'group' => 'Campaign Preferences' |
409 | ); | |
6a488035 | 410 | $description = "Demonstrates getvalue action - intended for runtime use as better caching than get"; |
7fbb4198 | 411 | |
412 | $result = $this->callAPIAndDocument('setting', 'getvalue', $params, __FUNCTION__, __FILE__, $description); | |
413 | $this->assertEquals('Petition Contacts', $result); | |
6a488035 TO |
414 | } |
415 | ||
416 | function testGetDefaults() { | |
7fbb4198 | 417 | $description = "gets defaults setting a variable for a given domain - if no domain is set current is assumed"; |
6a488035 | 418 | |
7fbb4198 | 419 | $params = array( |
6a488035 TO |
420 | 'name' => 'address_format', |
421 | ); | |
7fbb4198 | 422 | $result = $this->callAPIAndDocument('setting', 'getdefaults', $params, __FUNCTION__, __FILE__,$description,'GetDefaults','getdefaults'); |
6a488035 | 423 | $this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']); |
7fbb4198 | 424 | $params = array('name' => 'mailing_format',); |
425 | $result = $this->callAPISuccess('setting', 'getdefaults', $params); | |
6a488035 TO |
426 | $this->assertEquals("{contact.addressee}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['mailing_format']); |
427 | $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); | |
428 | } | |
429 | /* | |
430 | * Function tests reverting a specific parameter | |
431 | */ | |
432 | function testRevert() { | |
433 | ||
7fbb4198 | 434 | $params = array( 'address_format' => 'xyz', |
6a488035 TO |
435 | 'mailing_format' => 'bcs', |
436 | ); | |
7fbb4198 | 437 | $result = $this->callAPISuccess('setting', 'create', $params); |
6a488035 | 438 | $this->assertAPISuccess($result, "in line " . __LINE__); |
7fbb4198 | 439 | $revertParams = array( 'name' => 'address_format' |
6a488035 | 440 | ); |
7fbb4198 | 441 | $result = $this->callAPISuccess('setting', 'get', $params); |
6a488035 TO |
442 | //make sure it's set |
443 | $this->assertEquals('xyz', $result['values'][CRM_Core_Config::domainID()]['address_format']); | |
444 | $description = "Demonstrates reverting a parameter to default value"; | |
7fbb4198 | 445 | $result = $this->callAPIAndDocument('setting', 'revert', $revertParams, __FUNCTION__, __FILE__,$description,'','revert'); |
6a488035 | 446 | //make sure it's reverted |
7fbb4198 | 447 | $result = $this->callAPISuccess('setting', 'get', $params); |
6a488035 | 448 | $this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']); |
7fbb4198 | 449 | $params = array( 'return' => array('mailing_format'), |
6a488035 | 450 | ); |
7fbb4198 | 451 | $result = $this->callAPISuccess('setting', 'get', $params); |
6a488035 TO |
452 | //make sure it's unchanged |
453 | $this->assertEquals('bcs', $result['values'][CRM_Core_Config::domainID()]['mailing_format']); | |
454 | } | |
455 | /* | |
456 | * Tests reverting ALL parameters (specific domain) | |
457 | */ | |
458 | function testRevertAll() { | |
459 | ||
7fbb4198 | 460 | $params = array( 'address_format' => 'xyz', |
6a488035 TO |
461 | 'mailing_format' => 'bcs', |
462 | ); | |
7fbb4198 | 463 | $result = $this->callAPISuccess('setting', 'create', $params); |
464 | $revertParams = array( ); | |
465 | $result = $this->callAPISuccess('setting', 'get', $params); | |
6a488035 TO |
466 | //make sure it's set |
467 | $this->assertEquals('xyz', $result['values'][CRM_Core_Config::domainID()]['address_format']); | |
468 | ||
7fbb4198 | 469 | $this->callAPISuccess('setting', 'revert', $revertParams); |
6a488035 | 470 | //make sure it's reverted |
7fbb4198 | 471 | $result = $this->callAPISuccess('setting', 'get', array('group' => 'core')); |
6a488035 TO |
472 | $this->assertEquals("{contact.address_name}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['address_format']); |
473 | $this->assertEquals("{contact.addressee}\n{contact.street_address}\n{contact.supplemental_address_1}\n{contact.supplemental_address_2}\n{contact.city}{, }{contact.state_province}{ }{contact.postal_code}\n{contact.country}", $result['values'][CRM_Core_Config::domainID()]['mailing_format']); | |
474 | } | |
475 | ||
476 | /* | |
477 | * Tests filling missing params | |
478 | */ | |
479 | function testFill() { | |
480 | $domparams = array( | |
481 | 'name' => 'B Team Domain', | |
7fbb4198 | 482 | ); |
483 | $dom = $this->callAPISuccess('domain', 'create', $domparams); | |
484 | $params = array( 'domain_id' => 'all', | |
6a488035 | 485 | ); |
7fbb4198 | 486 | $result = $this->callAPISuccess('setting', 'get', $params); |
487 | $params = array( 'address_format' => 'xyz', | |
6a488035 TO |
488 | 'mailing_format' => 'bcs', |
489 | 'domain_id' => $this->_domainID2, | |
490 | ); | |
7fbb4198 | 491 | $result = $this->callAPISuccess('setting', 'create', $params); |
492 | $params = array( 'domain_id' => $dom['id'], | |
6a488035 | 493 | ); |
7fbb4198 | 494 | $result = $this->callAPISuccess('setting', 'get', $params); |
6a488035 TO |
495 | $this->assertAPISuccess($result, "in line " . __LINE__); |
496 | $this->assertArrayNotHasKey('tag_unconfirmed', $result['values'][$dom['id']],'setting for domain 3 should not be set. Debug this IF domain test is passing'); | |
7fbb4198 | 497 | $result = $this->callAPISuccess('setting', 'fill', $params); |
6a488035 | 498 | $this->assertAPISuccess($result, "in line " . __LINE__); |
7fbb4198 | 499 | $result = $this->callAPISuccess('setting', 'get', $params); |
6a488035 TO |
500 | $this->assertAPISuccess($result, "in line " . __LINE__); |
501 | $this->assertArrayHasKey('tag_unconfirmed', $result['values'][$dom['id']]); | |
f64cd471 | 502 | $this->assertArrayHasKey('extensionsDir', $result['values'][$dom['id']]); |
6a488035 TO |
503 | $this->assertEquals('Unconfirmed', $result['values'][$dom['id']]['tag_unconfirmed']); |
504 | } | |
505 | } | |
506 |