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_OptionGroupTest
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 testEnsureOptionGroupExistsExistingValue() {
33 CRM_Core_BAO_OptionGroup
::ensureOptionGroupExists(['name' => 'contribution_status']);
34 $this->callAPISuccessGetSingle('OptionGroup', ['name' => 'contribution_status']);
38 * Ensure only one option value exists adds a new value.
40 public function testEnsureOptionGroupExistsNewValue() {
41 CRM_Core_BAO_OptionGroup
::ensureOptionGroupExists(['name' => 'Bombed']);
42 $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', ['field' => 'option_group_id'])['values'];
43 $this->assertTrue(in_array('bombed', $optionGroups));
45 CRM_Core_BAO_OptionGroup
::ensureOptionGroupExists(['name' => 'Bombed Again']);
46 $optionGroups = $this->callAPISuccess('OptionValue', 'getoptions', ['field' => 'option_group_id'])['values'];
47 $this->assertTrue(in_array('bombed_again', $optionGroups));