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; | |
b7c9bc4c | 50 | |
6a488035 TO |
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(); | |
ee7b49c4 | 87 | $this->hookClass = CRM_Utils_Hook::singleton(); |
6a488035 TO |
88 | } |
89 | ||
90 | function tearDown() { | |
ee7b49c4 | 91 | CRM_Utils_Hook::singleton()->reset(); |
6a488035 | 92 | parent::tearDown(); |
7fbb4198 | 93 | $this->callAPISuccess('system','flush', array()); |
6a488035 | 94 | $this->quickCleanup(array('civicrm_domain')); |
6a488035 TO |
95 | } |
96 | ||
ee7b49c4 E |
97 | /** |
98 | * Set additional settings into metadata (implements hook) | |
99 | * @param array $metaDataFolders | |
100 | */ | |
101 | function setExtensionMetadata(&$metaDataFolders) { | |
102 | global $civicrm_root; | |
103 | $metaDataFolders[] = $civicrm_root . '/tests/phpunit/api/v3/settings'; | |
104 | } | |
105 | /** | |
6a488035 TO |
106 | /** |
107 | * check getfields works | |
108 | */ | |
109 | function testGetFields() { | |
6a488035 | 110 | $description = 'Demonstrate return from getfields - see subfolder for variants'; |
7fbb4198 | 111 | $result = $this->callAPIAndDocument('setting', 'getfields', array(), __FUNCTION__, __FILE__, $description); |
6a488035 TO |
112 | $this->assertArrayHasKey('customCSSURL', $result['values']); |
113 | ||
114 | $description = 'Demonstrate return from getfields'; | |
7fbb4198 | 115 | $result = $this->callAPISuccess('setting', 'getfields', array()); |
6a488035 | 116 | $this->assertArrayHasKey('customCSSURL', $result['values']); |
7fbb4198 | 117 | $this->callAPISuccess('system','flush', array()); |
6a488035 TO |
118 | } |
119 | ||
120 | /** | |
121 | * let's check it's loading from cache by meddling with the cache | |
122 | */ | |
123 | function testGetFieldsCaching() { | |
124 | $settingsMetadata = array(); | |
125 | CRM_Core_BAO_Cache::setItem($settingsMetadata,'CiviCRM setting Specs', 'settingsMetadata__'); | |
126 | CRM_Core_BAO_Cache::setItem($settingsMetadata,'CiviCRM setting Spec', 'All'); | |
7fbb4198 | 127 | $result = $this->callAPISuccess('setting', 'getfields', array()); |
6a488035 TO |
128 | $this->assertArrayNotHasKey('customCSSURL', $result['values']); |
129 | $this->quickCleanup(array('civicrm_cache')); | |
130 | } | |
131 | ||
132 | function testGetFieldsFilters() { | |
7fbb4198 | 133 | $params = array('name' => 'advanced_search_options'); |
134 | $result = $this->callAPISuccess('setting', 'getfields', $params); | |
6a488035 TO |
135 | $this->assertArrayNotHasKey('customCSSURL', $result['values']); |
136 | $this->assertArrayHasKey('advanced_search_options',$result['values']); | |
4ed37178 E |
137 | } |
138 | ||
139 | /** | |
140 | * Test that getfields will filter on group | |
141 | */ | |
142 | function testGetFieldsGroupFilters() { | |
143 | $params = array('filters' => array('group' => 'multisite')); | |
144 | $result = $this->callAPISuccess('setting', 'getfields', $params); | |
145 | $this->assertArrayNotHasKey('customCSSURL', $result['values']); | |
146 | $this->assertArrayHasKey('domain_group_id',$result['values']); | |
147 | } | |
148 | ||
149 | /** | |
150 | * Test that getfields will filter on another field (prefetch) | |
151 | */ | |
152 | function testGetFieldsPrefetchFilters() { | |
153 | $params = array('filters' => array('prefetch' => 1)); | |
154 | $result = $this->callAPISuccess('setting', 'getfields', $params); | |
155 | $this->assertArrayNotHasKey('disable_mandatory_tokens_check', $result['values']); | |
156 | $this->assertArrayHasKey('monetaryDecimalPoint',$result['values']); | |
6a488035 | 157 | } |
076d8c82 TO |
158 | |
159 | /** | |
160 | * Ensure that on_change callbacks fire. | |
161 | * | |
162 | * Note: api_v3_SettingTest::testOnChange and CRM_Core_BAO_SettingTest::testOnChange | |
163 | * are very similar, but they exercise different codepaths. The first uses the API | |
164 | * and setItems [plural]; the second uses setItem [singular]. | |
165 | */ | |
166 | function testOnChange() { | |
167 | global $_testOnChange_hookCalls; | |
168 | $this->setMockSettingsMetaData(array( | |
169 | 'onChangeExample' => array( | |
170 | 'group_name' => 'CiviCRM Preferences', | |
171 | 'group' => 'core', | |
172 | 'name' => 'onChangeExample', | |
173 | 'type' => 'Array', | |
174 | 'quick_form_type' => 'Element', | |
175 | 'html_type' => 'advmultiselect', | |
176 | 'default' => array('CiviEvent', 'CiviContribute'), | |
177 | 'add' => '4.4', | |
178 | 'title' => 'List of Components', | |
179 | 'is_domain' => '1', | |
180 | 'is_contact' => 0, | |
181 | 'description' => NULL, | |
182 | 'help_text' => NULL, | |
183 | 'on_change' => array( // list of callbacks | |
184 | array(__CLASS__, '_testOnChange_onChangeExample') | |
185 | ), | |
186 | ), | |
187 | )); | |
188 | ||
189 | // set initial value | |
190 | $_testOnChange_hookCalls = array('count' => 0); | |
191 | $this->callAPISuccess('setting', 'create', array( | |
192 | 'onChangeExample' => array('First', 'Value'), | |
193 | )); | |
194 | $this->assertEquals(1, $_testOnChange_hookCalls['count']); | |
195 | $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['newValue']); | |
196 | $this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']); | |
197 | ||
198 | // change value | |
199 | $_testOnChange_hookCalls = array('count' => 0); | |
200 | $this->callAPISuccess('setting', 'create', array( | |
201 | 'onChangeExample' => array('Second', 'Value'), | |
202 | )); | |
203 | $this->assertEquals(1, $_testOnChange_hookCalls['count']); | |
204 | $this->assertEquals(array('First', 'Value'), $_testOnChange_hookCalls['oldValue']); | |
205 | $this->assertEquals(array('Second', 'Value'), $_testOnChange_hookCalls['newValue']); | |
206 | $this->assertEquals('List of Components', $_testOnChange_hookCalls['metadata']['title']); | |
207 | } | |
208 | ||
209 | /** | |
210 | * Mock callback for a setting's on_change handler | |
211 | * | |
212 | * @param $oldValue | |
213 | * @param $newValue | |
214 | * @param $metadata | |
215 | */ | |
216 | static function _testOnChange_onChangeExample($oldValue, $newValue, $metadata) { | |
217 | global $_testOnChange_hookCalls; | |
218 | $_testOnChange_hookCalls['count']++; | |
219 | $_testOnChange_hookCalls['oldValue'] = $oldValue; | |
220 | $_testOnChange_hookCalls['newValue'] = $newValue; | |
221 | $_testOnChange_hookCalls['metadata'] = $metadata; | |
222 | } | |
223 | ||
6a488035 TO |
224 | /** |
225 | * check getfields works | |
226 | */ | |
227 | function testCreateSetting() { | |
7fbb4198 | 228 | $description = "shows setting a variable for a given domain - if no domain is set current is assumed"; |
6a488035 | 229 | |
7fbb4198 | 230 | $params = array( |
6a488035 TO |
231 | 'domain_id' => $this->_domainID2, |
232 | 'uniq_email_per_site' => 1, | |
233 | ); | |
7fbb4198 | 234 | $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__); |
6a488035 | 235 | |
7fbb4198 | 236 | $params = array('uniq_email_per_site' => 1,); |
6a488035 | 237 | $description = "shows setting a variable for a current domain"; |
7fbb4198 | 238 | $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateSettingCurrentDomain'); |
6a488035 TO |
239 | $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); |
240 | } | |
241 | ||
242 | /** | |
243 | * check getfields works | |
244 | */ | |
245 | function testCreateInvalidSettings() { | |
246 | ||
7fbb4198 | 247 | $params = array( |
6a488035 TO |
248 | 'domain_id' => $this->_domainID2, |
249 | 'invalid_key' => 1, | |
250 | ); | |
d0e1eff2 | 251 | $result = $this->callAPIFailure('setting', 'create', $params); |
6a488035 TO |
252 | } |
253 | ||
254 | /** | |
255 | * check invalid settings rejected - | |
256 | */ | |
257 | ||
258 | function testCreateInvalidURLSettings() { | |
259 | ||
7fbb4198 | 260 | $params = array( |
6a488035 TO |
261 | 'domain_id' => $this->_domainID2, |
262 | 'userFrameworkResourceURL' => 'dfhkdhfd', | |
263 | ); | |
d0e1eff2 | 264 | $result = $this->callAPIFailure('setting', 'create', $params); |
7fbb4198 | 265 | $params = array( |
6a488035 TO |
266 | 'domain_id' => $this->_domainID2, |
267 | 'userFrameworkResourceURL' => 'http://blah.com', | |
268 | ); | |
7fbb4198 | 269 | $result = $this->callAPISuccess('setting', 'create', $params); |
6a488035 TO |
270 | } |
271 | ||
272 | /** | |
273 | * check getfields works | |
274 | */ | |
275 | function testCreateInvalidBooleanSettings() { | |
276 | ||
7fbb4198 | 277 | $params = array( |
6a488035 TO |
278 | 'domain_id' => $this->_domainID2, |
279 | 'track_civimail_replies' => 'dfhkdhfd', | |
280 | ); | |
d0e1eff2 | 281 | $result = $this->callAPIFailure('setting', 'create', $params); |
6a488035 | 282 | |
7fbb4198 | 283 | $params = array('track_civimail_replies' => '0',); |
284 | $result = $this->callAPISuccess('setting', 'create', $params); | |
285 | $getResult = $this->callAPISuccess('setting','get',$params); | |
6a488035 TO |
286 | $this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']); |
287 | ||
7fbb4198 | 288 | $getResult = $this->callAPISuccess('setting','get',$params); |
6a488035 | 289 | $this->assertEquals(0, $getResult['values'][$this->_currentDomain]['track_civimail_replies']); |
7fbb4198 | 290 | $params = array( 'domain_id' => $this->_domainID2, |
6a488035 TO |
291 | 'track_civimail_replies' => '1', |
292 | ); | |
7fbb4198 | 293 | $result = $this->callAPISuccess('setting', 'create', $params); |
294 | $getResult = $this->callAPISuccess('setting','get',$params); | |
6a488035 TO |
295 | $this->assertEquals(1, $getResult['values'][$this->_domainID2]['track_civimail_replies']); |
296 | ||
7fbb4198 | 297 | $params = array( |
6a488035 TO |
298 | 'domain_id' => $this->_domainID2, |
299 | 'track_civimail_replies' => 'TRUE', | |
300 | ); | |
7fbb4198 | 301 | $result = $this->callAPISuccess('setting', 'create', $params); |
302 | $getResult = $this->callAPISuccess('setting','get',$params); | |
6a488035 TO |
303 | |
304 | $this->assertEquals(1, $getResult['values'][$this->_domainID2]['track_civimail_replies'], "check TRUE is converted to 1"); | |
305 | ||
306 | ||
307 | } | |
308 | ||
309 | /** | |
310 | * check getfields works | |
311 | */ | |
312 | function testCreateSettingMultipleDomains() { | |
7fbb4198 | 313 | $description = "shows setting a variable for all domains"; |
6a488035 | 314 | |
7fbb4198 | 315 | $params = array( |
6a488035 TO |
316 | 'domain_id' => 'all', |
317 | 'uniq_email_per_site' => 1, | |
6a488035 | 318 | ); |
7fbb4198 | 319 | $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__,$description, 'CreateAllDomains'); |
320 | ||
6a488035 TO |
321 | $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); |
322 | $this->assertEquals(1, $result['values'][1]['uniq_email_per_site']); | |
323 | $this->assertArrayHasKey(3, $result['values'], 'Domain create probably failed Debug this IF domain test is passing'); | |
324 | $this->assertEquals(1, $result['values'][3]['uniq_email_per_site'], 'failed to set setting for domain 3.'); | |
325 | ||
7fbb4198 | 326 | $params = array( |
6a488035 TO |
327 | 'domain_id' => 'all', |
328 | 'return' => 'uniq_email_per_site' | |
329 | ); | |
330 | // we'll check it with a 'get' | |
6a488035 | 331 | $description = "shows getting a variable for all domains"; |
7fbb4198 | 332 | $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__,$description, 'GetAllDomains', 'Get'); |
333 | ||
6a488035 TO |
334 | $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); |
335 | $this->assertEquals(1, $result['values'][1]['uniq_email_per_site']); | |
336 | $this->assertEquals(1, $result['values'][3]['uniq_email_per_site']); | |
337 | ||
7fbb4198 | 338 | $params = array( |
6a488035 TO |
339 | 'domain_id' => array(1,3), |
340 | 'uniq_email_per_site' => 0, | |
341 | ); | |
6a488035 | 342 | $description = "shows setting a variable for specified domains"; |
7fbb4198 | 343 | $result = $this->callAPIAndDocument('setting', 'create', $params, __FUNCTION__, __FILE__,$description, 'CreateSpecifiedDomains'); |
344 | ||
6a488035 TO |
345 | $this->assertEquals(0, $result['values'][3]['uniq_email_per_site']); |
346 | $this->assertEquals(0, $result['values'][1]['uniq_email_per_site']); | |
7fbb4198 | 347 | $params = array( |
6a488035 TO |
348 | 'domain_id' => array(1,2), |
349 | 'return' => array('uniq_email_per_site'), | |
350 | ); | |
6a488035 | 351 | $description = "shows getting a variable for specified domains"; |
7fbb4198 | 352 | $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__,$description, 'GetSpecifiedDomains', 'Get'); |
6a488035 TO |
353 | $this->assertEquals(1, $result['values'][2]['uniq_email_per_site']); |
354 | $this->assertEquals(0, $result['values'][1]['uniq_email_per_site']); | |
355 | ||
356 | } | |
357 | ||
358 | function testGetSetting() { | |
359 | ||
7fbb4198 | 360 | $params = array( |
361 | 'domain_id' => $this->_domainID2, | |
362 | 'return' => 'uniq_email_per_site', | |
6a488035 | 363 | ); |
6a488035 | 364 | $description = "shows get setting a variable for a given domain - if no domain is set current is assumed"; |
7fbb4198 | 365 | |
366 | $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__); | |
6a488035 TO |
367 | |
368 | $params = array( | |
6a488035 TO |
369 | 'return' => 'uniq_email_per_site', |
370 | ); | |
6a488035 | 371 | $description = "shows getting a variable for a current domain"; |
7fbb4198 | 372 | $result = $this->callAPIAndDocument('setting', 'get', $params, __FUNCTION__, __FILE__, $description, 'GetSettingCurrentDomain'); |
6a488035 TO |
373 | $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); |
374 | } | |
ee7b49c4 E |
375 | |
376 | /** | |
377 | * Check that setting defined in extension can be retrieved | |
378 | */ | |
379 | function testGetExtensionSetting() { | |
380 | $this->hookClass->setHook('civicrm_alterSettingsFolders', array($this, 'setExtensionMetadata')); | |
381 | $data = NULL; | |
382 | // the caching of data to all duplicates the caching of data to the empty string | |
383 | CRM_Core_BAO_Cache::setItem($data, 'CiviCRM setting Spec', 'All'); | |
384 | CRM_Core_BAO_Cache::setItem($data, 'CiviCRM setting Specs', 'settingsMetadata__'); | |
385 | $fields = $this->callAPISuccess('setting', 'getfields', array('filters' => array('group_name' => 'Test Settings'))); | |
386 | $this->assertArrayHasKey('test_key', $fields['values']); | |
387 | $this->callAPISuccess('setting', 'create', array('test_key' => 'keyset')); | |
388 | $result = $this->callAPISuccess('setting', 'getvalue', array('name' => 'test_key', 'group' => 'Test Settings')); | |
389 | $this->assertEquals('keyset', $result); | |
390 | } | |
6a488035 TO |
391 | /** |
392 | * setting api should set & fetch settings stored in config as well as those in settings table | |
393 | */ | |
394 | function testSetConfigSetting() { | |
395 | $config = CRM_Core_Config::singleton(); | |
396 | $this->assertFalse($config->debug == 1); | |
7fbb4198 | 397 | $params = array( |
6a488035 TO |
398 | 'domain_id' => $this->_domainID2, |
399 | 'debug_enabled' => 1, | |
400 | ); | |
7fbb4198 | 401 | $result = $this->callAPISuccess('setting', 'create', $params); |
5b887f26 | 402 | CRM_Core_BAO_Domain::setDomain($this->_domainID2); |
403 | $config = CRM_Core_Config::singleton(TRUE, TRUE); | |
404 | CRM_Core_BAO_Domain::resetDomain(); | |
6a488035 TO |
405 | $this->assertTrue($config->debug == 1); |
406 | // this should NOT be stored in the settings table now - only in config | |
407 | $sql = " SELECT count(*) as c FROM civicrm_setting WHERE name LIKE '%debug%'"; | |
408 | $dao = CRM_Core_DAO::executeQuery($sql); | |
409 | $dao->fetch(); | |
410 | $this->assertEquals($dao->c, 0); | |
411 | } | |
412 | /** | |
413 | * setting api should set & fetch settings stored in config as well as those in settings table | |
414 | */ | |
415 | function testGetConfigSetting() { | |
7fbb4198 | 416 | $settings = $this->callAPISuccess('setting', 'get', array( |
417 | 'name' => 'defaultCurrency', 'sequential' => 1,) | |
6a488035 | 418 | ); |
6a488035 TO |
419 | $this->assertEquals('USD', $settings['values'][0]['defaultCurrency']); |
420 | } | |
2ba45310 | 421 | |
422 | /** | |
423 | * setting api should set & fetch settings stored in config as well as those in settings table | |
424 | */ | |
425 | function testGetSetConfigSettingMultipleDomains() { | |
7fbb4198 | 426 | $settings = $this->callAPISuccess('setting', 'create', array( |
427 | 'defaultCurrency' => 'USD', 'domain_id' => $this->_currentDomain) | |
2ba45310 | 428 | ); |
7fbb4198 | 429 | $settings = $this->callAPISuccess('setting', 'create', array( |
430 | 'defaultCurrency' => 'CAD', 'domain_id' => $this->_domainID2) | |
2ba45310 | 431 | ); |
7fbb4198 | 432 | $settings = $this->callAPISuccess('setting', 'get', array( |
433 | 'return' => 'defaultCurrency', 'domain_id' => 'all', | |
2ba45310 | 434 | ) |
435 | ); | |
436 | $this->assertEquals('USD', $settings['values'][$this->_currentDomain]['defaultCurrency']); | |
437 | $this->assertEquals('CAD', $settings['values'][$this->_domainID2]['defaultCurrency'], | |
438 | "second domain (id {$this->_domainID2} ) should be set to CAD. First dom was {$this->_currentDomain} & was USD"); | |
439 | ||
440 | } | |
441 | ||
6a488035 TO |
442 | /* |
443 | * Use getValue against a config setting | |
444 | */ | |
445 | function testGetValueConfigSetting() { | |
7fbb4198 | 446 | $params = array( 'name' => 'monetaryThousandSeparator', |
6a488035 TO |
447 | 'group' => 'Localization Setting', |
448 | ); | |
7fbb4198 | 449 | $result = $this->callAPISuccess('setting', 'getvalue', $params); |
6a488035 TO |
450 | $this->assertEquals(',', $result); |
451 | } | |
452 | ||
453 | function testGetValue() { | |
7fbb4198 | 454 | $params = array( 'name' => 'petition_contacts', |
6a488035 TO |
455 | 'group' => 'Campaign Preferences' |
456 | ); | |
6a488035 | 457 | $description = "Demonstrates getvalue action - intended for runtime use as better caching than get"; |
7fbb4198 | 458 | |
459 | $result = $this->callAPIAndDocument('setting', 'getvalue', $params, __FUNCTION__, __FILE__, $description); | |
460 | $this->assertEquals('Petition Contacts', $result); | |
6a488035 TO |
461 | } |
462 | ||
463 | function testGetDefaults() { | |
7fbb4198 | 464 | $description = "gets defaults setting a variable for a given domain - if no domain is set current is assumed"; |
6a488035 | 465 | |
7fbb4198 | 466 | $params = array( |
6a488035 TO |
467 | 'name' => 'address_format', |
468 | ); | |
7fbb4198 | 469 | $result = $this->callAPIAndDocument('setting', 'getdefaults', $params, __FUNCTION__, __FILE__,$description,'GetDefaults','getdefaults'); |
6a488035 | 470 | $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 | 471 | $params = array('name' => 'mailing_format',); |
472 | $result = $this->callAPISuccess('setting', 'getdefaults', $params); | |
6a488035 TO |
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 | $this->assertArrayHasKey(CRM_Core_Config::domainID(), $result['values']); | |
475 | } | |
476 | /* | |
477 | * Function tests reverting a specific parameter | |
478 | */ | |
479 | function testRevert() { | |
480 | ||
7fbb4198 | 481 | $params = array( 'address_format' => 'xyz', |
6a488035 TO |
482 | 'mailing_format' => 'bcs', |
483 | ); | |
7fbb4198 | 484 | $result = $this->callAPISuccess('setting', 'create', $params); |
6a488035 | 485 | $this->assertAPISuccess($result, "in line " . __LINE__); |
7fbb4198 | 486 | $revertParams = array( 'name' => 'address_format' |
6a488035 | 487 | ); |
7fbb4198 | 488 | $result = $this->callAPISuccess('setting', 'get', $params); |
6a488035 TO |
489 | //make sure it's set |
490 | $this->assertEquals('xyz', $result['values'][CRM_Core_Config::domainID()]['address_format']); | |
491 | $description = "Demonstrates reverting a parameter to default value"; | |
7fbb4198 | 492 | $result = $this->callAPIAndDocument('setting', 'revert', $revertParams, __FUNCTION__, __FILE__,$description,'','revert'); |
6a488035 | 493 | //make sure it's reverted |
7fbb4198 | 494 | $result = $this->callAPISuccess('setting', 'get', $params); |
6a488035 | 495 | $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 | 496 | $params = array( 'return' => array('mailing_format'), |
6a488035 | 497 | ); |
7fbb4198 | 498 | $result = $this->callAPISuccess('setting', 'get', $params); |
6a488035 TO |
499 | //make sure it's unchanged |
500 | $this->assertEquals('bcs', $result['values'][CRM_Core_Config::domainID()]['mailing_format']); | |
501 | } | |
502 | /* | |
503 | * Tests reverting ALL parameters (specific domain) | |
504 | */ | |
505 | function testRevertAll() { | |
506 | ||
7fbb4198 | 507 | $params = array( 'address_format' => 'xyz', |
6a488035 TO |
508 | 'mailing_format' => 'bcs', |
509 | ); | |
7fbb4198 | 510 | $result = $this->callAPISuccess('setting', 'create', $params); |
511 | $revertParams = array( ); | |
512 | $result = $this->callAPISuccess('setting', 'get', $params); | |
6a488035 TO |
513 | //make sure it's set |
514 | $this->assertEquals('xyz', $result['values'][CRM_Core_Config::domainID()]['address_format']); | |
515 | ||
7fbb4198 | 516 | $this->callAPISuccess('setting', 'revert', $revertParams); |
6a488035 | 517 | //make sure it's reverted |
7fbb4198 | 518 | $result = $this->callAPISuccess('setting', 'get', array('group' => 'core')); |
6a488035 TO |
519 | $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']); |
520 | $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']); | |
521 | } | |
522 | ||
523 | /* | |
524 | * Tests filling missing params | |
525 | */ | |
526 | function testFill() { | |
527 | $domparams = array( | |
528 | 'name' => 'B Team Domain', | |
7fbb4198 | 529 | ); |
530 | $dom = $this->callAPISuccess('domain', 'create', $domparams); | |
531 | $params = array( 'domain_id' => 'all', | |
6a488035 | 532 | ); |
7fbb4198 | 533 | $result = $this->callAPISuccess('setting', 'get', $params); |
534 | $params = array( 'address_format' => 'xyz', | |
6a488035 TO |
535 | 'mailing_format' => 'bcs', |
536 | 'domain_id' => $this->_domainID2, | |
537 | ); | |
7fbb4198 | 538 | $result = $this->callAPISuccess('setting', 'create', $params); |
539 | $params = array( 'domain_id' => $dom['id'], | |
6a488035 | 540 | ); |
7fbb4198 | 541 | $result = $this->callAPISuccess('setting', 'get', $params); |
6a488035 TO |
542 | $this->assertAPISuccess($result, "in line " . __LINE__); |
543 | $this->assertArrayNotHasKey('tag_unconfirmed', $result['values'][$dom['id']],'setting for domain 3 should not be set. Debug this IF domain test is passing'); | |
7fbb4198 | 544 | $result = $this->callAPISuccess('setting', 'fill', $params); |
6a488035 | 545 | $this->assertAPISuccess($result, "in line " . __LINE__); |
7fbb4198 | 546 | $result = $this->callAPISuccess('setting', 'get', $params); |
6a488035 TO |
547 | $this->assertAPISuccess($result, "in line " . __LINE__); |
548 | $this->assertArrayHasKey('tag_unconfirmed', $result['values'][$dom['id']]); | |
f64cd471 | 549 | $this->assertArrayHasKey('extensionsDir', $result['values'][$dom['id']]); |
6a488035 TO |
550 | $this->assertEquals('Unconfirmed', $result['values'][$dom['id']]['tag_unconfirmed']); |
551 | } | |
552 | } | |
553 |