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