4 +--------------------------------------------------------------------+
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2019 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2019
38 namespace api\v
4\Action
;
40 use Civi\Api4\CustomField
;
41 use Civi\Api4\CustomGroup
;
42 use Civi\Api4\OptionGroup
;
43 use Civi\Api4\OptionValue
;
48 class CreateCustomValueTest
extends BaseCustomValueTest
{
50 public function testGetWithCustomData() {
51 $optionValues = ['r' => 'Red', 'g' => 'Green', 'b' => 'Blue'];
53 $customGroup = CustomGroup
::create()
54 ->setCheckPermissions(FALSE)
55 ->addValue('name', 'MyContactFields')
56 ->addValue('extends', 'Contact')
61 ->setCheckPermissions(FALSE)
62 ->addValue('label', 'Color')
63 ->addValue('option_values', $optionValues)
64 ->addValue('custom_group_id', $customGroup['id'])
65 ->addValue('html_type', 'Select')
66 ->addValue('data_type', 'String')
69 $customField = CustomField
::get()
70 ->setCheckPermissions(FALSE)
71 ->addWhere('label', '=', 'Color')
75 $this->assertNotNull($customField['option_group_id']);
76 $optionGroupId = $customField['option_group_id'];
78 $optionGroup = OptionGroup
::get()
79 ->setCheckPermissions(FALSE)
80 ->addWhere('id', '=', $optionGroupId)
84 $this->assertEquals('Color', $optionGroup['title']);
86 $createdOptionValues = OptionValue
::get()
87 ->setCheckPermissions(FALSE)
88 ->addWhere('option_group_id', '=', $optionGroupId)
92 $values = array_column($createdOptionValues, 'value');
93 $labels = array_column($createdOptionValues, 'label');
94 $createdOptionValues = array_combine($values, $labels);
96 $this->assertEquals($optionValues, $createdOptionValues);