From 7474eb75c469e654df5e6ae0e76d51466bb05406 Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Thu, 13 Sep 2018 12:34:45 -0400 Subject: [PATCH] Closes core#393 - allow 0 as a valid option value when option group data_type is Integer --- CRM/Utils/Check/Component/OptionGroups.php | 2 +- .../Check/Component/OptionGroupsTest.php | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/CRM/Utils/Check/Component/OptionGroupsTest.php diff --git a/CRM/Utils/Check/Component/OptionGroups.php b/CRM/Utils/Check/Component/OptionGroups.php index 91e88437eb..a0a920224f 100644 --- a/CRM/Utils/Check/Component/OptionGroups.php +++ b/CRM/Utils/Check/Component/OptionGroups.php @@ -49,7 +49,7 @@ class CRM_Utils_Check_Component_OptionGroups extends CRM_Utils_Check_Component { if (count($values) > 0) { foreach ($values as $value) { $validate = CRM_Utils_Type::validate($value['value'], $optionGroup['data_type'], FALSE); - if (!$validate) { + if (is_null($validate)) { $problemValues[] = array( 'group_name' => $optionGroup['title'], 'value_name' => $value['label'], diff --git a/tests/phpunit/CRM/Utils/Check/Component/OptionGroupsTest.php b/tests/phpunit/CRM/Utils/Check/Component/OptionGroupsTest.php new file mode 100644 index 0000000000..3a1c04c042 --- /dev/null +++ b/tests/phpunit/CRM/Utils/Check/Component/OptionGroupsTest.php @@ -0,0 +1,31 @@ +callAPISuccess('OptionGroup', 'create', [ + 'name' => 'testGroup', + 'title' => 'testGroup', + 'data_type' => 'Integer', + ]); + // test that zero is a valid integer. + $this->callAPISuccess('OptionValue', 'create', [ + 'option_group_id' => $optionGroup['id'], + 'label' => 'zero', + 'value' => 0, + ]); + $check = new \CRM_Utils_Check_Component_OptionGroups; + $result = $check->checkOptionGroupValues(); + $this->assertArrayNotHasKey(0, $result); + } +} \ No newline at end of file -- 2.25.1