4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 namespace api\v
4\Action
;
22 use Civi\Api4\CustomField
;
23 use Civi\Api4\CustomGroup
;
24 use Civi\Api4\OptionGroup
;
25 use Civi\Api4\OptionValue
;
30 class CreateCustomValueTest
extends BaseCustomValueTest
{
32 public function testGetWithCustomData() {
33 $optionValues = ['r' => 'Red', 'g' => 'Green', 'b' => 'Blue'];
35 $customGroup = CustomGroup
::create(FALSE)
36 ->addValue('name', 'MyContactFields')
37 ->addValue('extends', 'Contact')
41 CustomField
::create(FALSE)
42 ->addValue('label', 'Color')
43 ->addValue('option_values', $optionValues)
44 ->addValue('custom_group_id', $customGroup['id'])
45 ->addValue('html_type', 'Select')
46 ->addValue('data_type', 'String')
49 $customField = CustomField
::get(FALSE)
50 ->addWhere('label', '=', 'Color')
54 $this->assertNotNull($customField['option_group_id']);
55 $optionGroupId = $customField['option_group_id'];
57 $optionGroup = OptionGroup
::get(FALSE)
58 ->addWhere('id', '=', $optionGroupId)
62 $this->assertEquals('Color', $optionGroup['title']);
64 $createdOptionValues = OptionValue
::get(FALSE)
65 ->addWhere('option_group_id', '=', $optionGroupId)
69 $values = array_column($createdOptionValues, 'value');
70 $labels = array_column($createdOptionValues, 'label');
71 $createdOptionValues = array_combine($values, $labels);
73 $this->assertEquals($optionValues, $createdOptionValues);