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