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 | |
b9715b8a | 42 | $this->enableComponents("CiviCase"); |
6a488035 TO |
43 | |
44 | // let's give full CiviCase permissions to demo user (registered user). | |
45 | $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'); | |
46 | $this->changePermissions($permission); | |
47 | ||
48 | // Go directly to the URL of the screen that you will be testing (New Case-standalone). | |
d2771e94 | 49 | $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom'); |
6a488035 TO |
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? | |
d2771e94 | 84 | $this->assertElementContainsText('crm-notification-container', "Case opened successfully.", "Save successful status message didn't show up after saving!"); |
6a488035 TO |
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 | // Go directly to the URL of the screen that you will be testing (Activity Tab). | |
102 | $this->click("css=li#tab_activity a"); | |
103 | ||
104 | // waiting for the activity dropdown to show up | |
105 | $this->waitForElementPresent("other_activity"); | |
106 | ||
107 | // Select the activity type from the activity dropdown | |
108 | $this->select("other_activity", "label=Meeting"); | |
109 | ||
110 | // waitForPageToLoad is not always reliable. Below, we're waiting for the submit | |
111 | // button at the end of this page to show up, to make sure it's fully loaded. | |
112 | $this->waitForElementPresent("_qf_Activity_upload-bottom"); | |
113 | ||
114 | // Let's start filling the form with values. | |
115 | ||
116 | // ...and verifying if the page contains properly formatted display name for chosen contact. | |
d2771e94 | 117 | $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 |
118 | |
119 | // Now we're filling the "Assigned To" field. | |
120 | // Typing contact's name into the field (using typeKeys(), not type()!)... | |
121 | $this->click("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id"); | |
122 | $this->type("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName1); | |
123 | $this->typeKeys("css=tr.crm-activity-form-block-assignee_contact_id input#token-input-assignee_contact_id", $firstName1); | |
124 | ||
125 | // ...waiting for drop down with results to show up... | |
126 | $this->waitForElementPresent("css=div.token-input-dropdown-facebook"); | |
127 | $this->waitForElementPresent("css=li.token-input-dropdown-item2-facebook"); | |
128 | ||
129 | //..need to use mouseDownAt on first result (which is a li element), click does not work | |
130 | $this->mouseDownAt("css=li.token-input-dropdown-item2-facebook"); | |
131 | ||
132 | // ...again, waiting for the box with contact name to show up... | |
133 | $this->waitForElementPresent("css=tr.crm-activity-form-block-assignee_contact_id td ul li span.token-input-delete-token-facebook"); | |
134 | ||
135 | // ...and verifying if the page contains properly formatted display name for chosen contact. | |
d2771e94 | 136 | $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 |
137 | |
138 | // Putting the contents into subject field - assigning the text to variable, it'll come in handy later | |
139 | $subject = "This is subject of test activity being added through activity tab of contact summary screen."; | |
140 | // For simple input fields we can use field id as selector | |
141 | $this->type("subject", $subject); | |
142 | $this->type("location", "Some location needs to be put in this field."); | |
143 | ||
144 | // Choosing the Date. | |
145 | // Please note that we don't want to put in fixed date, since | |
146 | // we want this test to work in the future and not fail because | |
147 | // of date being set in the past. Therefore, using helper webtestFillDateTime function. | |
148 | $this->webtestFillDateTime('activity_date_time', '+1 month 11:10PM'); | |
149 | ||
150 | // Setting duration. | |
151 | $this->type("duration", "30"); | |
152 | ||
153 | // Putting in details. | |
154 | $this->type("details", "Really brief details information."); | |
155 | ||
156 | // Making sure that status is set to Scheduled (using value, not label). | |
157 | $this->select("status_id", "value=1"); | |
158 | ||
159 | // Setting priority. | |
160 | $this->select("priority_id", "value=1"); | |
161 | ||
162 | $textField = 'This is test custom data'; | |
163 | $this->click($customGroupTitle); | |
164 | $this->click("xpath=//div[@id='{$customGroupTitle}']/table/tbody/tr[2]/td[2]/table/tbody/tr/td[1]/input"); | |
165 | $this->type($customDataParams[1], $textField); | |
166 | ||
167 | // Scheduling follow-up. | |
168 | $this->click("css=.crm-activity-form-block-schedule_followup div.crm-accordion-header"); | |
169 | $this->select("followup_activity_type_id", "value=1"); | |
170 | $this->webtestFillDateTime('followup_date', '+2 months 10:00AM'); | |
171 | $this->type("followup_activity_subject", "This is subject of schedule follow-up activity"); | |
172 | ||
173 | // Clicking save. | |
174 | $this->click("_qf_Activity_upload-bottom"); | |
175 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
176 | ||
177 | // Is status message correct? | |
d2771e94 | 178 | $this->assertElementContainsText('crm-notification-container', "Activity '$subject' has been saved.", |
6a488035 TO |
179 | "Status message didn't show up after saving!" |
180 | ); | |
181 | ||
182 | // click through to the Activity view screen | |
183 | $this->waitForElementPresent("xpath=//div[@id='Activities']//table/tbody/tr[2]/td[9]"); | |
184 | $this->click("xpath=//div[@id='Activities']//table/tbody/tr[2]/td[9]/span[2]/ul/li/a[text()='File On Case']"); | |
185 | $this->waitForElementPresent("css=div#fileOnCaseDialog"); | |
186 | $this->waitForElementPresent('case_activity_subject'); | |
187 | ||
188 | // file activity on case | |
189 | $this->type('unclosed_cases', $firstName); | |
190 | $this->click('unclosed_cases'); | |
191 | $this->waitForElementPresent("css=div.ac_results-inner li"); | |
192 | $this->click("css=div.ac_results-inner li"); | |
193 | $this->assertContains($firstName, $this->getValue('unclosed_cases'), | |
194 | "autocomplete expected $firstName but didn’t find it in " . | |
195 | $this->getValue('unclosed_cases') | |
196 | ); | |
197 | ||
198 | $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Ok']"); | |
199 | $this->waitForElementPresent("xpath=//div[@id='Activities']//table/tbody/tr[1]/td[9]/span/a[text()='View']"); | |
200 | ||
201 | // verify if custom data is present | |
d2771e94 | 202 | $this->openCiviPage('case', 'reset=1'); |
6a488035 TO |
203 | $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']"); |
204 | ||
205 | $this->waitForElementPresent('_qf_CaseView_cancel-bottom'); | |
206 | $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='activities-selector']/tbody/tr[1]/td[2]"); | |
207 | ||
208 | $this->click("xpath=//div[@id='activities']//table[@id='activities-selector']//a[text()='{$subject}']"); | |
209 | ||
210 | $this->waitForElementPresent('view-activity'); | |
211 | $this->waitForElementPresent("css=table#crm-activity-view-table tr.crm-case-activityview-form-block-groupTitle"); | |
d2771e94 RN |
212 | $this->assertElementContainsText('crm-activity-view-table', "$customDataParams[0]"); |
213 | $this->assertElementContainsText('crm-activity-view-table', "$textField"); | |
6a488035 TO |
214 | $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Done']"); |
215 | $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='activities-selector']/tbody/tr[1]/td[2]"); | |
216 | ||
217 | $this->click("xpath=//div[@id='activities']//table[@id='activities-selector']/tbody//tr/td[2]/a[text()='{$subject}']/../../td[6]/a[text()='Scheduled']"); | |
218 | ||
219 | $this->waitForElementPresent("css=div#changeStatusDialog"); | |
220 | $this->waitForElementPresent('activity_change_status'); | |
221 | ||
222 | // change activity status | |
223 | $this->select('activity_change_status', 'value=2'); | |
224 | $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Ok']"); | |
225 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
d2771e94 | 226 | $this->openCiviPage('case', 'reset=1'); |
6a488035 TO |
227 | $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']"); |
228 | $this->waitForElementPresent('_qf_CaseView_cancel-bottom'); | |
229 | $this->waitForElementPresent("xpath=//div[@id='activities']//table[@id='activities-selector']/tbody/tr[1]/td[2]"); | |
230 | $this->click("xpath=//div[@id='activities']//table[@id='activities-selector']//a[text()='{$subject}']"); | |
231 | $this->waitForElementPresent('view-activity'); | |
232 | $this->waitForElementPresent("css=table#crm-activity-view-table tr.crm-case-activityview-form-block-groupTitle"); | |
233 | } | |
234 | ||
235 | function _addCustomData($customGroupTitle) { | |
236 | // Go directly to the URL of the screen that you will be testing (New Custom Group). | |
d2771e94 | 237 | $this->openCiviPage('admin/custom/group', 'reset=1'); |
6a488035 TO |
238 | |
239 | //add new custom data | |
240 | $this->click("//a[@id='newCustomDataGroup']/span"); | |
241 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
242 | ||
243 | //fill custom group title | |
244 | $this->click("title"); | |
245 | $this->type("title", $customGroupTitle); | |
246 | ||
247 | //custom group extends | |
248 | $this->click("extends[0]"); | |
249 | $this->select("extends[0]", "value=Activity"); | |
250 | $this->click("//option[@value='Activity']"); | |
251 | $this->click('_qf_Group_next-bottom'); | |
252 | $this->waitForElementPresent('_qf_Field_cancel-bottom'); | |
253 | ||
254 | //Is custom group created? | |
d2771e94 | 255 | $this->assertElementContainsText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."); |
6a488035 TO |
256 | |
257 | // create a custom field - Integer Radio | |
258 | $this->click("data_type[0]"); | |
259 | $this->select("data_type[0]", "value=1"); | |
260 | $this->click("//option[@value='1']"); | |
261 | $this->click("data_type[1]"); | |
262 | $this->select("data_type[1]", "value=Radio"); | |
263 | $this->click("//option[@value='Radio']"); | |
264 | ||
265 | $radioFieldLabel = 'Custom Field Radio_' . substr(sha1(rand()), 0, 4); | |
266 | $this->type("label", $radioFieldLabel); | |
267 | $radioOptionLabel1 = 'optionLabel_' . substr(sha1(rand()), 0, 5); | |
268 | $this->type("option_label_1", $radioOptionLabel1); | |
269 | $this->type("option_value_1", "1"); | |
270 | $radioOptionLabel2 = 'optionLabel_' . substr(sha1(rand()), 0, 5); | |
271 | $this->type("option_label_2", $radioOptionLabel2); | |
272 | $this->type("option_value_2", "2"); | |
273 | ||
274 | //select options per line | |
275 | $this->type("options_per_line", "3"); | |
276 | ||
277 | //enter pre help msg | |
278 | $this->type("help_pre", "this is field pre help"); | |
279 | ||
280 | //enter post help msg | |
281 | $this->type("help_post", "this is field post help"); | |
282 | ||
283 | //Is searchable? | |
284 | $this->click("is_searchable"); | |
285 | ||
286 | //clicking save | |
287 | $this->click("_qf_Field_next"); | |
288 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
289 | ||
290 | //Is custom field created | |
d2771e94 | 291 | $this->assertElementContainsText('crm-notification-container', "Your custom field '$radioFieldLabel' has been saved."); |
6a488035 TO |
292 | |
293 | // create another custom field - text field | |
294 | $this->click("//a[@id='newCustomField']/span"); | |
295 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
296 | ||
297 | $textFieldLabel = 'Custom Field Text_' . substr(sha1(rand()), 0, 4); | |
298 | $this->type('label', $textFieldLabel); | |
299 | ||
300 | //enter pre help msg | |
301 | $this->type('help_pre', "this is field pre help"); | |
302 | ||
303 | //enter post help msg | |
304 | $this->type('help_post', "this is field post help"); | |
305 | ||
306 | //Is searchable? | |
307 | $this->click('is_searchable'); | |
308 | ||
309 | //clicking save | |
310 | $this->click('_qf_Field_next'); | |
311 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
312 | ||
313 | //Is custom field created | |
d2771e94 | 314 | $this->assertElementContainsText('crm-notification-container', "Your custom field '$textFieldLabel' has been saved."); |
6a488035 TO |
315 | $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")); |
316 | $textFieldId = $textFieldId[1]; | |
317 | ||
318 | return array($radioOptionLabel1, "custom_{$textFieldId}_-1"); | |
319 | } | |
320 | } | |
321 |