-- webtest improvement made based on the break on server
[civicrm-core.git] / tests / phpunit / WebTest / Case / ActivityToCaseTest.php
CommitLineData
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
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Case_ActivityToCaseTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testAddActivityToCase() {
6a488035 35 // Log in as admin first to verify permissions for CiviCase
42daf119 36 $this->webtestLogin('true');
6a488035
TO
37
38 // Enable CiviCase module if necessary
b9715b8a 39 $this->enableComponents("CiviCase");
6a488035
TO
40
41 // let's give full CiviCase permissions to demo user (registered user).
42 $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');
43 $this->changePermissions($permission);
44
42daf119
CW
45 // Log in as normal user
46 $this->webtestLogin();
47
d2771e94 48 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
6a488035
TO
49
50 // Adding contact with randomized first name (so we can then select that contact when creating case)
51 // We're using pop-up New Contact dialog
52 $firstName = substr(sha1(rand()), 0, 7);
53 $lastName = "Fraser";
54 $contactName = "{$lastName}, {$firstName}";
55 $displayName = "{$firstName} {$lastName}";
56 $email = "{$lastName}.{$firstName}@example.org";
57 $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4);
58
59 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
60 $caseTypeLabel = "Adult Day Care Referral";
61 $subject = "Safe daytime setting - senior female";
62 $this->select('medium_id', 'value=1');
63 $this->type('activity_location', 'Main offices');
64 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
65 $this->fillRichTextField("activity_details", $details, 'CKEditor');
66 $this->type('activity_subject', $subject);
67
68 $this->select('case_type_id', "label={$caseTypeLabel}");
69
70 // Choose Case Start Date.
71 // Using helper webtestFillDate function.
72 $this->webtestFillDate('start_date', 'now');
73 $today = date('F jS, Y', strtotime('now'));
76e86fd8 74
6a488035 75 $this->type('duration', "20");
225a8648 76 $this->clickLink('_qf_Case_upload-bottom', '_qf_CaseView_cancel-bottom');
6a488035
TO
77
78 // Is status message correct?
6c5f7368 79 $this->waitForText('crm-notification-container', "Case opened successfully.");
6a488035
TO
80 $customGroupTitle = 'Custom_' . substr(sha1(rand()), 0, 7);
81
82 $this->_testAddNewActivity($firstName, $subject, $customGroupTitle, $contactName);
83 }
84
85 function _testAddNewActivity($firstName, $caseSubject, $customGroupTitle, $contactName) {
86 $customDataParams = $this->_addCustomData($customGroupTitle);
87 //$customDataParams = array( 'optionLabel_47d58', 'custom_8_-1' );
88
89 // Adding Adding contact with randomized first name for test testContactContextActivityAdd
90 // We're using Quick Add block on the main page for this.
91 $firstName1 = substr(sha1(rand()), 0, 7);
92 $this->webtestAddContact($firstName1, "Summerson", $firstName1 . "@summerson.name");
93 $firstName2 = substr(sha1(rand()), 0, 7);
94 $this->webtestAddContact($firstName2, "Anderson", $firstName2 . "@anderson.name");
95
6a488035
TO
96 $this->click("css=li#tab_activity a");
97
98 // waiting for the activity dropdown to show up
99 $this->waitForElementPresent("other_activity");
100
101 // Select the activity type from the activity dropdown
102 $this->select("other_activity", "label=Meeting");
103
104 // waitForPageToLoad is not always reliable. Below, we're waiting for the submit
105 // button at the end of this page to show up, to make sure it's fully loaded.
106 $this->waitForElementPresent("_qf_Activity_upload-bottom");
107
6a488035 108 // ...and verifying if the page contains properly formatted display name for chosen contact.
d2771e94 109 $this->assertElementContainsText('css=tr.crm-activity-form-block-target_contact_id td ul li.token-input-token-facebook', 'Anderson, ' . $firstName2, "Contact not found in line " . __LINE__);
6a488035
TO
110
111 // Now we're filling the "Assigned To" field.
112 // Typing contact's name into the field (using typeKeys(), not type()!)...
113 $this->click("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id");
114 $this->type("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName1);
115 $this->typeKeys("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName1);
116
117 // ...waiting for drop down with results to show up...
118 $this->waitForElementPresent("css=div.token-input-dropdown-facebook");
119 $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook");
120
121 //..need to use mouseDownAt on first result (which is a li element), click does not work
122 $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook");
123
124 // ...again, waiting for the box with contact name to show up...
125 $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook");
126
127 // ...and verifying if the page contains properly formatted display name for chosen contact.
d2771e94 128 $this->assertElementContainsText('css=tr.crm-activity-form-block-assignee_contact_id td ul li.token-input-token-facebook', 'Summerson, ' . $firstName1, "Contact not found in line " . __LINE__);
6a488035
TO
129
130 // Putting the contents into subject field - assigning the text to variable, it'll come in handy later
131 $subject = "This is subject of test activity being added through activity tab of contact summary screen.";
132 // For simple input fields we can use field id as selector
133 $this->type("subject", $subject);
134 $this->type("location", "Some location needs to be put in this field.");
135
136 // Choosing the Date.
137 // Please note that we don't want to put in fixed date, since
138 // we want this test to work in the future and not fail because
139 // of date being set in the past. Therefore, using helper webtestFillDateTime function.
140 $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM');
141
142 // Setting duration.
143 $this->type("duration", "30");
144
145 // Putting in details.
146 $this->type("details", "Really brief details information.");
147
148 // Making sure that status is set to Scheduled (using value, not label).
149 $this->select("status_id", "value=1");
150
151 // Setting priority.
152 $this->select("priority_id", "value=1");
153
154 $textField = 'This is test custom data';
155 $this->click($customGroupTitle);
156 $this->click("xpath=//div[@id='{$customGroupTitle}']/table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/input");
157 $this->type($customDataParams[1], $textField);
158
159 // Scheduling follow-up.
160 $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header");
161 $this->select("followup_activity_type_id", "value=1");
162 $this->webtestFillDateTime('followup_date', '+2 months 10:00AM');
163 $this->type("followup_activity_subject", "This is subject of schedule follow-up activity");
164
165 // Clicking save.
166 $this->click("_qf_Activity_upload-bottom");
167 $this->waitForPageToLoad($this->getTimeoutMsec());
168
169 // Is status message correct?
6c5f7368 170 $this->waitForText('crm-notification-container', $subject);
6a488035
TO
171
172 // click through to the Activity view screen
173 $this->waitForElementPresent("xpath=//div[@id='Activities']//table/tbody/tr[2]/td[9]");
174 $this->click("xpath=//div[@id='Activities']//table/tbody/tr[2]/td[9]/span[2]/ul/li/a[text()='File On Case']");
175 $this->waitForElementPresent("css=div#fileOnCaseDialog");
176 $this->waitForElementPresent('case_activity_subject');
177
178 // file activity on case
179 $this->type('unclosed_cases', $firstName);
180 $this->click('unclosed_cases');
181 $this->waitForElementPresent("css=div.ac_results-inner li");
182 $this->click("css=div.ac_results-inner li");
183 $this->assertContains($firstName, $this->getValue('unclosed_cases'),
184 "autocomplete expected $firstName but didn’t find it in " .
185 $this->getValue('unclosed_cases')
186 );
187
188 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Ok']");
189 $this->waitForElementPresent("xpath=//div[@id='Activities']//table/tbody/tr[1]/td[9]/span/a[text()='View']");
190
191 // verify if custom data is present
d2771e94 192 $this->openCiviPage('case', 'reset=1');
6a488035
TO
193 $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']");
194
195 $this->waitForElementPresent('_qf_CaseView_cancel-bottom');
196 $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='activities-selector']/tbody/tr[1]/td[2]");
197
198 $this->click("xpath=//div[@id='activities']//table[@id='activities-selector']//a[text()='{$subject}']");
199
200 $this->waitForElementPresent('view-activity');
201 $this->waitForElementPresent("css=table#crm-activity-view-table tr.crm-case-activityview-form-block-groupTitle");
d2771e94
RN
202 $this->assertElementContainsText('crm-activity-view-table', "$customDataParams[0]");
203 $this->assertElementContainsText('crm-activity-view-table', "$textField");
6a488035
TO
204 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Done']");
205 $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='activities-selector']/tbody/tr[1]/td[2]");
206
207 $this->click("xpath=//div[@id='activities']//table[@id='activities-selector']/tbody//tr/td[2]/a[text()='{$subject}']/../../td[6]/a[text()='Scheduled']");
208
baaf85ee 209 $this->waitForElementPresent("xpath=//html/body/div[7]");
6a488035
TO
210 $this->waitForElementPresent('activity_change_status');
211
212 // change activity status
213 $this->select('activity_change_status', 'value=2');
214 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Ok']");
215 $this->waitForPageToLoad($this->getTimeoutMsec());
d2771e94 216 $this->openCiviPage('case', 'reset=1');
6a488035
TO
217 $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']");
218 $this->waitForElementPresent('_qf_CaseView_cancel-bottom');
219 $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='activities-selector']/tbody/tr[1]/td[2]");
220 $this->click("xpath=//div[@id='activities']//table[@id='activities-selector']//a[text()='{$subject}']");
221 $this->waitForElementPresent('view-activity');
222 $this->waitForElementPresent("css=table#crm-activity-view-table tr.crm-case-activityview-form-block-groupTitle");
223 }
224
225 function _addCustomData($customGroupTitle) {
42daf119 226
d2771e94 227 $this->openCiviPage('admin/custom/group', 'reset=1');
6a488035
TO
228
229 //add new custom data
230 $this->click("//a[@id='newCustomDataGroup']/span");
231 $this->waitForPageToLoad($this->getTimeoutMsec());
232
233 //fill custom group title
234 $this->click("title");
235 $this->type("title", $customGroupTitle);
236
237 //custom group extends
238 $this->click("extends[0]");
239 $this->select("extends[0]", "value=Activity");
240 $this->click("//option[@value='Activity']");
241 $this->click('_qf_Group_next-bottom');
242 $this->waitForElementPresent('_qf_Field_cancel-bottom');
243
244 //Is custom group created?
6c5f7368 245 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
6a488035
TO
246
247 // create a custom field - Integer Radio
248 $this->click("data_type[0]");
249 $this->select("data_type[0]", "value=1");
250 $this->click("//option[@value='1']");
251 $this->click("data_type[1]");
252 $this->select("data_type[1]", "value=Radio");
253 $this->click("//option[@value='Radio']");
254
255 $radioFieldLabel = 'Custom Field Radio_' . substr(sha1(rand()), 0, 4);
256 $this->type("label", $radioFieldLabel);
257 $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
258 $this->type("option_label_1", $radioOptionLabel1);
259 $this->type("option_value_1", "1");
260 $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5);
261 $this->type("option_label_2", $radioOptionLabel2);
262 $this->type("option_value_2", "2");
263
264 //select options per line
265 $this->type("options_per_line", "3");
266
267 //enter pre help msg
268 $this->type("help_pre", "this is field pre help");
269
270 //enter post help msg
271 $this->type("help_post", "this is field post help");
272
273 //Is searchable?
274 $this->click("is_searchable");
275
276 //clicking save
277 $this->click("_qf_Field_next");
278 $this->waitForPageToLoad($this->getTimeoutMsec());
279
280 //Is custom field created
6c5f7368 281 $this->waitForText('crm-notification-container', "Your custom field '$radioFieldLabel' has been saved.");
6a488035
TO
282
283 // create another custom field - text field
284 $this->click("//a[@id='newCustomField']/span");
285 $this->waitForPageToLoad($this->getTimeoutMsec());
286
287 $textFieldLabel = 'Custom Field Text_' . substr(sha1(rand()), 0, 4);
288 $this->type('label', $textFieldLabel);
289
290 //enter pre help msg
291 $this->type('help_pre', "this is field pre help");
292
293 //enter post help msg
294 $this->type('help_post', "this is field post help");
295
296 //Is searchable?
297 $this->click('is_searchable');
298
299 //clicking save
300 $this->click('_qf_Field_next');
301 $this->waitForPageToLoad($this->getTimeoutMsec());
302
303 //Is custom field created
6c5f7368 304 $this->waitForText('crm-notification-container', "Your custom field '$textFieldLabel' has been saved.");
6a488035
TO
305 $textFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$textFieldLabel']/../../td[8]/span/a[text()='Edit Field']/@href"));
306 $textFieldId = $textFieldId[1];
307
308 return array($radioOptionLabel1, "custom_{$textFieldId}_-1");
309 }
310}
311