Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] php8 - Unit test for empty checkbox array #23305 #25201

Merged
merged 1 commit into from
Dec 21, 2022

Conversation

demeritcowboy
Copy link
Contributor

Overview

To create a contact with a custom checkbox field where none of the boxes are checked, or update a contact where there are some checked to be unchecked, you can pass in 'custom_1' => [] as one of the params, but this crashes in php 8.

Before

TypeError: mysqli_real_escape_string(): Argument #2 ($string) must be of type string, array given ... vendor\pear\db\DB\mysqli.php:880

After

Technical Details

As noted in #23305, the problem is in the format function. Normally it would convert an array to a string in this situation, but it skips doing that because it returns too early, so ends up passing on an array to escapeString() later.

Comments

Is Test

@civibot
Copy link

civibot bot commented Dec 19, 2022

(Standard links)

@demeritcowboy
Copy link
Contributor Author

As expected:

api_v3_ContactTest::testCreateWithEmptyCustomCheckbox
TypeError: mysqli_real_escape_string(): Argument #2 ($string) must be of type string, array given

/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/vendor/pear/db/DB/mysqli.php:880
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/packages/DB/DataObject.php:1851
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/CRM/Core/DAO.php:2241
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/CRM/Core/DAO.php:1776
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/CRM/Core/DAO.php:1657
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/CRM/Core/BAO/CustomValueTable.php:271
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/CRM/Core/BAO/CustomValueTable.php:398
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/CRM/Contact/BAO/Contact.php:384
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/api/v3/Contact.php:571
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/api/v3/Contact.php:99
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/Civi/API/Provider/MagicFunctionProvider.php:89
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/Civi/API/Kernel.php:158
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/Civi/API/Kernel.php:81
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/api/api.php:22
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/Civi/Test/Api3TestTrait.php:292
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/Civi/Test/Api3TestTrait.php:173
/home/jenkins/bknix-dfl/build/core-25201-4exn3/web/sites/all/modules/civicrm/tests/phpunit/api/v3/ContactTest.php:755

The second fail is fallout from the first fail causing transaction issues.

@demeritcowboy demeritcowboy changed the title php8 - Failing test for empty checkbox array #23305 [NFC] php8 - Unit test for empty checkbox array #23305 Dec 20, 2022
@demeritcowboy
Copy link
Contributor Author

This should pass now. Jenkins retest this please.

@seamuslee001 seamuslee001 merged commit 04edd1c into civicrm:master Dec 21, 2022
@demeritcowboy demeritcowboy deleted the empty-checkbox branch December 21, 2022 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants