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