Commit | Line | Data |
---|---|---|
6f408d71 | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6f408d71 | 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 | | |
6f408d71 | 9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
6f408d71 | 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. | |
acb109b7 | 17 | * @group headless |
6f408d71 | 18 | */ |
19 | class CRM_Core_BAO_OptionValueTest extends CiviUnitTestCase { | |
20 | ||
21 | /** | |
22 | * Test setup for every test. | |
23 | */ | |
faba1457 | 24 | public function setUp(): void { |
6f408d71 | 25 | parent::setUp(); |
26 | $this->useTransaction(TRUE); | |
27 | } | |
28 | ||
29 | /** | |
30 | * Ensure only one option value exists after calling ensureOptionValueExists. | |
31 | */ | |
32 | public function testEnsureOptionValueExistsExistingValue() { | |
9099cab3 CW |
33 | CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Completed', 'option_group_id' => 'contribution_status']); |
34 | $this->callAPISuccessGetSingle('OptionValue', ['name' => 'Completed', 'option_group_id' => 'contribution_status']); | |
6f408d71 | 35 | } |
36 | ||
37 | /** | |
38 | * Ensure only one option value exists adds a new value. | |
39 | */ | |
40 | public function testEnsureOptionValueExistsNewValue() { | |
9099cab3 CW |
41 | CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Bombed', 'option_group_id' => 'contribution_status']); |
42 | $optionValues = $this->callAPISuccess('OptionValue', 'get', ['option_group_id' => 'contribution_status']); | |
6f408d71 | 43 | foreach ($optionValues['values'] as $value) { |
44 | if ($value['name'] == 'Bombed') { | |
45 | return; | |
46 | } | |
47 | } | |
48 | $this->fail('Should not have gotten this far'); | |
49 | } | |
50 | ||
6f408d71 | 51 | /** |
52 | * Ensure only one option value copes with disabled. | |
53 | * | |
54 | * (Our expectation is no change - ie. currently we are respecting 'someone's | |
55 | * decision to disable it & leaving it in that state. | |
56 | */ | |
57 | public function testEnsureOptionValueExistsDisabled() { | |
9099cab3 CW |
58 | $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Crashed', 'option_group_id' => 'contribution_status', 'is_active' => 0]); |
59 | $value = $this->callAPISuccessGetSingle('OptionValue', ['name' => 'Crashed', 'option_group_id' => 'contribution_status']); | |
6f408d71 | 60 | $this->assertEquals(0, $value['is_active']); |
ad8d1ce3 RO |
61 | $this->assertEquals($value['id'], $optionValue['id']); |
62 | ||
9099cab3 CW |
63 | $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists(['name' => 'Crashed', 'option_group_id' => 'contribution_status']); |
64 | $value = $this->callAPISuccessGetSingle('OptionValue', ['name' => 'Crashed', 'option_group_id' => 'contribution_status']); | |
6f408d71 | 65 | $this->assertEquals(0, $value['is_active']); |
ad8d1ce3 | 66 | $this->assertEquals($value['id'], $optionValue['id']); |
6f408d71 | 67 | } |
68 | ||
69 | } |