Commit | Line | Data |
---|---|---|
2caf0feb JM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
2caf0feb | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
2caf0feb JM |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * Test Activity report outcome | |
30 | * | |
31 | * @package CiviCRM | |
32 | */ | |
33 | class CRM_Report_Form_ActivityTest extends CiviReportTestCase { | |
9099cab3 | 34 | protected $_tablesToTruncate = [ |
2caf0feb JM |
35 | 'civicrm_contact', |
36 | 'civicrm_email', | |
37 | 'civicrm_phone', | |
38 | 'civicrm_address', | |
39 | 'civicrm_contribution', | |
9099cab3 | 40 | ]; |
2caf0feb JM |
41 | |
42 | public function setUp() { | |
43 | parent::setUp(); | |
44 | $this->quickCleanup($this->_tablesToTruncate); | |
45 | } | |
46 | ||
47 | public function tearDown() { | |
48 | parent::tearDown(); | |
c00963a1 | 49 | CRM_Core_DAO::executeQuery('DROP TEMPORARY TABLE IF EXISTS civireport_activity_temp_target'); |
2caf0feb JM |
50 | } |
51 | ||
52 | /** | |
53 | * Ensure long custom field names don't result in errors. | |
54 | */ | |
55 | public function testLongCustomFieldNames() { | |
56 | // Create custom group with long name and custom field with long name. | |
57 | $long_name = 'this is a very very very very long name with 65 characters in it'; | |
9099cab3 | 58 | $group_params = [ |
2caf0feb JM |
59 | 'title' => $long_name, |
60 | 'extends' => 'Activity', | |
9099cab3 | 61 | ]; |
2caf0feb JM |
62 | $result = $this->customGroupCreate($group_params); |
63 | $custom_group_id = $result['id']; | |
9099cab3 | 64 | $field_params = [ |
2caf0feb JM |
65 | 'custom_group_id' => $custom_group_id, |
66 | 'label' => $long_name, | |
9099cab3 | 67 | ]; |
2caf0feb JM |
68 | $result = $this->customFieldCreate($field_params); |
69 | $custom_field_id = $result['id']; | |
9099cab3 CW |
70 | $input = [ |
71 | 'fields' => [ | |
2caf0feb | 72 | 'custom_' . $custom_field_id, |
9099cab3 CW |
73 | ], |
74 | ]; | |
2caf0feb JM |
75 | $obj = $this->getReportObject('CRM_Report_Form_Activity', $input); |
76 | //$params = $obj->_params; | |
77 | //$params['fields'] = array('custom_' . $custom_field_id); | |
78 | //$obj->setParams($params); | |
79 | $obj->getResultSet(); | |
80 | $this->assertTrue(TRUE, "Testo"); | |
81 | } | |
82 | ||
c00963a1 | 83 | /** |
84 | * Ensure that activity detail report only shows addres fields of target contact | |
85 | */ | |
86 | public function testTargetAddressFields() { | |
87 | $countryNames = array_flip(CRM_Core_PseudoConstant::country()); | |
88 | // Create contact 1 and 2 with address fields, later considered as target contacts for activity | |
9099cab3 CW |
89 | $contactID1 = $this->individualCreate([ |
90 | 'api.Address.create' => [ | |
c00963a1 | 91 | 'contact_id' => '$value.id', |
92 | 'location_type_id' => 'Home', | |
93 | 'city' => 'ABC', | |
94 | 'country_id' => $countryNames['India'], | |
9099cab3 CW |
95 | ], |
96 | ]); | |
97 | $contactID2 = $this->individualCreate([ | |
98 | 'api.Address.create' => [ | |
c00963a1 | 99 | 'contact_id' => '$value.id', |
100 | 'location_type_id' => 'Home', | |
101 | 'city' => 'DEF', | |
102 | 'country_id' => $countryNames['United States'], | |
9099cab3 CW |
103 | ], |
104 | ]); | |
c00963a1 | 105 | // Create Contact 3 later considered as assignee contact of activity |
9099cab3 CW |
106 | $contactID3 = $this->individualCreate([ |
107 | 'api.Address.create' => [ | |
c00963a1 | 108 | 'contact_id' => '$value.id', |
109 | 'location_type_id' => 'Home', | |
110 | 'city' => 'GHI', | |
111 | 'country_id' => $countryNames['China'], | |
9099cab3 CW |
112 | ], |
113 | ]); | |
c00963a1 | 114 | |
115 | // create dummy activity type | |
9099cab3 | 116 | $activityTypeID = CRM_Utils_Array::value('id', $this->callAPISuccess('option_value', 'create', [ |
c00963a1 | 117 | 'option_group_id' => 'activity_type', |
118 | 'name' => 'Test activity type', | |
119 | 'label' => 'Test activity type', | |
9099cab3 | 120 | ])); |
c00963a1 | 121 | // create activity |
9099cab3 | 122 | $result = $this->callAPISuccess('activity', 'create', [ |
c00963a1 | 123 | 'subject' => 'Make-it-Happen Meeting', |
124 | 'activity_date_time' => date('Ymd'), | |
125 | 'duration' => 120, | |
126 | 'location' => 'Pennsylvania', | |
127 | 'details' => 'a test activity', | |
128 | 'status_id' => 1, | |
129 | 'activity_type_id' => 'Test activity type', | |
130 | 'source_contact_id' => $this->individualCreate(), | |
9099cab3 | 131 | 'target_contact_id' => [$contactID1, $contactID2], |
c00963a1 | 132 | 'assignee_contact_id' => $contactID3, |
9099cab3 | 133 | ]); |
c00963a1 | 134 | // display city and country field so that we can check its value |
9099cab3 CW |
135 | $input = [ |
136 | 'fields' => [ | |
c00963a1 | 137 | 'city', |
138 | 'country_id', | |
9099cab3 CW |
139 | ], |
140 | 'order_bys' => [ | |
141 | 'city' => [], | |
142 | 'country_id' => ['default' => TRUE], | |
143 | ], | |
144 | ]; | |
c00963a1 | 145 | // generate result |
146 | $obj = $this->getReportObject('CRM_Report_Form_Activity', $input); | |
147 | $rows = $obj->getResultSet(); | |
148 | ||
149 | // ensure that only 1 activity is created | |
150 | $this->assertEquals(1, count($rows)); | |
151 | // ensure that country values of respective target contacts are only shown | |
b72100fc | 152 | $this->assertTrue(in_array($rows[0]['civicrm_address_country_id'], ['India;United States', 'United States;India'])); |
c00963a1 | 153 | // ensure that city values of respective target contacts are only shown |
77347e0a | 154 | $this->assertTrue(in_array($rows[0]['civicrm_address_city'], ['ABC;DEF', 'DEF;ABC'])); |
c00963a1 | 155 | } |
156 | ||
2caf0feb | 157 | } |