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