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