3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Test Activity report outcome
17 class CRM_Report_Form_ActivityTest
extends CiviReportTestCase
{
18 protected $_tablesToTruncate = [
23 'civicrm_contribution',
26 public function setUp() {
28 $this->quickCleanup($this->_tablesToTruncate
);
31 public function tearDown() {
33 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_activity_temp_target');
37 * Ensure long custom field names don't result in errors.
39 public function testLongCustomFieldNames() {
40 // Create custom group with long name and custom field with long name.
41 $long_name = 'this is a very very very very long name with 65 characters in it';
43 'title' => $long_name,
44 'extends' => 'Activity',
46 $result = $this->customGroupCreate($group_params);
47 $custom_group_id = $result['id'];
49 'custom_group_id' => $custom_group_id,
50 'label' => $long_name,
52 $result = $this->customFieldCreate($field_params);
53 $custom_field_id = $result['id'];
56 'custom_' . $custom_field_id,
59 $obj = $this->getReportObject('CRM_Report_Form_Activity', $input);
60 //$params = $obj->_params;
61 //$params['fields'] = array('custom_' . $custom_field_id);
62 //$obj->setParams($params);
64 $this->assertTrue(TRUE, "Testo");
68 * Ensure that activity detail report only shows addres fields of target contact
70 public function testTargetAddressFields() {
71 $countryNames = array_flip(CRM_Core_PseudoConstant
::country());
72 // Create contact 1 and 2 with address fields, later considered as target contacts for activity
73 $contactID1 = $this->individualCreate([
74 'api.Address.create' => [
75 'contact_id' => '$value.id',
76 'location_type_id' => 'Home',
78 'country_id' => $countryNames['India'],
81 $contactID2 = $this->individualCreate([
82 'api.Address.create' => [
83 'contact_id' => '$value.id',
84 'location_type_id' => 'Home',
86 'country_id' => $countryNames['United States'],
89 // Create Contact 3 later considered as assignee contact of activity
90 $contactID3 = $this->individualCreate([
91 'api.Address.create' => [
92 'contact_id' => '$value.id',
93 'location_type_id' => 'Home',
95 'country_id' => $countryNames['China'],
99 // create dummy activity type
100 $activityTypeID = CRM_Utils_Array
::value('id', $this->callAPISuccess('option_value', 'create', [
101 'option_group_id' => 'activity_type',
102 'name' => 'Test activity type',
103 'label' => 'Test activity type',
106 $result = $this->callAPISuccess('activity', 'create', [
107 'subject' => 'Make-it-Happen Meeting',
108 'activity_date_time' => date('Ymd'),
110 'location' => 'Pennsylvania',
111 'details' => 'a test activity',
113 'activity_type_id' => 'Test activity type',
114 'source_contact_id' => $this->individualCreate(),
115 'target_contact_id' => [$contactID1, $contactID2],
116 'assignee_contact_id' => $contactID3,
118 // display city and country field so that we can check its value
126 'country_id' => ['default' => TRUE],
130 $obj = $this->getReportObject('CRM_Report_Form_Activity', $input);
131 $rows = $obj->getResultSet();
133 // ensure that only 1 activity is created
134 $this->assertEquals(1, count($rows));
135 // ensure that country values of respective target contacts are only shown
136 $this->assertTrue(in_array($rows[0]['civicrm_address_country_id'], ['India;United States', 'United States;India']));
137 // ensure that city values of respective target contacts are only shown
138 $this->assertTrue(in_array($rows[0]['civicrm_address_city'], ['ABC;DEF', 'DEF;ABC']));