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