Commit | Line | Data |
---|---|---|
7cbde1aa | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
7cbde1aa | 5 | | | |
7d61e75f TO |
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 | | |
7cbde1aa | 9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * Class CRM_Core_BAO_SchemaHandlerTest. | |
14 | * | |
15 | * These tests create and drop indexes on the civicrm_uf_join table. The indexes | |
16 | * being added and dropped we assume will never exist. | |
17 | * @group headless | |
18 | */ | |
19 | class CRM_Core_BAO_OptionGroupTest extends CiviUnitTestCase { | |
20 | ||
21 | /** | |
22 | * Test setup for every test. | |
23 | */ | |
faba1457 | 24 | public function setUp(): void { |
7cbde1aa | 25 | parent::setUp(); |
26 | $this->useTransaction(TRUE); | |
27 | } | |
28 | ||
29 | /** | |
30 | * Ensure only one option value exists after calling ensureOptionValueExists. | |
31 | */ | |
32 | public function testEnsureOptionGroupExistsExistingValue() { | |
9099cab3 CW |
33 | CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'contribution_status']); |
34 | $this->callAPISuccessGetSingle('OptionGroup', ['name' => 'contribution_status']); | |
7cbde1aa | 35 | } |
36 | ||
37 | /** | |
38 | * Ensure only one option value exists adds a new value. | |
39 | */ | |
40 | public function testEnsureOptionGroupExistsNewValue() { | |
9099cab3 | 41 | CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'Bombed']); |
17f78bae | 42 | $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', ['context' => 'validate', 'field' => 'option_group_id'])['values']; |
6ebc7a89 | 43 | $this->assertTrue(in_array('bombed', $optionGroups)); |
7cbde1aa | 44 | |
9099cab3 | 45 | CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'Bombed Again']); |
17f78bae | 46 | $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', ['context' => 'validate', 'field' => 'option_group_id'])['values']; |
6ebc7a89 | 47 | $this->assertTrue(in_array('bombed_again', $optionGroups)); |
7cbde1aa | 48 | } |
49 | ||
50 | } |