3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
13 * Class CRM_Core_BAO_SchemaHandlerTest.
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.
19 class CRM_Core_BAO_OptionValueTest
extends CiviUnitTestCase
{
22 * Test setup for every test.
24 public function setUp() {
26 $this->useTransaction(TRUE);
30 * Ensure only one option value exists after calling ensureOptionValueExists.
32 public function testEnsureOptionValueExistsExistingValue() {
33 CRM_Core_BAO_OptionValue
::ensureOptionValueExists(['name' => 'Completed', 'option_group_id' => 'contribution_status']);
34 $this->callAPISuccessGetSingle('OptionValue', ['name' => 'Completed', 'option_group_id' => 'contribution_status']);
38 * Ensure only one option value exists adds a new value.
40 public function testEnsureOptionValueExistsNewValue() {
41 CRM_Core_BAO_OptionValue
::ensureOptionValueExists(['name' => 'Bombed', 'option_group_id' => 'contribution_status']);
42 $optionValues = $this->callAPISuccess('OptionValue', 'get', ['option_group_id' => 'contribution_status']);
43 foreach ($optionValues['values'] as $value) {
44 if ($value['name'] == 'Bombed') {
48 $this->fail('Should not have gotten this far');
52 * Ensure only one option value copes with disabled.
54 * (Our expectation is no change - ie. currently we are respecting 'someone's
55 * decision to disable it & leaving it in that state.
57 public function testEnsureOptionValueExistsDisabled() {
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']);
60 $this->assertEquals(0, $value['is_active']);
61 $this->assertEquals($value['id'], $optionValue['id']);
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']);
65 $this->assertEquals(0, $value['is_active']);
66 $this->assertEquals($value['id'], $optionValue['id']);