Test for https://github.com/civicrm/civicrm-core/pull/15435
authoreileen <emcnaughton@wikimedia.org>
Mon, 13 Jul 2020 03:51:29 +0000 (15:51 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 13 Jul 2020 22:30:21 +0000 (10:30 +1200)
CRM/Report/Form.php
CRM/Report/Form/Contribute/Detail.php
api/v3/ReportTemplate.php
tests/phpunit/CRM/Report/Form/Contribute/DetailTest.php
tests/phpunit/CiviTest/CiviReportTestCase.php

index 31866f648a8f3fea6e768acba403e5050b5f092b..2532743da02a020cf877cf3f91d318041cb4bcd6 100644 (file)
@@ -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;
index 815aa987e9097d3ca85004f248a43aca1418b37d..c164f42cdfd9366d97c61e691f659ac86c2253cf 100644 (file)
@@ -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);
index 5d2e98fe6162982b902fa9e30bfedba44ab84aac..2b96179265d1c7561a6c60e8b3fd2a4267d5bba8 100644 (file)
@@ -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']);
index ab186b2cf64d146b712cefac0a7dc9cd38c4f4d3..c384ff17f530093699c8a6aeeb0eb43d8517518b 100644 (file)
@@ -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);
+
   }
 
 }
index 7e71a4d98b86dedf452282ec7da6498c5b3058bb..fca4ea43ad7ca7506b546d107325de60d93c7882 100644 (file)
@@ -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) {