4e736a347fe6a525e5c844c09329a05eda1a0a87
[civicrm-core.git] / tests / phpunit / WebTest / Report / LoggingReportTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Report_LoggingReportTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testLoggingReport() {
36 $this->webtestLogin();
37
38 //enable the logging
39 $this->openCiviPage('admin/setting/misc', 'reset=1');
40 $this->click("xpath=//tr[@class='crm-miscellaneous-form-block-logging']/td[2]/label[text()='Yes']");
41 $this->click("_qf_Miscellaneous_next-top");
42 $this->waitForTextPresent("Changes Saved");
43
44 //enable CiviCase component
45 $this->enableComponents("CiviCase");
46
47 //add new contact
48 $orginalFirstName = $firstName = 'Anthony' . substr(sha1(rand()), 0, 7);
49 $lastName = 'Anderson' . substr(sha1(rand()), 0, 7);
50
51 $this->webtestAddContact($firstName, $lastName);
52 $cid = explode('&cid=', $this->getLocation());
53
54 //add contact to group
55 $this->waitForElementPresent("xpath=//li[@id='tab_group']/a");
56 $this->click("xpath=//li[@id='tab_group']/a");
57 sleep(3);
58 $this->select("group_id", "label=Case Resources");
59 $this->click("_qf_GroupContact_next");
60
61 $this->waitForPageToLoad($this->getTimeoutMsec());
62 $this->waitForElementPresent("xpath=//div[@id='groupContact']/div/div[4]/table/tbody/tr/td[4]/a");
63 $this->click("xpath=//div[@id='groupContact']/div/div[4]/table/tbody/tr/td[4]/a");
64
65 // Check confirmation alert.
66 $this->assertTrue((bool)preg_match("/^Are you sure you want to remove/",
67 $this->getConfirmation()
68 ));
69 $this->chooseOkOnNextConfirmation();
70 $this->waitForPageToLoad($this->getTimeoutMsec());
71
72 //tag addition
73 $this->waitForElementPresent("xpath=//li[@id='tab_tag']/a");
74 $this->click("xpath=//li[@id='tab_tag']/a");
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");
86 sleep(3);
87 $this->click("xpath=//div[@id='Notes']//div[@class='action-link']/a");
88
89 $this->waitForElementPresent("_qf_Note_upload-top");
90 $noteSubject = "test note" . substr(sha1(rand()), 0, 7);
91 $noteText = "test note text" . substr(sha1(rand()), 0, 7);
92 $this->type('subject', $noteSubject);
93 $this->type('note', $noteText);
94 $this->click("_qf_Note_upload-top");
95 $this->waitForElementPresent("xpath=//div[@id='notes']//a[text()='Edit']");
96 $this->click("xpath=//div[@id='notes']//a[text()='Edit']");
97
98 $this->waitForElementPresent("_qf_Note_upload-top");
99 $this->type('subject', $noteSubject . "_edited");
100 $this->type('note', $noteText . "_edited");
101 $this->click("_qf_Note_upload-top");
102
103 $this->waitForElementPresent("xpath=//div[@class='crm-results-block']/div[@id='notes']/div/table/tbody/tr//td/span[2]/ul/li[2]/a[text()='Delete']");
104 $this->click("xpath=//div[@class='crm-results-block']/div[@id='notes']/div/table/tbody/tr//td/span[2]/ul/li[2]/a[text()='Delete']");
105 // Check confirmation alert.
106 $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this note/",
107 $this->getConfirmation()
108 ));
109 $this->chooseOkOnNextConfirmation();
110 $this->waitForPageToLoad($this->getTimeoutMsec());
111
112 //add new relationship , disable it , delete it
113 $this->waitForElementPresent("xpath=//li[@id='tab_rel']/a");
114 $this->click("xpath=//li[@id='tab_rel']/a");
115 sleep(3);
116 $this->click("xpath=//div[@id='Relationships']//div[@class='action-link']/a");
117 $this->waitForElementPresent("_qf_Relationship_refresh");
118 $this->select("relationship_type_id", "label=Employee of");
119 $this->webtestFillAutocomplete("Default Organization");
120 $this->waitForElementPresent("quick-save");
121 $this->click("quick-save");
122 $this->waitForPageToLoad($this->getTimeoutMsec());
123 $this->waitForElementPresent("xpath=//div[@id='current-relationships']//a[text()='Disable']");
124 $this->click("xpath=//div[@id='current-relationships']//a[text()='Disable']");
125 $this->assertTrue((bool)preg_match("/^Are you sure you want to disable this relationship/",
126 $this->getConfirmation()
127 ));
128 $this->chooseOkOnNextConfirmation();
129 $this->waitForPageToLoad($this->getTimeoutMsec());
130 $this->waitForElementPresent(" xpath=//div[@id='inactive-relationships']//a[text()='Delete']");
131 $this->click("xpath=//div[@id='inactive-relationships']//a[text()='Delete']");
132 $this->assertTrue((bool)preg_match("/^Are you sure you want to delete this relationship/",
133 $this->getConfirmation()
134 ));
135 $this->chooseOkOnNextConfirmation();
136 $this->waitForPageToLoad($this->getTimeoutMsec());
137
138 //update existing contact
139 $this->click("xpath=//ul[@id='actions']/li[2]/a");
140 $this->waitForElementPresent("_qf_Contact_upload_view-top");
141 $firstName = "{$firstName}_edited";
142 $this->type("first_name", $firstName);
143 $this->click("_qf_Contact_upload_view-top");
144 $this->waitForPageToLoad($this->getTimeoutMsec());
145
146 //add an activity
147 $this->click("xpath=//li[@id='tab_activity']/a");
148 $this->waitForElementPresent("other_activity");
149 $this->select("other_activity", "label=Interview");
150 $this->waitForPageToLoad($this->getTimeoutMsec());
151 $this->click('_qf_Activity_upload-bottom');
152 $this->waitForElementPresent("xpath=//table[@id='contact-activity-selector-activity']/tbody/tr/td[9]/span/a[2]");
153 $this->click("xpath=//table[@id='contact-activity-selector-activity']/tbody/tr/td[9]/span/a[2]");
154 $this->waitForPageToLoad($this->getTimeoutMsec());
155 $this->select("status_id","value=2");
156 $this->click('_qf_Activity_upload-bottom');
157 $this->waitForPageToLoad($this->getTimeoutMsec());
158
159 //add a case
160 $this->click("xpath=//li[@id='tab_case']/a");
161 $this->waitForElementPresent("xpath=//div[@id='Cases']//div[@class='action-link']/a");
162 $this->click("xpath=//div[@id='Cases']//div[@class='action-link']/a");
163 $this->waitForPageToLoad($this->getTimeoutMsec());
164 $this->type('activity_subject',"subject".rand());
165 $this->select('case_type_id','value=1');
166 $this->click('_qf_Case_upload-bottom');
167 $this->waitForPageToLoad($this->getTimeoutMsec());
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->waitForPageToLoad($this->getTimeoutMsec());
173
174 //visit the logging contact summary report
175 $this->openCiviPage('report/logging/contact/summary', 'reset=1');
176 $this->type('altered_contact_value', $firstName);
177 $this->click("_qf_LoggingSummary_submit");
178 $this->waitForPageToLoad($this->getTimeoutMsec());
179
180 $data = array(
181 //contact data check
182 array("log_type" => "Contact", "altered_contact" => "{$firstName} {$lastName}", "action" => "Update"),
183 array("log_type" => "Contact", "altered_contact" => "{$firstName} {$lastName}", "action" => "Insert"),
184 //relationship data check
185 array("log_type" => "Relationship", "altered_contact" => "{$firstName} {$lastName} [Employee of]", "action" => "Update"),
186 array("log_type" => "Relationship", "altered_contact" => "{$firstName} {$lastName} [Employee of]", "action" => "Insert"),
187 array("log_type" => "Relationship", "altered_contact" => "{$firstName} {$lastName} [Employee of]", "action" => "Delete"),
188 //group data check
189 array("log_type" => "Group", "altered_contact" => "{$firstName} {$lastName} [Case Resources]", "action" => "Added"),
190 array("log_type" => "Group", "altered_contact" => "{$firstName} {$lastName} [Case Resources]", "action" => "Removed"),
191 //note data check
192 array("log_type" => "Note", "altered_contact" => "{$firstName} {$lastName}", "action" => "Update"),
193 array("log_type" => "Note", "altered_contact" => "{$firstName} {$lastName}", "action" => "Insert"),
194 array("log_type" => "Note", "altered_contact" => "{$firstName} {$lastName}", "action" => "Delete"),
195 //tags data check
196 array("log_type" => "Tag", "altered_contact" => "{$firstName} {$lastName} [Company]", "action" => "Insert"),
197 array("log_type" => "Tag", "altered_contact" => "{$firstName} {$lastName} [Government Entity]", "action" => "Insert"),
198 array("log_type" => "Tag", "altered_contact" => "{$firstName} {$lastName} [Company]", "action" => "Delete"),
199 //case data check
200 array("log_type" => "Case", "altered_contact" => "{$firstName} {$lastName} [Housing Support]", "action" => "Update"),
201 array("log_type" => "Case", "altered_contact" => "{$firstName} {$lastName} [Housing Support]", "action" => "Insert"),
202 //case activity check
203 array("log_type" => "Activity", "altered_contact" => "{$firstName} {$lastName} [Interview]", "action" => "Update"),
204 array("log_type" => "Activity", "altered_contact" => "{$firstName} {$lastName} [Interview]", "action" => "Insert"),
205 );
206 $this->verifyReportData($data);
207
208 //update link (logging details report check)
209 $contactInfo = array();
210 $contactInfo['data'] = array(
211 array('field' => 'Sort Name', 'changed_from' => "{$lastName}, {$orginalFirstName}", 'changed_to' => "{$lastName}, {$firstName}"),
212 array('field' => 'Display Name', 'changed_from' => "{$orginalFirstName} {$lastName}", 'changed_to' => "{$firstName} {$lastName}"),
213 array('field' => 'First Name', 'changed_from' => $orginalFirstName, 'changed_to' => $firstName),
214 // array('field' => 'Email Greeting', 'changed_from' => "Dear {$orginalFirstName}", 'changed_to' => "Dear {$firstName}"),
215 // array('field' => 'Postal Greeting', 'changed_from' => "Dear {$orginalFirstName}", 'changed_to' => "Dear {$firstName}"),
216 // array('field' => 'Addressee', 'changed_from' => "{$orginalFirstName} {$lastName}", 'changed_to' => "{$firstName} {$lastName}"),
217 );
218 $contactInfo = array_merge($contactInfo, $data[0]);
219
220 $relationshipInfo = array();
221 $relationshipInfo['data'] = array(
222 array('field' => 'Relationship Is Active', 'changed_from' => 'true', 'changed_to' => 'false')
223 );
224 $relationshipInfo = array_merge($relationshipInfo, $data[2]);
225
226 $noteInfo = array();
227 $noteInfo['data'] = array(
228 array('field' => 'Note', 'changed_from' => $noteText, 'changed_to' => "{$noteText}_edited"),
229 array('field' => 'Subject', 'changed_from' => $noteSubject, 'changed_to' => "{$noteSubject}_edited"),
230 );
231 $noteInfo = array_merge($noteInfo, $data[7]);
232
233 $caseInfo = array();
234 $caseInfo['data'] = array(
235 array('field' => 'Case Status Id', 'changed_from' => 'Ongoing', 'changed_to' => "Resolved"),
236 );
237 $caseInfo = array_merge($caseInfo, $data[13]);
238
239 $activityInfo = array();
240 $activityInfo['data'] = array(
241 array('field' => 'Activity Status Id', 'changed_from' => 'Scheduled', 'changed_to' => 'Completed'),
242 );
243 $activityInfo = array_merge($activityInfo, $data[15]);
244
245 $dataForReportDetail = array($contactInfo, $relationshipInfo, $noteInfo, $caseInfo, $activityInfo);
246 $filters = array(
247 'text' => array('altered_contact_value' => "{$firstName} {$lastName}"),
248 );
249 $this->detailReportCheck($dataForReportDetail, $filters);
250
251 //delete contact check
252 $this->openCiviPage('contact/view/delete', "reset=1&delete=1&cid={$cid[1]}");
253 $this->click("_qf_Delete_done");
254 $this->waitForPageToLoad($this->getTimeoutMsec());
255
256 $this->openCiviPage('report/logging/contact/summary', 'reset=1');
257 $this->click("_qf_LoggingSummary_submit");
258 $this->waitForPageToLoad($this->getTimeoutMsec());
259
260 $contactDataDelete = array(array("log_type" => "Contact", "altered_contact" => "{$firstName} {$lastName}", "action" => "Delete (to trash)"));
261 $this->verifyReportData($contactDataDelete);
262
263 //disable the logging
264 $this->openCiviPage('admin/setting/misc', 'reset=1');
265 $this->click("xpath=//tr[@class='crm-miscellaneous-form-block-logging']/td[2]/label[text()='No']");
266 $this->click("_qf_Miscellaneous_next-top");
267 $this->waitForTextPresent("Changes Saved");
268 }
269
270 function verifyReportData($data) {
271 foreach ($data as $value) {
272 // check for the row contains proper data
273 $actionPath = ($value['action'] == 'Update') ? "td[1]/a[2]" : "td[1][contains(text(), '{$value['action']}')]";
274 $contactCheck = ($value['action'] == 'Delete (to trash)') ? "td[4][contains(text(), '{$value['altered_contact']}')]" : "td[4]/a[contains(text(), '{$value['altered_contact']}')]/..";
275
276 $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']})");
277
278 if ($value['action'] == 'Update') {
279 $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)");
280 }
281 }
282 }
283
284 function detailReportCheck($dataForReportDetail, $filters = array()) {
285 foreach ($dataForReportDetail as $value) {
286 $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]");
287 $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]");
288 $this->waitForPageToLoad($this->getTimeoutMsec());
289
290 foreach ($value['data'] as $key => $data) {
291 $rowCount = $this->getXpathCount("//table[@class='report-layout display']/tbody/tr");
292 for ($i = 1; $i <= $rowCount; $i++) {
293 $field = $data['field'];
294 if ($this->isElementPresent("xpath=//form[@id='LoggingDetail']//table/tbody/tr[{$i}]/td[@class='crm-report-field'][text()='$field']")) {
295 $this->verifyText("xpath=//form[@id='LoggingDetail']//table/tbody/tr[{$i}]/td[@class='crm-report-field']", preg_quote($data['field']));
296 $this->verifyText("xpath=//form[@id='LoggingDetail']//table/tbody/tr[{$i}]/td[@class='crm-report-from']", preg_quote($data['changed_from']));
297 $this->verifyText("xpath=//form[@id='LoggingDetail']//table/tbody/tr[{$i}]/td[@class='crm-report-to']", preg_quote($data['changed_to']));
298 }
299 }
300 }
301
302 //visit the logging contact summary report
303 $this->openCiviPage('report/logging/contact/summary', 'reset=1');
304 foreach ($filters as $type => $filter) {
305 if ($type == 'text' ) {
306 foreach ($filter as $filterName => $filterValue) {
307 $this->type($filterName, $filterValue);
308 }
309 }
310 }
311 $this->click("_qf_LoggingSummary_submit");
312 $this->waitForPageToLoad($this->getTimeoutMsec());
313 }
314 }
315 }