| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 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 | */ |
| 24 | public function setUp() { |
| 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() { |
| 33 | CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'contribution_status']); |
| 34 | $this->callAPISuccessGetSingle('OptionGroup', ['name' => 'contribution_status']); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Ensure only one option value exists adds a new value. |
| 39 | */ |
| 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)); |
| 44 | |
| 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)); |
| 48 | } |
| 49 | |
| 50 | } |