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