Merge pull request #11868 from eileenmcnaughton/cust_url
[civicrm-core.git] / tests / phpunit / WebTest / Report / LoggingReportTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Report_LoggingReportTest
31 */
32 class WebTest_Report_LoggingReportTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testLoggingReport() {
39 $this->webtestLogin();
40
41 //enable the logging
42 $this->openCiviPage('admin/setting/misc', 'reset=1');
43 $this->click("xpath=//tr[@class='crm-miscellaneous-form-block-logging']/td[2]/label[text()='Yes']");
44 $this->click("_qf_Miscellaneous_next-top");
45 $this->waitForPageToLoad(2 * $this->getTimeoutMsec());
46 // FIXME: good to do waitForText here but enabling log is time consuming and status may fade out by the time we do the check.
47
48 //enable CiviCase component
49 $this->enableComponents("CiviCase");
50
51 //add new contact
52 $originalFirstName = $firstName = 'Anthony' . substr(sha1(rand()), 0, 7);
53 $lastName = 'Anderson' . substr(sha1(rand()), 0, 7);
54
55 $this->webtestAddContact($firstName, $lastName);
56 $cid = $this->urlArg('cid');
57
58 //add contact to group
59 $this->waitForElementPresent("xpath=//li[@id='tab_group']/a");
60 $this->click("xpath=//li[@id='tab_group']/a");
61 // Because it tends to cause problems, all uses of sleep() must be justified in comments
62 // Sleep should never be used for wait for anything to load from the server
63 // Justification for this instance: FIXME
64 $this->waitForElementPresent("group_id");
65 $this->select("group_id", "label=Case Resources");
66 $this->click("_qf_GroupContact_next");
67 $this->waitForElementPresent("xpath=//form[@id='GroupContact']//div[@class='view-content view-contact-groups']//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[4]/a");
68 $this->click("xpath=//form[@id='GroupContact']//div[@class='view-content view-contact-groups']//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[4]/a");
69
70 // Check confirmation alert.
71 $this->waitForText("xpath=//div[@class='crm-confirm-dialog ui-dialog-content ui-widget-content modal-dialog']", "Remove $firstName $lastName from Case Resources?");
72 $this->click("xpath=//div[@class='ui-dialog-buttonset']//button//span[text()='Continue']");
73
74 //tag addition
75 $this->waitForElementPresent("xpath=//li[@id='tab_tag']/a");
76 $this->click("xpath=//li[@id='tab_tag']/a");
77 // Because it tends to cause problems, all uses of sleep() must be justified in comments
78 // Sleep should never be used for wait for anything to load from the server
79 // Justification for this instance: FIXME
80 $this->waitForElementPresent("tagtree");
81 $this->click("xpath=//div[@id='tagtree']/ul//li/span/label[text()='Company']");
82 $this->waitForTextPresent("Saved");
83 $this->click("xpath=//div[@id='tagtree']/ul//li/span/label[text()='Government Entity']");
84 $this->waitForTextPresent("Saved");
85 $this->click("xpath=//div[@id='tagtree']/ul//li/span/label[text()='Company']");
86 $this->waitForTextPresent("Saved");
87
88 //add new note
89 $this->waitForElementPresent("xpath=//li[@id='tab_note']/a");
90 $this->click("xpath=//li[@id='tab_note']/a");
91 $this->waitForAjaxContent();
92 $this->click("xpath=//div[@class='view-content']//div[@class='action-link']/a[@class='button medium-popup']");
93
94 $this->waitForElementPresent("_qf_Note_upload-top");
95 $noteSubject = "test note" . substr(sha1(rand()), 0, 7);
96 $noteText = "test note text" . substr(sha1(rand()), 0, 7);
97 $this->type('subject', $noteSubject);
98 $this->type('note', $noteText);
99 $this->click("_qf_Note_upload-top");
100 $this->waitForElementPresent("xpath=//div[@id='notes']/div/table/tbody/tr/td[7]/span[1]/a[2][text()='Edit']");
101 $this->click("xpath=//div[@id='notes']/div/table/tbody/tr/td[7]/span[1]/a[2][text()='Edit']");
102 $this->waitForElementPresent("_qf_Note_upload-top");
103 $this->type('subject', $noteSubject . "_edited");
104 $this->type('note', $noteText . "_edited");
105 $this->clickLink("_qf_Note_upload-top", "xpath=//div[@class='crm-results-block']/div[@id='notes']/div/table/tbody/tr//td/span[2]/ul/li[2]/a[text()='Delete']", FALSE);
106
107 $this->click("xpath=//div[@id='notes']/div/table/tbody/tr/td[7]/span[2]/ul/li[2]/a[text()='Delete']");
108 // Check confirmation alert.
109 $this->waitForText("xpath=//form[@id='Note']/div[@class='view-content']/div[@class='status']", "Are you sure you want to delete the note ''?");
110 $this->click("xpath=//input[@id='_qf_Note_next']");
111 $this->waitForText('crm-notification-container', "Selected Note has been deleted successfully.");
112
113 //add new relationship , disable it , delete it
114 $this->waitForElementPresent("xpath=//li[@id='tab_rel']/a");
115 $this->click("css=li#tab_rel a");
116 $this->waitForElementPresent("link=Add Relationship");
117 $this->click("link=Add Relationship");
118 $this->waitForElementPresent("_qf_Relationship_cancel");
119 $this->select("relationship_type_id", "label=Employee of");
120 $this->select2('related_contact_id', 'Default', TRUE);
121 $this->click('_qf_Relationship_upload-bottom');
122 $this->waitForElementPresent("xpath=//div[@id='contact-summary-relationship-tab']/div[2]/div/table/tbody/tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Disable']");
123
124 $this->click("xpath=//div[@id='contact-summary-relationship-tab']/div[2]/div/table/tbody/tr/td[9]/span[2][text()='more']/ul/li[1]/a[text()='Disable']");
125 $this->waitForText("xpath=//div[@class='crm-confirm-dialog ui-dialog-content ui-widget-content modal-dialog crm-ajax-container']", 'Are you sure you want to disable this relationship?');
126 $this->click("xpath=//div[@class='ui-dialog-buttonset']//button//span[text()='Yes']");
127 $this->waitForElementPresent("xpath=//div[@class='crm-contact-relationship-past']/div//table/tbody//tr/td[9]/span[2][text()='more']/ul/li[2]/a[text()='Delete']");
128 $this->click("xpath=//div[@class='crm-contact-relationship-past']/div//table/tbody//tr/td[9]/span[2][text()='more']/ul/li[2]/a[text()='Delete']");
129 $this->waitForText("xpath=//form[@id='Relationship']/div[@class='status']", "Are you sure you want to delete this Relationship?");
130 $this->click("_qf_Relationship_next-bottom");
131 $this->waitForElementPresent("link=Add Relationship");
132
133 //update existing contact
134 $this->click("xpath=//ul[@id='actions']/li[2]/a");
135 $this->waitForElementPresent("_qf_Contact_upload_view-top");
136 $firstName = "{$firstName}_edited";
137 $this->type("first_name", $firstName);
138 $this->click("_qf_Contact_upload_view-top");
139 $this->waitForPageToLoad($this->getTimeoutMsec());
140
141 //add an activity
142 $this->click("xpath=//li[@id='tab_activity']/a");
143 $this->waitForElementPresent("other_activity");
144 $this->select("other_activity", "label=Interview");
145 $this->waitForElementPresent("_qf_Activity_cancel-bottom");
146 $this->click('_qf_Activity_upload-bottom');
147 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr//td//span/a[text()='Edit']");
148 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr//td//span/a[text()='Edit']");
149 $this->waitForElementPresent("_qf_Activity_cancel-bottom");
150 $this->select("status_id", "value=2");
151 $this->waitForAjaxContent();
152 $this->click('_qf_Activity_upload-bottom');
153 $this->waitForText("crm-notification-container", "Activity has been saved.");
154 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[7]/div");
155 $this->verifyText("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[7]/div", 'Completed');
156
157 //add a case
158 $this->click("xpath=//li[@id='tab_case']/a");
159 $this->waitForElementPresent("xpath=//form[@id='Search']//div/div//div[@class='action-link']/a");
160 $this->click("xpath=//form[@id='Search']//div/div//div[@class='action-link']/a");
161 $this->waitForElementPresent("_qf_Case_cancel-bottom");
162 $this->type('activity_subject', "subject" . rand());
163 $this->select('case_type_id', 'value=1');
164 $this->click('_qf_Case_upload-bottom');
165 $this->waitForElementPresent("xpath=//table[@class='caseSelector']/tbody//tr/td[9]//span/a[1][text()='Manage']");
166 $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[9]//span/a[1][text()='Manage']");
167 $this->waitForElementPresent("xpath=//form[@id='CaseView']/div[2]/table/tbody/tr/td[4]/a");
168 $this->click("xpath=//form[@id='CaseView']/div[2]/table/tbody/tr/td[4]/a");
169 $this->waitForElementPresent("_qf_Activity_cancel-bottom");
170 $this->select("case_status_id", "value=2");
171 $this->click("_qf_Activity_upload-top");
172 $this->waitForElementPresent("_qf_CaseView_cancel-bottom");
173 $this->click("_qf_CaseView_cancel-bottom");
174 $this->waitForPageToLoad($this->getTimeoutMsec());
175
176 //visit the logging contact summary report
177 $this->openCiviPage('report/logging/contact/summary', 'reset=1');
178 $this->waitForElementPresent('altered_contact_value');
179 $this->type('altered_contact_value', $firstName);
180 $this->click("_qf_LoggingSummary_submit");
181 $this->waitForPageToLoad($this->getTimeoutMsec());
182
183 $data = array(
184 //contact data check
185 array("log_type" => "Contact", "altered_contact" => "{$firstName} {$lastName}", "action" => "Update"),
186 array("log_type" => "Contact", "altered_contact" => "{$firstName} {$lastName}", "action" => "Insert"),
187 //relationship data check
188 array(
189 "log_type" => "Relationship",
190 "altered_contact" => "{$firstName} {$lastName} [Employee of]",
191 "action" => "Update",
192 ),
193 array(
194 "log_type" => "Relationship",
195 "altered_contact" => "{$firstName} {$lastName} [Employee of]",
196 "action" => "Insert",
197 ),
198 array(
199 "log_type" => "Relationship",
200 "altered_contact" => "{$firstName} {$lastName} [Employee of]",
201 "action" => "Delete",
202 ),
203 //group data check
204 array(
205 "log_type" => "Group",
206 "altered_contact" => "{$firstName} {$lastName} [Case Resources]",
207 "action" => "Added",
208 ),
209 array(
210 "log_type" => "Group",
211 "altered_contact" => "{$firstName} {$lastName} [Case Resources]",
212 "action" => "Removed",
213 ),
214 //note data check
215 array("log_type" => "Note", "altered_contact" => "{$firstName} {$lastName}", "action" => "Update"),
216 array("log_type" => "Note", "altered_contact" => "{$firstName} {$lastName}", "action" => "Insert"),
217 array("log_type" => "Note", "altered_contact" => "{$firstName} {$lastName}", "action" => "Delete"),
218 //tags data check
219 array("log_type" => "Tag", "altered_contact" => "{$firstName} {$lastName} [Company]", "action" => "Insert"),
220 array(
221 "log_type" => "Tag",
222 "altered_contact" => "{$firstName} {$lastName} [Government Entity]",
223 "action" => "Insert",
224 ),
225 array("log_type" => "Tag", "altered_contact" => "{$firstName} {$lastName} [Company]", "action" => "Delete"),
226 //case data check
227 array(
228 "log_type" => "Case",
229 "altered_contact" => "{$firstName} {$lastName} [Housing Support]",
230 "action" => "Update",
231 ),
232 array(
233 "log_type" => "Case",
234 "altered_contact" => "{$firstName} {$lastName} [Housing Support]",
235 "action" => "Insert",
236 ),
237 //case activity check
238 array(
239 "log_type" => "Activity",
240 "altered_contact" => "{$firstName} {$lastName} [Interview]",
241 "action" => "Update",
242 ),
243 array(
244 "log_type" => "Activity",
245 "altered_contact" => "{$firstName} {$lastName} [Interview]",
246 "action" => "Insert",
247 ),
248 );
249 $this->verifyReportData($data);
250
251 //update link (logging details report check)
252 $contactInfo = array();
253 $contactInfo['data'] = array(
254 array(
255 'field' => 'Sort Name',
256 'changed_from' => "{$lastName}, {$originalFirstName}",
257 'changed_to' => "{$lastName}, {$firstName}",
258 ),
259 array(
260 'field' => 'Display Name',
261 'changed_from' => "{$originalFirstName} {$lastName}",
262 'changed_to' => "{$firstName} {$lastName}",
263 ),
264 array('field' => 'First Name', 'changed_from' => $originalFirstName, 'changed_to' => $firstName),
265 // array('field' => 'Email Greeting', 'changed_from' => "Dear {$originalFirstName}", 'changed_to' => "Dear {$firstName}"),
266 // array('field' => 'Postal Greeting', 'changed_from' => "Dear {$originalFirstName}", 'changed_to' => "Dear {$firstName}"),
267 // array('field' => 'Addressee', 'changed_from' => "{$originalFirstName} {$lastName}", 'changed_to' => "{$firstName} {$lastName}"),
268 );
269 $contactInfo = array_merge($contactInfo, $data[0]);
270
271 $relationshipInfo = array();
272 $relationshipInfo['data'] = array(
273 array('field' => 'Relationship Is Active', 'changed_from' => 'true', 'changed_to' => 'false'),
274 );
275 $relationshipInfo = array_merge($relationshipInfo, $data[2]);
276
277 $noteInfo = array();
278 $noteInfo['data'] = array(
279 array('field' => 'Note', 'changed_from' => $noteText, 'changed_to' => "{$noteText}_edited"),
280 array('field' => 'Subject', 'changed_from' => $noteSubject, 'changed_to' => "{$noteSubject}_edited"),
281 );
282 $noteInfo = array_merge($noteInfo, $data[7]);
283
284 $caseInfo = array();
285 $caseInfo['data'] = array(
286 array('field' => 'Case Status Id', 'changed_from' => 'Ongoing', 'changed_to' => "Resolved"),
287 );
288 $caseInfo = array_merge($caseInfo, $data[13]);
289
290 $activityInfo = array();
291 $activityInfo['data'] = array(
292 array('field' => 'Activity Status Id', 'changed_from' => 'Scheduled', 'changed_to' => 'Completed'),
293 );
294 $activityInfo = array_merge($activityInfo, $data[15]);
295
296 $dataForReportDetail = array($contactInfo, $relationshipInfo, $noteInfo, $caseInfo, $activityInfo);
297 $filters = array(
298 'text' => array('altered_contact_value' => "{$firstName} {$lastName}"),
299 );
300 $this->detailReportCheck($dataForReportDetail, $filters);
301
302 //delete contact check
303 $this->openCiviPage('contact/view/delete', "reset=1&delete=1&cid=$cid");
304 $this->click("_qf_Delete_done");
305 $this->waitForPageToLoad($this->getTimeoutMsec());
306
307 $this->openCiviPage('report/logging/contact/summary', 'reset=1');
308 $this->click("_qf_LoggingSummary_submit");
309 $this->waitForPageToLoad($this->getTimeoutMsec());
310
311 $contactDataDelete = array(
312 array(
313 "log_type" => "Contact",
314 "altered_contact" => "{$firstName} {$lastName}",
315 "action" => "Delete (to trash)",
316 ),
317 );
318 $this->verifyReportData($contactDataDelete);
319
320 //disable the logging
321 $this->openCiviPage('admin/setting/misc', 'reset=1');
322 $this->waitForElementPresent("xpath=//tr[@class='crm-miscellaneous-form-block-logging']/td[2]/label[text()='No']");
323 $this->click("xpath=//tr[@class='crm-miscellaneous-form-block-logging']/td[2]/label[text()='No']");
324 $this->click("_qf_Miscellaneous_next-top");
325 $this->waitForTextPresent("Changes Saved");
326 }
327
328 /**
329 * @param $data
330 */
331 public function verifyReportData($data) {
332 foreach ($data as $value) {
333 // check for the row contains proper data
334 $actionPath = ($value['action'] == 'Update') ? "td[1]/a[2]" : "td[1][contains(text(), '{$value['action']}')]";
335 $contactCheck = ($value['action'] == 'Delete (to trash)') ? "td[4][contains(text(), '{$value['altered_contact']}')]" : "td[4]/a[contains(text(), '{$value['altered_contact']}')]/..";
336
337 $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[2][contains(text(), '{$value['log_type']}')]/../{$contactCheck}/../{$actionPath}"), "The proper record not present for (log type : {$value['log_type']}, altered contact : {$value['altered_contact']}, action as {$value['action']})");
338
339 if ($value['action'] == 'Update') {
340 $this->assertTrue(($value['action'] == $this->getText("xpath=//table/tbody//tr/td[2][contains(text(), '{$value['log_type']}')]/../td[4]/a[contains(text(), '{$value['altered_contact']}')]/../../{$actionPath}")), "The proper record action {$value['action']} not present for (log type : {$value['log_type']}, altered contact : {$value['altered_contact']} record)");
341 }
342 }
343 }
344
345 /**
346 * @param $dataForReportDetail
347 * @param array $filters
348 */
349 public function detailReportCheck($dataForReportDetail, $filters = array()) {
350 foreach ($dataForReportDetail as $value) {
351 $this->waitForElementPresent("xpath=//table/tbody//tr/td[2][contains(text(), '{$value['log_type']}')]/../td[4]/a[contains(text(), '{$value['altered_contact']}')]/../../td[1]/a[2]");
352 $this->click("xpath=//table/tbody//tr/td[2][contains(text(), '{$value['log_type']}')]/../td[4]/a[contains(text(), '{$value['altered_contact']}')]/../../td[1]/a[2]");
353 $this->waitForPageToLoad($this->getTimeoutMsec());
354
355 foreach ($value['data'] as $key => $data) {
356 $rowCount = $this->getXpathCount("//table[@class='report-layout display']/tbody/tr");
357 for ($i = 1; $i <= $rowCount; $i++) {
358 $field = $data['field'];
359 if ($this->isElementPresent("xpath=//form[@id='LoggingDetail']//table/tbody/tr[{$i}]/td[@class='crm-report-field'][text()='$field']")) {
360 $this->verifyText("xpath=//form[@id='LoggingDetail']//table/tbody/tr[{$i}]/td[@class='crm-report-field']", preg_quote($data['field']));
361 $this->verifyText("xpath=//form[@id='LoggingDetail']//table/tbody/tr[{$i}]/td[@class='crm-report-from']", preg_quote($data['changed_from']));
362 $this->verifyText("xpath=//form[@id='LoggingDetail']//table/tbody/tr[{$i}]/td[@class='crm-report-to']", preg_quote($data['changed_to']));
363 }
364 }
365 }
366
367 //visit the logging contact summary report
368 $this->openCiviPage('report/logging/contact/summary', 'reset=1');
369 foreach ($filters as $type => $filter) {
370 if ($type == 'text') {
371 foreach ($filter as $filterName => $filterValue) {
372 $this->type($filterName, $filterValue);
373 }
374 }
375 }
376 $this->click("_qf_LoggingSummary_submit");
377 $this->waitForPageToLoad($this->getTimeoutMsec());
378 }
379 }
380
381 }