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