From c00963a16eecdf857a688ed731cc3c5a16463a0c Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Sat, 10 Feb 2018 00:34:02 +0530 Subject: [PATCH] additional fix --- CRM/Report/Form/Activity.php | 8 +- .../phpunit/CRM/Report/Form/ActivityTest.php | 75 +++++++++++++++++++ 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/CRM/Report/Form/Activity.php b/CRM/Report/Form/Activity.php index e3d4d3b0db..fef30e8811 100644 --- a/CRM/Report/Form/Activity.php +++ b/CRM/Report/Form/Activity.php @@ -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]; diff --git a/tests/phpunit/CRM/Report/Form/ActivityTest.php b/tests/phpunit/CRM/Report/Form/ActivityTest.php index 5a7fdced3d..40701db881 100644 --- a/tests/phpunit/CRM/Report/Form/ActivityTest.php +++ b/tests/phpunit/CRM/Report/Form/ActivityTest.php @@ -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']); + } + } -- 2.25.1