From 258c92c6086599fae32e1aa27c99c9e026d18265 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 11 Oct 2016 23:32:47 +1100 Subject: [PATCH] Fix Syntax Conformance Tests (#2) --- Civi/API/SelectQuery.php | 5 ++--- api/v3/utils.php | 11 +++-------- tests/phpunit/api/v3/SyntaxConformanceTest.php | 8 ++++++++ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Civi/API/SelectQuery.php b/Civi/API/SelectQuery.php index 44c347c64b..fc5d22cad5 100644 --- a/Civi/API/SelectQuery.php +++ b/Civi/API/SelectQuery.php @@ -123,8 +123,7 @@ abstract class SelectQuery { $this->buildSelectFields(); $this->buildWhereClause(); - - if (in_array('count', $this->select)) { + if (in_array('count_rows', $this->select)) { $this->query->select("count(*) as c"); } else { @@ -144,7 +143,7 @@ abstract class SelectQuery { $result_dao = \CRM_Core_DAO::executeQuery($this->query->toSQL()); while ($result_dao->fetch()) { - if (in_array('count', $this->select)) { + if (in_array('count_rows', $this->select)) { $result_dao->free(); return (int) $result_dao->c; } diff --git a/api/v3/utils.php b/api/v3/utils.php index e48f6a52cb..ba7393aeba 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -176,13 +176,8 @@ function civicrm_api3_create_success($values = 1, $params = array(), $entity = N $values[$key]['id'] = $item[$lowercase_entity . "_id"]; } if (!empty($item['financial_type_id'])) { - // 4.3 legacy handling - translate financial_type to contribution_type unless financial_type is explicitly specified. - if (!is_array($params) || empty($params['return']) || !is_array($params['return']) || - (empty($params['return']['financial_type_id']) && !in_array('financial_type_id', $params['return'])) || - (!empty($params['return']['contribution_type_id']) || in_array('contribution_type_id', $params['return'])) - ) { - $values[$key]['contribution_type_id'] = $item['financial_type_id']; - } + // 4.3 legacy handling. + $values[$key]['contribution_type_id'] = $item['financial_type_id']; } if (!empty($item['next_sched_contribution_date'])) { // 4.4 legacy handling @@ -1347,7 +1342,7 @@ function _civicrm_api3_basic_get($bao_name, $params, $returnAsSuccess = TRUE, $e $query = new \Civi\API\Api3SelectQuery($entity, CRM_Utils_Array::value('check_permissions', $params, FALSE)); $query->where = $params; if ($options['is_count']) { - $query->select = array('count'); + $query->select = array('count_rows'); } else { $query->select = array_keys(array_filter($options['return'])); diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 238fdea644..c2f7a25d82 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -1282,6 +1282,10 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { //api has special handling on these 2 fields for backward compatibility reasons $entity['contribution_type_id'] = $updateParams['financial_type_id']; } + if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, array('ContributionRecur'))) { + //api has special handling on these 2 fields for backward compatibility reasons + $entity['next_sched_contribution'] = $updateParams['next_sched_contribution_date']; + } $update = $this->callAPISuccess($entityName, 'create', $updateParams); $checkParams = array( @@ -1312,6 +1316,10 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase { //api has special handling on these 2 fields for backward compatibility reasons $entity['contribution_type_id'] = $updateParams['financial_type_id']; } + if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, array('ContributionRecur'))) { + //api has special handling on these 2 fields for backward compatibility reasons + $entity['next_sched_contribution'] = $updateParams['next_sched_contribution_date']; + } } } $baoObj->free(); -- 2.25.1