3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Case_ActivityToCaseTest
32 class WebTest_Case_ActivityToCaseTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testAddActivityToCase() {
39 $this->markTestSkipped('Skipping for now as it works fine locally.');
40 // Log in as admin first to verify permissions for CiviCase
41 $this->webtestLogin('admin');
43 // Enable CiviCase module if necessary
44 $this->enableComponents("CiviCase");
46 // let's give full CiviCase permissions to demo user (registered user).
48 'edit-2-access-all-cases-and-activities',
49 'edit-2-access-my-cases-and-activities',
50 'edit-2-administer-civicase',
51 'edit-2-delete-in-civicase',
53 $this->changePermissions($permission);
55 // Log in as normal user
56 $this->webtestLogin();
58 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
60 // Adding contact with randomized first name (so we can then select that contact when creating case)
61 // We're using pop-up New Contact dialog
62 $contact = $this->createDialogContact("client_id");
64 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
65 $caseTypeLabel = "Adult Day Care Referral";
66 $subject = "Safe daytime setting - senior female";
67 $this->select('medium_id', 'value=1');
68 $this->type('activity_location', 'Main offices');
69 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
70 $this->fillRichTextField("activity_details", $details, 'CKEditor');
71 $this->type('activity_subject', $subject);
73 $this->select('case_type_id', "label={$caseTypeLabel}");
75 // Choose Case Start Date.
76 // Using helper webtestFillDate function.
77 $this->webtestFillDate('start_date', 'now');
78 $today = date('F jS, Y', strtotime('now'));
80 $this->type('duration', "20");
81 $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom', FALSE);
83 // Is status message correct?
84 $this->checkCRMAlert("Case opened successfully.");
85 $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 7);
87 $this->_testAddNewActivity($contact['first_name'], $subject, $customGroupTitle, $contact['sort_name']);
90 public function testLinkCases() {
91 // Log in as admin first to verify permissions for CiviCase
92 $this->webtestLogin('admin');
94 // Enable CiviCase module if necessary
95 $this->enableComponents("CiviCase");
97 // let's give full CiviCase permissions to demo user (registered user).
99 'edit-2-access-all-cases-and-activities',
100 'edit-2-access-my-cases-and-activities',
101 'edit-2-administer-civicase',
102 'edit-2-delete-in-civicase',
104 $this->changePermissions($permission);
106 // Log in as normal user
107 $this->webtestLogin();
110 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
112 // Adding contact with randomized first name (so we can then select that contact when creating case)
113 // We're using pop-up New Contact dialog
114 $contact1 = $this->createDialogContact('client_id');
116 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
117 $caseTypeLabel = "Adult Day Care Referral";
118 $subject = "Safe daytime setting - senior female";
119 $this->select('medium_id', 'value=1');
120 $this->type('activity_location', 'Main offices');
121 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
122 $this->fillRichTextField("activity_details", $details, 'CKEditor');
123 $this->type('activity_subject', $subject);
125 $this->select('case_type_id', "label={$caseTypeLabel}");
127 // Choose Case Start Date.
128 // Using helper webtestFillDate function.
129 $this->webtestFillDate('start_date', 'now');
130 $today = date('F jS, Y', strtotime('now'));
132 $this->type('duration', "20");
133 $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom');
135 // Is status message correct?
136 $this->checkCRMAlert("Case opened successfully.");
139 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
141 // Adding contact with randomized first name (so we can then select that contact when creating case)
142 // We're using pop-up New Contact dialog
143 $contact2 = $this->createDialogContact('client_id');
145 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
146 $caseTypeLabel2 = "Adult Day Care Referral";
147 $subject2 = "Subject For Case 2";
148 $this->select('medium_id', 'value=1');
149 $this->type('activity_location', 'Main offices');
150 $details2 = "Details For Case 2";
151 $this->fillRichTextField("activity_details", $details2, 'CKEditor');
152 $this->type('activity_subject', $subject2);
154 $this->select('case_type_id', "label={$caseTypeLabel2}");
156 // Choose Case Start Date.
157 // Using helper webtestFillDate function.
158 $this->webtestFillDate('start_date', 'now');
159 $today = date('F jS, Y', strtotime('now'));
161 $this->type('duration', "20");
162 $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom');
164 // Is status message correct?
165 $this->checkCRMAlert("Case opened successfully.");
167 // We should now be on the "manage case" screen for case 2
168 //Add Link Case Activity to case 1
169 $this->select('add_activity_type_id', 'Link Cases');
170 $this->waitForElementPresent("_qf_Activity_cancel-bottom");
171 $this->select2('link_to_case_id', $contact1['sort_name']);
172 $activitydetails = 'Details of Link Case Activity';
173 $this->fillRichTextField("details", $activitydetails, 'CKEditor');
174 $this->click('css=#activity-details .crm-accordion-header');
175 $this->waitForVisible('subject');
176 $activitySubject = 'Link Case Activity between case 1 and case 2';
177 $activitylocation = 'Main Office Building';
178 $this->select2('source_contact_id', $contact2['sort_name']);
179 $this->type('subject', $activitySubject);
180 $this->type('location', $activitylocation);
181 $this->clickAjaxLink('_qf_Activity_upload-bottom');
182 $id = $this->urlArg('id');
183 $this->waitForText("case_id_$id", $activitySubject);
184 $this->click("xpath=//table[@id='case_id_{$id}']/tbody//tr/td[2]/div[text()='{$activitySubject}']/../../td[8]/a[text()='View']");
186 $LinkCaseActivityData = array(
187 "Client" => $contact2['first_name'],
188 "Activity Type" => "Link Cases",
189 "Subject" => $activitySubject,
190 "Reported By" => $contact2['display_name'],
192 "Location" => $activitylocation,
193 "Date and Time" => $today,
194 "Details" => $activitydetails,
195 "Status" => "Scheduled",
196 "Priority" => "Normal",
198 $this->webtestVerifyTabularData($LinkCaseActivityData);
202 * @param string $firstName
203 * @param $caseSubject
204 * @param $customGroupTitle
205 * @param $contactName
207 public function _testAddNewActivity($firstName, $caseSubject, $customGroupTitle, $contactName) {
208 $customDataParams = $this->_addCustomData($customGroupTitle);
209 //$customDataParams = array( 'optionLabel_47d58', 'custom_8_-1' );
211 // Adding Adding contact with randomized first name for test testContactContextActivityAdd
212 // We're using Quick Add block on the main page for this.
213 $firstName1 = substr(sha1(rand()), 0, 7);
214 $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name");
215 $firstName2 = substr(sha1(rand()), 0, 7);
216 $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name");
218 $this->click("css=li#tab_activity a");
220 // waiting for the activity dropdown to show up
221 $this->waitForElementPresent("other_activity");
223 // Select the activity type from the activity dropdown
224 $this->select("other_activity", "label=Meeting");
226 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
227 // button at the end of this page to show up, to make sure it's fully loaded.
228 $this->waitForElementPresent("_qf_Activity_upload-bottom");
230 // ...and verifying if the page contains properly formatted display name for chosen contact.
231 $this->waitForText("xpath=//div[@id='s2id_target_contact_id']", 'Anderson, ' . $firstName2, "Contact not found in line " . __LINE__
);
233 // Now we're filling the "Assigned To" field.
234 // Typing contact's name into the field (using typeKeys(), not type()!)...
235 $this->click("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input");
236 $this->keyDown("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", " ");
237 $this->type("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName1);
238 $this->typeKeys("xpath=//div[@id='s2id_assignee_contact_id']/ul/li/input", $firstName1);
240 // ...waiting for drop down with results to show up...
241 $this->waitForElementPresent("xpath=//div[@class='select2-result-label']");
243 //..need to use mouseDownAt on first result (which is a li element), click does not work
244 $this->clickAt("xpath=//div[@class='select2-result-label']");
246 // ...again, waiting for the box with contact name to show up...
247 $this->waitForText("xpath=//div[@id='s2id_assignee_contact_id']", "$firstName1");
249 // ...and verifying if the page contains properly formatted display name for chosen contact.
250 $this->assertElementContainsText("xpath=//div[@id='s2id_assignee_contact_id']", "Summerson, $firstName1", 'Contact not found in line ' . __LINE__
);
252 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
253 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
254 // For simple input fields we can use field id as selector
255 $this->type("subject", $subject);
256 $this->type("location", "Some location needs to be put in this field.");
258 // Choosing the Date.
259 // Please note that we don't want to put in fixed date, since
260 // we want this test to work in the future and not fail because
261 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
262 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
265 $this->type("duration", "30");
267 // Putting in details.
268 $this->type("details", "Really brief details information.");
270 // Making sure that status is set to Scheduled (using value, not label).
271 $this->select("status_id", "value=1");
274 $this->select("priority_id", "value=1");
276 $textField = 'This is test custom data';
277 $this->click("xpath=//div[@id='customData']//div[@class='custom-group custom-group-$customGroupTitle crm-accordion-wrapper collapsed']");
278 $this->waitForElementPresent("xpath=//div[@class='crm-accordion-body']//table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/input");
279 $this->click("xpath=//div[@class='crm-accordion-body']//table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/input");
280 $this->type($customDataParams[1], $textField);
282 // Scheduling follow-up.
283 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
284 $this->select("followup_activity_type_id", "value=1");
285 $this->webtestFillDateTime('followup_date', '+2 months 10:00AM');
286 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
289 $this->click("_qf_Activity_upload-bottom");
291 // Is status message correct?
292 $this->waitForText('crm-notification-container', $subject);
294 // click through to the Activity view screen
295 $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']");
296 $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']");
297 $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");
298 $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");
300 // file activity on case
301 $this->waitForElementPresent('file_on_case_unclosed_case_id');
302 $this->select2('file_on_case_unclosed_case_id', $firstName);
303 $this->assertElementContainsText("xpath=//div[@id='s2id_file_on_case_unclosed_case_id']", "$firstName", 'Contact not found in line ' . __LINE__
);
304 $this->type('file_on_case_activity_subject', $subject);
305 $this->click("xpath=//div[@class='ui-dialog-buttonset']//button//span[text()='Save']");
306 $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']");
308 // verify if custom data is present
309 $this->openCiviPage('case', 'reset=1');
310 $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']");
312 $this->waitForElementPresent('_qf_CaseView_cancel-bottom');
313 $id = $this->urlArg('id');
314 $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='case_id_" . $id . "']/tbody/tr[1]/td[2]");
315 $this->click("xpath=//table[@id='case_id_" . $id . "']/tbody/tr[1]/td[2]/div[text()='{$subject}']/../../td[8]/a[text()='View']");
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 fa-times']");
321 $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='case_id_" . $id . "']/tbody/tr[1]/td[2]");
323 $this->click("xpath=//div[@id='activities']//table[@id='case_id_" . $id . "']/tbody//tr/td[2]/div[text()='{$subject}']/../../td[7]/div[text()='Scheduled']");
325 $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='case_id_" . $id . "']/tbody//tr/td[2]/div[text()='{$subject}']/../../td[7]/div/form/select");
327 // change activity status
328 $this->select("xpath=//div[@id='activities']//table[@id='case_id_" . $id . "']/tbody//tr/td[2]/div[text()='{$subject}']/../../td[7]/div/form/select", 'value=2');
329 $this->click("xpath=//div[@id='activities']//table[@id='case_id_" . $id . "']/tbody//tr/td[2]/div[text()='{$subject}']/../../td[7]/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 . "']/tbody//tr/td[2]/div[text()='{$subject}']/../../td[8]/a[1]");
336 $this->waitForElementPresent('ActivityView');
337 $this->waitForElementPresent("css=table#crm-activity-view-table tr.crm-case-activityview-form-block-groupTitle");
341 * @param $customGroupTitle
345 public function _addCustomData($customGroupTitle) {
347 $this->openCiviPage('admin/custom/group', 'reset=1');
349 //add new custom data
350 $this->clickLink("//a[@id='newCustomDataGroup']/span");
352 //fill custom group title
353 $this->click("title");
354 $this->type("title", $customGroupTitle);
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');
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.");
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']");
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");
383 //select options per line
384 $this->type("options_per_line", "3");
387 $this->type("help_pre", "this is field pre help");
389 //enter post help msg
390 $this->type("help_post", "this is field post help");
393 $this->click("is_searchable");
396 $this->clickLink("_qf_Field_next_new-bottom", "_qf_Field_next_new-bottom");
398 //Is custom field created
399 $this->waitForText('crm-notification-container', "Custom field '$radioFieldLabel' has been saved.");
401 // create another custom field - text field
402 $textFieldLabel = 'Custom Field Text_' . substr(sha1(rand()), 0, 4);
403 $this->type('label', $textFieldLabel);
406 $this->type('help_pre', "this is field pre help");
408 //enter post help msg
409 $this->type('help_post', "this is field post help");
412 $this->click('is_searchable');
415 $this->clickLink("_qf_Field_done-bottom", "//a[@id='newCustomField']/span");
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];
422 return array($radioOptionLabel1, "custom_{$textFieldId}_-1");