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