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