3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Test Activity report outcome
33 class CRM_Report_Form_ActivityTest
extends CiviReportTestCase
{
34 protected $_tablesToTruncate = array(
39 'civicrm_contribution',
42 public function setUp() {
44 $this->quickCleanup($this->_tablesToTruncate
);
47 public function tearDown() {
49 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp1');
50 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp2');
51 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_contribution_detail_temp3');
52 CRM_Core_DAO
::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_activity_temp_target');
56 * Ensure long custom field names don't result in errors.
58 public function testLongCustomFieldNames() {
59 // Create custom group with long name and custom field with long name.
60 $long_name = 'this is a very very very very long name with 65 characters in it';
61 $group_params = array(
62 'title' => $long_name,
63 'extends' => 'Activity',
65 $result = $this->customGroupCreate($group_params);
66 $custom_group_id = $result['id'];
67 $field_params = array(
68 'custom_group_id' => $custom_group_id,
69 'label' => $long_name,
71 $result = $this->customFieldCreate($field_params);
72 $custom_field_id = $result['id'];
75 'custom_' . $custom_field_id,
78 $obj = $this->getReportObject('CRM_Report_Form_Activity', $input);
79 //$params = $obj->_params;
80 //$params['fields'] = array('custom_' . $custom_field_id);
81 //$obj->setParams($params);
83 $this->assertTrue(TRUE, "Testo");
87 * Ensure that activity detail report only shows addres fields of target contact
89 public function testTargetAddressFields() {
90 $countryNames = array_flip(CRM_Core_PseudoConstant
::country());
91 // Create contact 1 and 2 with address fields, later considered as target contacts for activity
92 $contactID1 = $this->individualCreate(array(
93 'api.Address.create' => array(
94 'contact_id' => '$value.id',
95 'location_type_id' => 'Home',
97 'country_id' => $countryNames['India'],
100 $contactID2 = $this->individualCreate(array(
101 'api.Address.create' => array(
102 'contact_id' => '$value.id',
103 'location_type_id' => 'Home',
105 'country_id' => $countryNames['United States'],
108 // Create Contact 3 later considered as assignee contact of activity
109 $contactID3 = $this->individualCreate(array(
110 'api.Address.create' => array(
111 'contact_id' => '$value.id',
112 'location_type_id' => 'Home',
114 'country_id' => $countryNames['China'],
118 // create dummy activity type
119 $activityTypeID = CRM_Utils_Array
::value('id', $this->callAPISuccess('option_value', 'create', array(
120 'option_group_id' => 'activity_type',
121 'name' => 'Test activity type',
122 'label' => 'Test activity type',
125 $result = $this->callAPISuccess('activity', 'create', array(
126 'subject' => 'Make-it-Happen Meeting',
127 'activity_date_time' => date('Ymd'),
129 'location' => 'Pennsylvania',
130 'details' => 'a test activity',
132 'activity_type_id' => 'Test activity type',
133 'source_contact_id' => $this->individualCreate(),
134 'target_contact_id' => array($contactID1, $contactID2),
135 'assignee_contact_id' => $contactID3,
137 // display city and country field so that we can check its value
143 'order_bys' => array(
145 'country_id' => array('default' => TRUE),
149 $obj = $this->getReportObject('CRM_Report_Form_Activity', $input);
150 $rows = $obj->getResultSet();
152 // ensure that only 1 activity is created
153 $this->assertEquals(1, count($rows));
154 // ensure that country values of respective target contacts are only shown
155 $this->assertEquals('India;United States', $rows[0]['civicrm_address_country_id']);
156 // ensure that city values of respective target contacts are only shown
157 $this->assertEquals('ABC;DEF', $rows[0]['civicrm_address_city']);