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