From 7bc341d57345fd5514471706e0fc5207a1efe78b Mon Sep 17 00:00:00 2001 From: demeritcowboy <demeritcowboy@hotmail.com> Date: Mon, 19 Dec 2022 14:39:40 -0500 Subject: [PATCH] failing test for empty checkbox array --- tests/phpunit/api/v3/ContactTest.php | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/phpunit/api/v3/ContactTest.php b/tests/phpunit/api/v3/ContactTest.php index 6e47a45281..7a6aeaebc1 100644 --- a/tests/phpunit/api/v3/ContactTest.php +++ b/tests/phpunit/api/v3/ContactTest.php @@ -718,6 +718,49 @@ class api_v3_ContactTest extends CiviUnitTestCase { $this->customGroupDelete($ids['custom_group_id']); } + /** + * Test create contact with custom checkbox with empty array + */ + public function testCreateWithEmptyCustomCheckbox(): void { + $this->callAPISuccess('OptionGroup', 'create', [ + 'name' => 'checkbox_opts', + 'title' => 'Checkbox Options', + 'data_type' => 'String', + 'is_active' => 1, + ]); + $this->callAPISuccess('OptionValue', 'create', [ + 'option_group_id' => 'checkbox_opts', + 'name' => 'checkbox_option_one', + 'label' => 'Checkbox Option One', + 'is_active' => 1, + 'value' => 1, + ]); + $custom_group_id = $this->createCustomGroup([ + 'name' => 'checkbox_custom_group', + 'title' => 'Checkbox Group', + 'extends' => 'Contact', + ]); + $custom_field_id = $this->callAPISuccess('CustomField', 'create', [ + 'name' => 'a_checkbox_field', + 'label' => 'A Checkbox Field', + 'custom_group_id' => $custom_group_id, + 'option_group_id' => 'checkbox_opts', + 'html_type' => 'CheckBox', + 'data_type' => 'String', + 'is_active' => 1, + ])['id']; + + $params = $this->_params; + $params['custom_' . $custom_field_id] = []; + $contact_id = $this->callAPISuccess('Contact', 'create', $params)['id']; + + $result = $this->callAPISuccessGetSingle('Contact', ['id' => $contact_id, 'return' => ['custom_' . $custom_field_id]]); + $this->assertSame('', $result['custom_' . $custom_field_id]); + + $this->customFieldDelete($custom_field_id); + $this->customGroupDelete($custom_group_id); + } + /** * CRM-14232 test preferred language set to site default if not passed. * -- 2.25.1