Skip to content

Commit

Permalink
Fix Syntax Conformance Tests (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslee001 authored and colemanw committed Oct 11, 2016
1 parent 3313990 commit 258c92c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 2 additions & 3 deletions Civi/API/SelectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ public function run() {
$this->buildSelectFields();

$this->buildWhereClause();

if (in_array('count', $this->select)) {
if (in_array('count_rows', $this->select)) {
$this->query->select("count(*) as c");
}
else {
Expand All @@ -144,7 +143,7 @@ public function run() {
$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;
}
Expand Down
11 changes: 3 additions & 8 deletions api/v3/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']));
Expand Down
8 changes: 8 additions & 0 deletions tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,10 @@ public function testCreateSingleValueAlter($entityName) {
//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(
Expand Down Expand Up @@ -1312,6 +1316,10 @@ public function testCreateSingleValueAlter($entityName) {
//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();
Expand Down

0 comments on commit 258c92c

Please sign in to comment.