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