Merge pull request #17253 from mattwire/utf8convertblocksize
[civicrm-core.git] / tests / phpunit / CRM / Core / BAO / OptionValueTest.php
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_OptionValueTest 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 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']);
35 }
36
37 /**
38 * Ensure only one option value exists adds a new value.
39 */
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') {
45 return;
46 }
47 }
48 $this->fail('Should not have gotten this far');
49 }
50
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() {
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']);
62
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']);
67 }
68
69 }