diff --git a/api/v3/utils.php b/api/v3/utils.php index 0c8f3190202858715f7ebec9fa7b4d0cf97f82dd..2fa4336a4ceb747409b779ed07f53cb6cfef8407 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -2078,9 +2078,14 @@ function _civicrm_api3_validate_integer(&$params, $fieldName, &$fieldInfo, $enti $fieldValue = NULL; } } - if (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options']) || $fieldName === 'campaign_id') { + if ( + (!empty($fieldInfo['pseudoconstant']) || !empty($fieldInfo['options']) || $fieldName === 'campaign_id') + // if it is already numeric AND it is an FK field we don't need to validate because + // sql will do that for us on insert (this also saves a big lookup) + && (!is_numeric($fieldValue) || empty($fieldInfo['FKClassName'])) + ) { $additional_lookup_params = []; - if (strtolower($entity) == 'address' && $fieldName == 'state_province_id') { + if (strtolower($entity) === 'address' && $fieldName == 'state_province_id') { $country_id = _civicrm_api3_resolve_country_id($params); if (!empty($country_id)) { $additional_lookup_params = ['country_id' => $country_id]; diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 3dfa28be3f0fa39815e25aecd9f3ec32bb412b6e..d71a75d16bdf195688b132479a0284e1285b0ec4 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -1203,10 +1203,10 @@ class api_v3_ContributionTest extends CiviUnitTestCase { * In the interests of removing financial type / contribution type checks from * legacy format function lets test that the api is doing this for us */ - public function testCreateInvalidFinancialType() { + public function testCreateInvalidFinancialType(): void { $params = $this->_params; $params['financial_type_id'] = 99999; - $this->callAPIFailure($this->entity, 'create', $params, "'99999' is not a valid option for field financial_type_id"); + $this->callAPIFailure($this->entity, 'create', $params); } /** diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index c23f5150d4b6eb538577757b487554cfdcfe9f76..9a62fa14add7ecc29de668731e4970579f1a405f 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -915,23 +915,6 @@ class api_v3_MembershipTest extends CiviUnitTestCase { ); } - public function testMembershipCreateWithInvalidStatus() { - $params = $this->_params; - $params['status_id'] = 999; - $this->callAPIFailure('membership', 'create', $params, - "'999' is not a valid option for field status_id" - ); - } - - public function testMembershipCreateWithInvalidType() { - $params = $this->_params; - $params['membership_type_id'] = 999; - - $this->callAPIFailure('membership', 'create', $params, - "'999' is not a valid option for field membership_type_id" - ); - } - /** * Check with complete array + custom field * Note that the test is written on purpose without any