Additional webtest error check
[civicrm-core.git] / tests / phpunit / WebTest / Case / ActivityToCaseTest.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 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Case_ActivityToCaseTest
31 */
6a488035
TO
32class WebTest_Case_ActivityToCaseTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testAddActivityToCase() {
6a488035 39 // Log in as admin first to verify permissions for CiviCase
80f3b91d 40 $this->webtestLogin('admin');
6a488035
TO
41
42 // Enable CiviCase module if necessary
b9715b8a 43 $this->enableComponents("CiviCase");
6a488035
TO
44
45 // let's give full CiviCase permissions to demo user (registered user).
46 $permission = array('edit-2-access-all-cases-and-activities', 'edit-2-access-my-cases-and-activities', 'edit-2-administer-civicase', 'edit-2-delete-in-civicase');
47 $this->changePermissions($permission);
48
42daf119
CW
49 // Log in as normal user
50 $this->webtestLogin();
51
d2771e94 52 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
6a488035
TO
53
54 // Adding contact with randomized first name (so we can then select that contact when creating case)
55 // We're using pop-up New Contact dialog
80f3b91d 56 $contact = $this->createDialogContact("client_id");
6a488035
TO
57
58 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
59 $caseTypeLabel = "Adult Day Care Referral";
60 $subject = "Safe daytime setting - senior female";
61 $this->select('medium_id', 'value=1');
62 $this->type('activity_location', 'Main offices');
63 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
64 $this->fillRichTextField("activity_details", $details, 'CKEditor');
65 $this->type('activity_subject', $subject);
66
67 $this->select('case_type_id', "label={$caseTypeLabel}");
68
69 // Choose Case Start Date.
70 // Using helper webtestFillDate function.
71 $this->webtestFillDate('start_date', 'now');
72 $today = date('F jS, Y', strtotime('now'));
76e86fd8 73
6a488035 74 $this->type('duration', "20");
44c45561 75 $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom', FALSE);
6a488035
TO
76
77 // Is status message correct?
80f3b91d 78 $this->checkCRMAlert("Case opened successfully.");
6a488035
TO
79 $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 7);
80
80f3b91d 81 $this->_testAddNewActivity($contact['first_name'], $subject, $customGroupTitle, $contact['sort_name']);
6a488035
TO
82 }
83
8e05e179
JP
84 function testLinkCases() {
85 $this->webtestLogin();
3f4fcdb9
RK
86
87 // Enable CiviCase module if necessary
ca70bd72 88 $this->enableComponents("CiviCase");
3f4fcdb9 89
8e05e179
JP
90 //Add Case 1
91 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
92
93 // Adding contact with randomized first name (so we can then select that contact when creating case)
94 // We're using pop-up New Contact dialog
80f3b91d 95 $contact1 = $this->createDialogContact('client_id');
8e05e179
JP
96
97 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
98 $caseTypeLabel = "Adult Day Care Referral";
99 $subject = "Safe daytime setting - senior female";
100 $this->select('medium_id', 'value=1');
101 $this->type('activity_location', 'Main offices');
102 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
103 $this->fillRichTextField("activity_details", $details, 'CKEditor');
104 $this->type('activity_subject', $subject);
105
106 $this->select('case_type_id', "label={$caseTypeLabel}");
107
108 // Choose Case Start Date.
109 // Using helper webtestFillDate function.
110 $this->webtestFillDate('start_date', 'now');
111 $today = date('F jS, Y', strtotime('now'));
112
113 $this->type('duration', "20");
80f3b91d 114 $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom');
8e05e179
JP
115
116 // Is status message correct?
80f3b91d 117 $this->checkCRMAlert("Case opened successfully.");
8e05e179
JP
118
119 //Add Case 2
120 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
121
122 // Adding contact with randomized first name (so we can then select that contact when creating case)
123 // We're using pop-up New Contact dialog
80f3b91d 124 $contact2 = $this->createDialogContact('client_id');
8e05e179
JP
125
126 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
127 $caseTypeLabel2 = "Adult Day Care Referral";
128 $subject2 = "Subject For Case 2";
129 $this->select('medium_id', 'value=1');
130 $this->type('activity_location', 'Main offices');
131 $details2 = "Details For Case 2";
132 $this->fillRichTextField("activity_details", $details2, 'CKEditor');
133 $this->type('activity_subject', $subject2);
134
135 $this->select('case_type_id', "label={$caseTypeLabel2}");
136
137 // Choose Case Start Date.
138 // Using helper webtestFillDate function.
139 $this->webtestFillDate('start_date', 'now');
140 $today = date('F jS, Y', strtotime('now'));
141
142 $this->type('duration', "20");
80f3b91d 143 $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom');
8e05e179
JP
144
145 // Is status message correct?
80f3b91d 146 $this->checkCRMAlert("Case opened successfully.");
8e05e179 147
80f3b91d
CW
148 // We should now be on the "manage case" screen for case 2
149 //Add Link Case Activity to case 1
8e05e179
JP
150 $this->select('add_activity_type_id', 'Link Cases');
151 $this->waitForElementPresent("_qf_Activity_cancel-bottom");
80f3b91d 152 $this->select2('link_to_case_id', $contact1['sort_name']);
8e05e179
JP
153 $activitydetails = 'Details of Link Case Activity';
154 $this->fillRichTextField("details", $activitydetails, 'CKEditor');
80f3b91d
CW
155 $this->click('css=#activity-details .crm-accordion-header');
156 $this->waitForVisible('subject');
8e05e179
JP
157 $activitySubject = 'Link Case Activity between case 1 and case 2';
158 $activitylocation = 'Main Office Building';
80f3b91d 159 $this->select2('source_contact_id', $contact2['sort_name']);
8e05e179
JP
160 $this->type('subject', $activitySubject);
161 $this->type('location', $activitylocation);
80f3b91d 162 $this->clickAjaxLink('_qf_Activity_upload-bottom');
8e05e179
JP
163 $id = $this->urlArg('id');
164 $this->waitForText("case_id_$id", $activitySubject);
165 $this->click("xpath=//a[contains(text(),'$activitySubject')]");
166
167 $LinkCaseActivityData = array(
80f3b91d 168 "Client" => $contact2['first_name'],
8e05e179
JP
169 "Activity Type" => "Link Cases",
170 "Subject" => $activitySubject,
80f3b91d 171 "Reported By" => $contact2['display_name'],
8e05e179
JP
172 "Medium" => "Phone",
173 "Location" => $activitylocation,
174 "Date and Time" => $today,
175 "Details" => $activitydetails,
176 "Status" => "Scheduled",
177 "Priority" => "Normal",
178 );
179 $this->webtestVerifyTabularData($LinkCaseActivityData);
180 }
4cbe18b8
EM
181 /**
182 * @param $firstName
183 * @param $caseSubject
184 * @param $customGroupTitle
185 * @param $contactName
186 */
6a488035
TO
187 function _testAddNewActivity($firstName, $caseSubject, $customGroupTitle, $contactName) {
188 $customDataParams = $this->_addCustomData($customGroupTitle);
189 //$customDataParams = array( 'optionLabel_47d58', 'custom_8_-1' );
190
191 // Adding Adding contact with randomized first name for test testContactContextActivityAdd
192 // We're using Quick Add block on the main page for this.
193 $firstName1 = substr(sha1(rand()), 0, 7);
194 $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name");
195 $firstName2 = substr(sha1(rand()), 0, 7);
196 $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name");
197
6a488035
TO
198 $this->click("css=li#tab_activity a");
199
200 // waiting for the activity dropdown to show up
201 $this->waitForElementPresent("other_activity");
202
203 // Select the activity type from the activity dropdown
204 $this->select("other_activity", "label=Meeting");
205
206 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
207 // button at the end of this page to show up, to make sure it's fully loaded.
208 $this->waitForElementPresent("_qf_Activity_upload-bottom");
209
6a488035 210 // ...and verifying if the page contains properly formatted display name for chosen contact.
44c45561 211 $this->waitForText("xpath=//div[@id='s2id_target_contact_id']", 'Anderson, ' . $firstName2, "Contact not found in line " . __LINE__);
6a488035
TO
212
213 // Now we're filling the "Assigned To" field.
214 // Typing contact's name into the field (using typeKeys(), not type()!)...
44c45561 215 $this->click("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input");
216 $this->keyDown("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", " ");
217 $this->type("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName1);
218 $this->typeKeys("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName1);
6a488035
TO
219
220 // ...waiting for drop down with results to show up...
44c45561 221 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
6a488035
TO
222
223 //..need to use mouseDownAt on first result (which is a li element), click does not work
44c45561 224 $this->clickAt("xpath=//div[@class='select2-result-label']");
6a488035
TO
225
226 // ...again, waiting for the box with contact name to show up...
44c45561 227 $this->waitForText("xpath=//div[@id='s2id_assignee_contact_id']","$firstName1");
6a488035
TO
228
229 // ...and verifying if the page contains properly formatted display name for chosen contact.
44c45561 230 $this->assertElementContainsText("xpath=//div[@id='s2id_assignee_contact_id']", "Summerson, $firstName1", 'Contact not found in line ' . __LINE__);
6a488035
TO
231
232 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
233 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
234 // For simple input fields we can use field id as selector
235 $this->type("subject", $subject);
236 $this->type("location", "Some location needs to be put in this field.");
237
238 // Choosing the Date.
239 // Please note that we don't want to put in fixed date, since
240 // we want this test to work in the future and not fail because
241 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
242 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
243
244 // Setting duration.
245 $this->type("duration", "30");
246
247 // Putting in details.
248 $this->type("details", "Really brief details information.");
249
250 // Making sure that status is set to Scheduled (using value, not label).
251 $this->select("status_id", "value=1");
252
253 // Setting priority.
254 $this->select("priority_id", "value=1");
255
256 $textField = 'This is test custom data';
44c45561 257 $this->click("xpath=//div[@id='customData']//div[@class='custom-group custom-group-$customGroupTitle crm-accordion-wrapper collapsed']");
258 $this->waitForElementPresent("xpath=//div[@class='crm-accordion-body']//table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/input");
259 $this->click("xpath=//div[@class='crm-accordion-body']//table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/input");
6a488035
TO
260 $this->type($customDataParams[1], $textField);
261
262 // Scheduling follow-up.
263 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
264 $this->select("followup_activity_type_id", "value=1");
265 $this->webtestFillDateTime('followup_date', '+2 months 10:00AM');
266 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
267
268 // Clicking save.
269 $this->click("_qf_Activity_upload-bottom");
6a488035
TO
270
271 // Is status message correct?
6c5f7368 272 $this->waitForText('crm-notification-container', $subject);
6a488035
TO
273
274 // click through to the Activity view screen
ca70bd72
RK
275 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr/td[5]/a[text()='Summerson, $firstName1']/../../td[8]/span/a[1][text()='View']");
276 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr/td[5]/a[text()='Summerson, $firstName1']/../../td[8]/span/a[1][text()='View']");
277 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr/td[5]/a[text()='Summerson, $firstName1']/../../td[8]/span[2][text()='more']/ul[1]/li[1]/a");
278 $this->click("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr/td[5]/a[text()='Summerson, $firstName1']/../../td[8]/span[2][text()='more']/ul[1]/li[1]/a");
6a488035
TO
279
280 // file activity on case
ca70bd72 281 $this->waitForElementPresent('file_on_case_unclosed_case_id');
44c45561 282 $this->select2('file_on_case_unclosed_case_id', $firstName);
283 $this->assertElementContainsText("xpath=//div[@id='s2id_file_on_case_unclosed_case_id']", "$firstName", 'Contact not found in line ' . __LINE__);
ca70bd72 284 $this->type('file_on_case_activity_subject', $subject);
44c45561 285 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Save']");
ca70bd72 286 $this->waitForElementPresent("xpath=//div[@class='dataTables_wrapper no-footer']/table/tbody//tr/td[5]/a[text()='Summerson, $firstName1']/../../td[8]/span/a[1][text()='View']");
6a488035
TO
287
288 // verify if custom data is present
d2771e94 289 $this->openCiviPage('case', 'reset=1');
6a488035
TO
290 $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']");
291
292 $this->waitForElementPresent('_qf_CaseView_cancel-bottom');
44c45561 293 $id = $this->urlArg('id');
294 $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='case_id_".$id."']/tbody/tr[1]/td[2]");
6a488035 295
44c45561 296 $this->click("xpath=//div[@id='activities']//table[@id='case_id_".$id."']/tbody/tr[1]/td[2]//a[text()='{$subject}']");
6a488035 297
44c45561 298 $this->waitForElementPresent('ActivityView');
6a488035 299 $this->waitForElementPresent("css=table#crm-activity-view-table tr.crm-case-activityview-form-block-groupTitle");
d2771e94 300 $this->assertElementContainsText('crm-activity-view-table', "$textField");
44c45561 301 $this->click("xpath=//span[@class='ui-button-icon-primary ui-icon ui-icon-closethick']");
302 $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='case_id_".$id."']/tbody/tr[1]/td[2]");
6a488035 303
44c45561 304 $this->click("xpath=//div[@id='activities']//table[@id='case_id_".$id."']/tbody//tr/td[2]/a[text()='{$subject}']/../../td[6]/a[text()='Scheduled']");
6a488035 305
baaf85ee 306 $this->waitForElementPresent("xpath=//html/body/div[7]");
6a488035
TO
307 $this->waitForElementPresent('activity_change_status');
308
309 // change activity status
310 $this->select('activity_change_status', 'value=2');
e1326164 311 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[text()='Continue']");
d2771e94 312 $this->openCiviPage('case', 'reset=1');
6a488035
TO
313 $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']");
314 $this->waitForElementPresent('_qf_CaseView_cancel-bottom');
44c45561 315 $id2 = $this->urlArg('id');
316 $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='case_id_".$id2."']/tbody/tr[1]/td[2]");
317 $this->click("xpath=//div[@id='activities']//table[@id='case_id_".$id2."']//a[text()='{$subject}']");
318 $this->waitForElementPresent('ActivityView');
6a488035
TO
319 $this->waitForElementPresent("css=table#crm-activity-view-table tr.crm-case-activityview-form-block-groupTitle");
320 }
321
4cbe18b8
EM
322 /**
323 * @param $customGroupTitle
324 *
325 * @return array
326 */
6a488035 327 function _addCustomData($customGroupTitle) {
42daf119 328
d2771e94 329 $this->openCiviPage('admin/custom/group', 'reset=1');
6a488035
TO
330
331 //add new custom data
57e9cdaf 332 $this->clickLink("//a[@id='newCustomDataGroup']/span");
6a488035
TO
333
334 //fill custom group title
335 $this->click("title");
336 $this->type("title", $customGroupTitle);
337
338 //custom group extends
339 $this->click("extends[0]");
340 $this->select("extends[0]", "value=Activity");
341 $this->click("//option[@value='Activity']");
7df6dc24 342 $this->clickLink('_qf_Group_next-bottom');
6a488035
TO
343
344 //Is custom group created?
6c5f7368 345 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
6a488035
TO
346
347 // create a custom field - Integer Radio
57e9cdaf 348 $this->clickLinkSuppressPopup('newCustomField', "data_type[0]");
6a488035
TO
349 $this->click("data_type[0]");
350 $this->select("data_type[0]", "value=1");
351 $this->click("//option[@value='1']");
352 $this->click("data_type[1]");
353 $this->select("data_type[1]", "value=Radio");
354 $this->click("//option[@value='Radio']");
355
356 $radioFieldLabel = 'Custom Field Radio_' . substr(sha1(rand()), 0, 4);
357 $this->type("label", $radioFieldLabel);
358 $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
359 $this->type("option_label_1", $radioOptionLabel1);
360 $this->type("option_value_1", "1");
361 $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
362 $this->type("option_label_2", $radioOptionLabel2);
363 $this->type("option_value_2", "2");
364
365 //select options per line
366 $this->type("options_per_line", "3");
367
368 //enter pre help msg
369 $this->type("help_pre", "this is field pre help");
370
371 //enter post help msg
372 $this->type("help_post", "this is field post help");
373
374 //Is searchable?
375 $this->click("is_searchable");
376
377 //clicking save
57e9cdaf 378 $this->clickLink("_qf_Field_next_new-bottom", "_qf_Field_next_new-bottom");
6a488035
TO
379
380 //Is custom field created
44c45561 381 $this->waitForText('crm-notification-container', "Custom field '$radioFieldLabel' has been saved.");
6a488035
TO
382
383 // create another custom field - text field
6a488035
TO
384 $textFieldLabel = 'Custom Field Text_' . substr(sha1(rand()), 0, 4);
385 $this->type('label', $textFieldLabel);
386
387 //enter pre help msg
388 $this->type('help_pre', "this is field pre help");
389
390 //enter post help msg
391 $this->type('help_post', "this is field post help");
392
393 //Is searchable?
394 $this->click('is_searchable');
395
396 //clicking save
57e9cdaf 397 $this->clickLink("_qf_Field_done-bottom", "//a[@id='newCustomField']/span");
6a488035
TO
398
399 //Is custom field created
44c45561 400 $this->waitForText('crm-notification-container', "Custom field '$textFieldLabel' has been saved.");
ca70bd72 401 $textFieldId = explode('&id=', $this->getAttribute("xpath=//table[@id='options']/tbody//tr/td[1]/span[text()='$textFieldLabel']/../../td[8]/span/a[1][text()='Edit Field']/@href"));
6a488035
TO
402 $textFieldId = $textFieldId[1];
403
404 return array($radioOptionLabel1, "custom_{$textFieldId}_-1");
405 }
406}
407