dev/core#212 - Contribution Details report fails when 'Is not one of' condition is...
authorJitendra Purohit <jitendra@fuzion.co.nz>
Tue, 3 Jul 2018 11:59:37 +0000 (17:29 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Thu, 5 Jul 2018 11:24:02 +0000 (16:54 +0530)
CRM/Report/Form/Contribute/Detail.php
CRM/Report/Form/Contribute/Repeat.php
tests/phpunit/api/v3/ReportTemplateTest.php

index 3619a474093ee77d4ce811d0fedc4bb17219838c..8b0d9d99733c8f7cfc746476058adf487cdcf0fa 100644 (file)
@@ -926,6 +926,10 @@ WHERE  civicrm_contribution_contribution_id={$row['civicrm_contribution_contribu
       {$this->_aclFrom}
     ";
 
+    //Join temp table if report is filtered by group. This is specific to 'notin' operator and covered in unit test(ref dev/core#212)
+    if (!empty($this->_params['gid_op']) && $this->_params['gid_op'] == 'notin') {
+      $this->joinGroupTempTable('civicrm_contact', 'id', $this->_aliases['civicrm_contact']);
+    }
     $this->appendAdditionalFromJoins();
   }
 
index 6b87d4ebfdb642ed667fc67bdca04a3e33d410e3..471b076dab1b626b97bf8ede23d87df02c674588 100644 (file)
@@ -400,6 +400,11 @@ LEFT JOIN $this->tempTableRepeat1 {$this->_aliases['civicrm_contribution']}1
        .{$this->contributionJoinTableColumn}
 LEFT JOIN $this->tempTableRepeat2 {$this->_aliases['civicrm_contribution']}2
        ON {$this->groupByTableAlias}.$fromCol = {$this->_aliases['civicrm_contribution']}2.{$this->contributionJoinTableColumn}";
+
+    //Join temp table if report is filtered by group. This is specific to 'notin' operator and covered in unit test(ref dev/core#212)
+    if (!empty($this->_params['gid_op']) && $this->_params['gid_op'] == 'notin') {
+      $this->joinGroupTempTable('civicrm_contact', 'id', $this->_aliases['civicrm_contact']);
+    }
   }
 
   /**
@@ -825,6 +830,7 @@ GROUP BY    currency
   public function postProcess() {
     $this->beginPostProcess();
 
+    $this->buildGroupTempTable();
     $this->select();
     $this->from();
     $this->where();
index 118a3e57f329352e41d5f343897cdc2dfae1c64d..5d73da06c4fa5bd69193634604f5ce7b994ad7c4 100644 (file)
@@ -360,14 +360,15 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase {
 
     $this->assertEquals(2, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE));
 
-    $this->assertContains('DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci
+    $expected = 'DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci
       SELECT SQL_CALC_FOUND_ROWS contact_civireport.id as cid  FROM civicrm_contact contact_civireport    INNER JOIN civicrm_contribution contribution_civireport USE index (received_date) ON contribution_civireport.contact_id = contact_civireport.id
          AND contribution_civireport.is_test = 0
          AND contribution_civireport.receive_date BETWEEN \'20140701000000\' AND \'20150630235959\'
-       
+
        LEFT JOIN civicrm_contribution cont_exclude ON cont_exclude.contact_id = contact_civireport.id
          AND cont_exclude.receive_date BETWEEN \'2015-7-1\' AND \'20160630235959\' WHERE cont_exclude.id IS NULL AND 1 AND ( contribution_civireport.contribution_status_id IN (1) )
-      GROUP BY contact_civireport.id', $rows['metadata']['sql'][0]);
+      GROUP BY contact_civireport.id';
+    $this->assertContains(preg_replace('/\s+/', ' ', $expected), preg_replace('/\s+/', ' ', $rows['metadata']['sql'][0]));
   }
 
   /**
@@ -756,4 +757,23 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase {
     }
   }
 
+  /**
+   * Test the group filter works on the various reports.
+   *
+   * @dataProvider getMembershipAndContributionReportTemplatesForGroupTests
+   *
+   * @param string $template
+   *   Report template unique identifier.
+   */
+  public function testReportsWithNoTInSmartGroupFilter($template) {
+    $groupID = $this->setUpPopulatedGroup();
+    $rows = $this->callAPISuccess('report_template', 'getrows', array(
+      'report_id' => $template,
+      'gid_value' => array($groupID),
+      'gid_op' => 'notin',
+      'options' => array('metadata' => array('sql')),
+    ));
+    $this->assertNumberOfContactsInResult(2, $rows, $template);
+  }
+
 }