additional fix
authordeb.monish <monish.deb@jmaconsulting.biz>
Fri, 9 Feb 2018 19:04:02 +0000 (00:34 +0530)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Sun, 11 Feb 2018 17:02:13 +0000 (22:32 +0530)
CRM/Report/Form/Activity.php
tests/phpunit/CRM/Report/Form/ActivityTest.php

index e3d4d3b0dbcb96ba5eb289df951337bce0c92b67..fef30e881107809757b18c9d7e2b22ab688ae80a 100644 (file)
@@ -436,7 +436,8 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
           strstr($clause, 'civicrm_email_target.') ||
           strstr($clause, 'civicrm_email_source.') ||
           strstr($clause, 'civicrm_phone_target.') ||
-          strstr($clause, 'civicrm_phone_source.')
+          strstr($clause, 'civicrm_phone_source.') ||
+          strstr($clause, 'civicrm_address_')
         ) {
           $removeKeys[] = $key;
           unset($this->_selectClauses[$key]);
@@ -450,7 +451,8 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
           strstr($clause, 'civicrm_email_target.') ||
           strstr($clause, 'civicrm_email_assignee.') ||
           strstr($clause, 'civicrm_phone_target.') ||
-          strstr($clause, 'civicrm_phone_assignee.')
+          strstr($clause, 'civicrm_phone_assignee.') ||
+          strstr($clause, 'civicrm_address_')
         ) {
           $removeKeys[] = $key;
           unset($this->_selectClauses[$key]);
@@ -481,7 +483,7 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
         unset($this->_selectAliases[$key]);
       }
 
-      if ($recordType != 'final') {
+      if ($recordType == 'target') {
         foreach ($this->_columns['civicrm_address']['order_bys'] as $fieldName => $field) {
           $orderByFld = $this->_columns['civicrm_address']['order_bys'][$fieldName];
           $fldInfo = $this->_columns['civicrm_address']['fields'][$fieldName];
index 5a7fdced3d39f8b35ac8093133a58f2b72e5cfb0..40701db881fc850298c93a6ab836ea486b8a31b6 100644 (file)
@@ -49,6 +49,7 @@ class CRM_Report_Form_ActivityTest extends CiviReportTestCase {
     CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp1');
     CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp2');
     CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp3');
+    CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_activity_temp_target');
   }
 
   /**
@@ -82,4 +83,78 @@ class CRM_Report_Form_ActivityTest extends CiviReportTestCase {
     $this->assertTrue(TRUE, "Testo");
   }
 
+  /**
+   * Ensure that activity detail report only shows addres fields of target contact
+   */
+  public function testTargetAddressFields() {
+    $countryNames = array_flip(CRM_Core_PseudoConstant::country());
+    // Create contact 1 and 2 with address fields, later considered as target contacts for activity
+    $contactID1 = $this->individualCreate(array(
+      'api.Address.create' => array(
+        'contact_id' => '$value.id',
+        'location_type_id' => 'Home',
+        'city' => 'ABC',
+        'country_id' => $countryNames['India'],
+      ),
+    ));
+    $contactID2 = $this->individualCreate(array(
+      'api.Address.create' => array(
+        'contact_id' => '$value.id',
+        'location_type_id' => 'Home',
+        'city' => 'DEF',
+        'country_id' => $countryNames['United States'],
+      ),
+    ));
+    // Create Contact 3 later considered as assignee contact of activity
+    $contactID3 = $this->individualCreate(array(
+      'api.Address.create' => array(
+        'contact_id' => '$value.id',
+        'location_type_id' => 'Home',
+        'city' => 'GHI',
+        'country_id' => $countryNames['China'],
+      ),
+    ));
+
+    // create dummy activity type
+    $activityTypeID = CRM_Utils_Array::value('id', $this->callAPISuccess('option_value', 'create', array(
+      'option_group_id' => 'activity_type',
+      'name' => 'Test activity type',
+      'label' => 'Test activity type',
+    )));
+    // create activity
+    $result = $this->callAPISuccess('activity', 'create', array(
+      'subject' => 'Make-it-Happen Meeting',
+      'activity_date_time' => date('Ymd'),
+      'duration' => 120,
+      'location' => 'Pennsylvania',
+      'details' => 'a test activity',
+      'status_id' => 1,
+      'activity_type_id' => 'Test activity type',
+      'source_contact_id' => $this->individualCreate(),
+      'target_contact_id' => array($contactID1, $contactID2),
+      'assignee_contact_id' => $contactID3,
+    ));
+    // display city and country field so that we can check its value
+    $input = array(
+      'fields' => array(
+        'city',
+        'country_id',
+      ),
+      'order_bys' => array(
+        'city' => array(),
+        'country_id' => array('default' => TRUE),
+      ),
+    );
+    // generate result
+    $obj = $this->getReportObject('CRM_Report_Form_Activity', $input);
+    $rows = $obj->getResultSet();
+
+    // ensure that only 1 activity is created
+    $this->assertEquals(1, count($rows));
+    // ensure that country values of respective target contacts are only shown
+    $this->assertEquals('India;United States', $rows[0]['civicrm_address_country_id']);
+    // ensure that city values of respective target contacts are only shown
+    $this->assertEquals('ABC;DEF', $rows[0]['civicrm_address_city']);
+  }
+
 }