From: eileen Date: Mon, 13 Jul 2020 03:51:29 +0000 (+1200) Subject: Test for https://github.com/civicrm/civicrm-core/pull/15435 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c86f74b12a5d555bf51fbf4999a5252009a252ac;p=civicrm-core.git Test for https://github.com/civicrm/civicrm-core/pull/15435 --- diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 31866f648a..2532743da0 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -4324,13 +4324,12 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a } if (array_key_exists('filters', $table)) { foreach ($table['filters'] as $filterName => $filter) { + $filterOp = $this->_params["{$filterName}_op"] ?? ''; if ((isset($this->_params["{$filterName}_value"]) && !CRM_Utils_System::isNull($this->_params["{$filterName}_value"])) || !empty($this->_params["{$filterName}_relative"]) - || CRM_Utils_Array::value("{$filterName}_op", $this->_params) == - 'nll' - || CRM_Utils_Array::value("{$filterName}_op", $this->_params) == - 'nnll' + || $filterOp === 'nll' + || $filterOp === 'nnll' ) { $this->_selectedTables[] = $tableName; $this->filteredTables[] = $tableName; diff --git a/CRM/Report/Form/Contribute/Detail.php b/CRM/Report/Form/Contribute/Detail.php index 815aa987e9..c164f42cdf 100644 --- a/CRM/Report/Form/Contribute/Detail.php +++ b/CRM/Report/Form/Contribute/Detail.php @@ -411,6 +411,7 @@ class CRM_Report_Form_Contribute_Detail extends CRM_Report_Form { * @param $rows * * @return array + * @throws \CRM_Core_Exception */ public function statistics(&$rows) { $statistics = parent::statistics($rows); diff --git a/api/v3/ReportTemplate.php b/api/v3/ReportTemplate.php index 5d2e98fe61..2b96179265 100644 --- a/api/v3/ReportTemplate.php +++ b/api/v3/ReportTemplate.php @@ -97,6 +97,9 @@ function civicrm_api3_report_template_delete($params) { * * @return array * API result array + * + * @throws \API_Exception + * @throws \CiviCRM_API3_Exception */ function civicrm_api3_report_template_getrows($params) { civicrm_api3_verify_one_mandatory($params, NULL, ['report_id', 'instance_id']); diff --git a/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php b/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php index ab186b2cf6..c384ff17f5 100644 --- a/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php +++ b/tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php @@ -176,10 +176,10 @@ class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase { $this->callAPISuccess('ContributionSoft', 'create', $softParams); $input = [ - 'filters' => [ - 'contribution_or_soft_op' => 'eq', - 'contribution_or_soft_value' => 'contributions_only', - ], + 'contribution_or_soft_op' => 'eq', + 'contribution_or_soft_value' => 'contributions_only', + 'soft_credit_type_id_op' => 'nnll', + 'soft_credit_type_id_value' => [], 'fields' => [ 'sort_name', 'email', @@ -190,10 +190,67 @@ class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase { 'soft_credits', ], ]; - $obj = $this->getReportObject('CRM_Report_Form_Contribute_Detail', $input); - $rows = $obj->getResultSet(); - $this->assertEquals(1, count($rows)); + $params = array_merge([ + 'report_id' => 'contribute/detail', + ], $input); + $rows = $this->callAPISuccess('ReportTemplate', 'getrows', $params)['values']; + $this->assertCount(1, $rows); $this->assertEquals('$ 150.00', $rows[0]['civicrm_contribution_total_amount']); + + $statistics = $this->callAPISuccess('ReportTemplate', 'getstatistics', $params)['values']; + $this->assertEquals([ + 'counts' => [ + 'rowCount' => [ + 'title' => 'Row(s) Listed', + 'value' => 1, + ], + 'amount' => [ + 'title' => 'Total Amount (Contributions)', + 'value' => '$ 150.00 (1)', + 'type' => 2, + ], + 'count' => [ + 'title' => 'Total Contributions', + 'value' => 1, + ], + 'fees' => [ + 'title' => 'Fees', + 'value' => '$ 5.00', + 'type' => 2, + ], + 'net' => [ + 'title' => 'Net', + 'value' => '$ 145.00', + 'type' => 2, + ], + 'avg' => [ + 'title' => 'Average', + 'value' => '$ 150.00', + 'type' => 2, + ], + ], + 'groups' => [ + [ + 'title' => 'Grouping(s)', + 'value' => 'Contribution', + ], + ], + 'filters' => [ + [ + 'title' => 'Contribution OR Soft Credit?', + 'value' => 'Is equal to Contributions Only', + ], + [ + 'title' => 'Contribution Status', + 'value' => 'Is Completed', + ], + [ + 'title' => 'Soft Credit Type', + 'value' => 'Is not empty (Null)', + ], + ], + ], $statistics); + } } diff --git a/tests/phpunit/CiviTest/CiviReportTestCase.php b/tests/phpunit/CiviTest/CiviReportTestCase.php index 7e71a4d98b..fca4ea43ad 100644 --- a/tests/phpunit/CiviTest/CiviReportTestCase.php +++ b/tests/phpunit/CiviTest/CiviReportTestCase.php @@ -47,10 +47,10 @@ class CiviReportTestCase extends CiviUnitTestCase { } /** - * @param $reportClass + * @param string $reportClass * @param array $inputParams * - * @return array + * @return CRM_Report_Form * @throws Exception */ public function getReportObject($reportClass, $inputParams) {