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_CaseCustomFieldsTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testAddCase() { | |
42daf119 | 36 | $this->webtestLogin('admin'); |
6a488035 TO |
37 | |
38 | // Enable CiviCase module if necessary | |
0bd37c06 CW |
39 | $this->enableComponents("CiviCase"); |
40 | ||
6a488035 TO |
41 | $customGrp1 = "CaseCustom_Data1_" . substr(sha1(rand()), 0, 7); |
42 | ||
43 | // create custom group1 | |
d2771e94 | 44 | $this->openCiviPage('admin/custom/group', 'reset=1'); |
6a488035 TO |
45 | $this->click("newCustomDataGroup"); |
46 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
47 | $this->type("title", $customGrp1); | |
48 | $this->select("extends[0]", "value=Case"); | |
efb29358 CW |
49 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
50 | // Sleep should never be used for wait for anything to load from the server | |
51 | // Justification for this instance: FIXME | |
6a488035 TO |
52 | sleep(1); |
53 | $this->select("extends_1", "value=2"); | |
54 | $this->click("_qf_Group_next-bottom"); | |
55 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
56 | ||
57 | // get custom group id | |
58 | $elements = $this->parseURL(); | |
59 | $customGrpId1 = $elements['queryString']['gid']; | |
60 | ||
61 | $customId = $this->_testGetCustomFieldId($customGrpId1); | |
0bd37c06 CW |
62 | $cusId_1 = 'custom_' . $customId[0] . '_-1'; |
63 | $cusId_2 = 'custom_' . $customId[1] . '_-1'; | |
64 | $cusId_3 = 'custom_' . $customId[2] . '_-1'; | |
6a488035 TO |
65 | |
66 | // let's give full CiviCase permissions. | |
67 | $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'); | |
68 | $this->changePermissions($permission); | |
69 | ||
42daf119 CW |
70 | // Log in as normal user |
71 | $this->webtestLogin(); | |
72 | ||
6a488035 | 73 | // Go to reserved New Individual Profile to set value for logged in user's contact name (we'll need that later) |
d2771e94 | 74 | $this->openCiviPage('profile/edit', 'reset=1&gid=4', '_qf_Edit_next'); |
6a488035 TO |
75 | $testUserFirstName = "Testuserfirst"; |
76 | $testUserLastName = "Testuserlast"; | |
6a488035 TO |
77 | $this->type("first_name", $testUserFirstName); |
78 | $this->type("last_name", $testUserLastName); | |
79 | $this->click("_qf_Edit_next"); | |
80 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
81 | $this->waitForElementPresent("profilewrap4"); | |
82 | ||
d2771e94 | 83 | $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom'); |
6a488035 TO |
84 | |
85 | // Try submitting the form without creating or selecting a contact (test for CRM-7971) | |
86 | $this->click("_qf_Case_upload-bottom"); | |
87 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
88 | $this->waitForElementPresent("css=span.crm-error"); | |
6a488035 TO |
89 | |
90 | // Adding contact with randomized first name (so we can then select that contact when creating case) | |
91 | // We're using pop-up New Contact dialog | |
92 | $firstName = substr(sha1(rand()), 0, 7); | |
93 | $lastName = "Fraser"; | |
94 | $contactName = "{$lastName}, {$firstName}"; | |
95 | $displayName = "{$firstName} {$lastName}"; | |
96 | $email = "{$lastName}.{$firstName}@example.org"; | |
97 | $custFname = "Mike" . substr(sha1(rand()), 0, 7); | |
98 | $custMname = "Dav" . substr(sha1(rand()), 0, 7); | |
99 | $custLname = "Krist" . substr(sha1(rand()), 0, 7); | |
100 | $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4); | |
101 | ||
102 | // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files. | |
103 | $caseTypeLabel = "Adult Day Care Referral"; | |
104 | ||
105 | // activity types we expect for this case type | |
0bd37c06 CW |
106 | $activityTypes = array("ADC referral", "Follow up", "Medical evaluation", "Mental health evaluation"); |
107 | $caseRoles = array("Senior Services Coordinator", "Health Services Coordinator", "Benefits Specialist", "Client"); | |
6a488035 | 108 | $caseStatusLabel = "Ongoing"; |
0bd37c06 | 109 | $subject = "Safe daytime setting - senior female"; |
6a488035 TO |
110 | $this->select("medium_id", "value=1"); |
111 | $location = "Main offices"; | |
112 | $this->type("activity_location", $location); | |
113 | $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented."; | |
114 | $this->fillRichTextField("activity_details", $details, 'CKEditor'); | |
115 | $this->type("activity_subject", $subject); | |
116 | ||
117 | $this->select("case_type_id", "label={$caseTypeLabel}"); | |
efb29358 CW |
118 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
119 | // Sleep should never be used for wait for anything to load from the server | |
120 | // Justification for this instance: FIXME | |
6a488035 TO |
121 | sleep(3); |
122 | $this->select("status_id", "label={$caseStatusLabel}"); | |
123 | ||
124 | // Choose Case Start Date. | |
125 | // Using helper webtestFillDate function. | |
126 | $this->webtestFillDate('start_date', 'now'); | |
127 | $today = date('F jS, Y', strtotime('now')); | |
128 | ||
129 | // echo 'Today is ' . $today; | |
130 | $this->type("duration", "20"); | |
131 | $this->type("{$cusId_1}", $custFname); | |
132 | $this->type("{$cusId_2}", $custMname); | |
133 | $this->type("{$cusId_3}", $custLname); | |
134 | $this->click("_qf_Case_upload-bottom"); | |
135 | ||
136 | // We should be at manage case screen | |
137 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
138 | $this->waitForElementPresent("_qf_CaseView_cancel-bottom"); | |
139 | ||
140 | // Is status message correct? | |
141 | $this->assertTextPresent("Case opened successfully.", "Save successful status message didn't show up after saving!"); | |
142 | $this->click("_qf_CaseView_cancel-bottom"); | |
143 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
d2771e94 | 144 | $this->openCiviPage('case', 'reset=1', "xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[8]/a[text()='Open Case']"); |
6a488035 TO |
145 | $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[8]/a[text()='Open Case']"); |
146 | $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Done']"); | |
efb29358 CW |
147 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
148 | // Sleep should never be used for wait for anything to load from the server | |
149 | // Justification for this instance: FIXME | |
6a488035 TO |
150 | sleep(3); |
151 | ||
152 | $openCaseData = array( | |
153 | "Client" => $displayName, | |
154 | "Activity Type" => "Open Case", | |
155 | "Subject" => $subject, | |
156 | "Created By" => "{$testUserFirstName} {$testUserLastName}", | |
157 | "Reported By" => "{$testUserFirstName} {$testUserLastName}", | |
158 | "Medium" => "In Person", | |
159 | "Location" => $location, | |
160 | "Date and Time" => $today, | |
161 | "Status" => "Completed", | |
162 | "Priority" => "Normal", | |
163 | ); | |
164 | $this->webtestVerifyTabularData($openCaseData); | |
165 | $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Done']"); | |
166 | ||
167 | // verify if custom data is present | |
d2771e94 | 168 | $this->openCiviPage('case', 'reset=1'); |
6a488035 TO |
169 | $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[9]/span/a[text()='Manage']"); |
170 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
0bd37c06 CW |
171 | $this->click("css=#{$customGrp1} .crm-accordion-header"); |
172 | $this->waitForElementPresent("css=#{$customGrp1} a.button"); | |
173 | $cusId_1 = 'custom_' . $customId[0] . '_1'; | |
174 | $cusId_2 = 'custom_' . $customId[1] . '_1'; | |
175 | $cusId_3 = 'custom_' . $customId[2] . '_1'; | |
176 | $this->click("css=#{$customGrp1} a.button"); | |
efb29358 CW |
177 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
178 | // Sleep should never be used for wait for anything to load from the server | |
179 | // Justification for this instance: FIXME | |
6a488035 | 180 | sleep(2); |
0bd37c06 | 181 | $this->waitForElementPresent("{$cusId_1}"); |
6a488035 TO |
182 | $custFname = "Miky" . substr(sha1(rand()), 0, 7); |
183 | $custMname = "Davy" . substr(sha1(rand()), 0, 7); | |
184 | $custLname = "Kristy" . substr(sha1(rand()), 0, 7); | |
6a488035 TO |
185 | $this->type("{$cusId_1}", $custFname); |
186 | $this->type("{$cusId_2}", $custMname); | |
187 | $this->type("{$cusId_3}", $custLname); | |
188 | $this->click("_qf_CustomData_upload"); | |
efb29358 CW |
189 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
190 | // Sleep should never be used for wait for anything to load from the server | |
191 | // Justification for this instance: FIXME | |
6a488035 | 192 | sleep(2); |
d2771e94 | 193 | $this->openCiviPage('case', 'reset=1'); |
6a488035 | 194 | $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$contactName}']/../../td[8]/a[text()='Change Custom Data']"); |
efb29358 CW |
195 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
196 | // Sleep should never be used for wait for anything to load from the server | |
197 | // Justification for this instance: FIXME | |
6a488035 TO |
198 | sleep(3); |
199 | $openCaseChangeData = array( | |
200 | "Client" => $displayName, | |
201 | "Activity Type" => "Change Custom Data", | |
202 | "Subject" => $customGrp1 . " : change data", | |
203 | "Created By" => "{$testUserFirstName} {$testUserLastName}", | |
204 | "Reported By" => "{$testUserFirstName} {$testUserLastName}", | |
205 | "Date and Time" => $today, | |
206 | "Status" => "Completed", | |
207 | "Priority" => "Normal", | |
208 | ); | |
209 | $this->webtestVerifyTabularData($openCaseChangeData); | |
210 | $this->click("xpath=//div[@class='ui-dialog-buttonset']/button/span[text()='Done']"); | |
efb29358 CW |
211 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
212 | // Sleep should never be used for wait for anything to load from the server | |
213 | // Justification for this instance: FIXME | |
6a488035 TO |
214 | sleep(2); |
215 | $this->_testAdvansearchCaseData($customId, $custFname, $custMname, $custLname); | |
216 | $this->_testDeleteCustomData($customGrpId1, $customId); | |
217 | } | |
218 | ||
219 | function _testVerifyCaseSummary($validateStrings, $activityTypes) { | |
220 | $this->assertStringsPresent($validateStrings); | |
221 | foreach ($activityTypes as $aType) { | |
222 | $this->assertText("activity_type_id", $aType); | |
223 | } | |
224 | $this->assertElementPresent("link=Assign to Another Client", "Assign to Another Client link is missing."); | |
225 | $this->assertElementPresent("name=case_report_all", "Print Case Summary button is missing."); | |
226 | } | |
227 | ||
228 | function _testGetCustomFieldId($customGrpId1) { | |
229 | $customId = array(); | |
230 | ||
231 | // Create a custom data to add in profile | |
6a488035 TO |
232 | $field1 = "Fname" . substr(sha1(rand()), 0, 7); |
233 | $field2 = "Mname" . substr(sha1(rand()), 0, 7); | |
234 | $field3 = "Lname" . substr(sha1(rand()), 0, 7); | |
235 | ||
236 | // add custom fields for group 1 | |
0bd37c06 | 237 | $this->openCiviPage('admin/custom/group/field/add', array('reset' => 1, 'action' => 'add', 'gid' => $customGrpId1)); |
6a488035 TO |
238 | $this->type("label", $field1); |
239 | $this->check("is_searchable"); | |
240 | $this->click("_qf_Field_next_new-bottom"); | |
241 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
242 | ||
243 | $this->type("label", $field2); | |
244 | $this->check("is_searchable"); | |
245 | $this->click("_qf_Field_next_new-bottom"); | |
246 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
247 | ||
248 | $this->type("label", $field3); | |
249 | $this->check("is_searchable"); | |
250 | $this->click("_qf_Field_next-bottom"); | |
251 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
252 | ||
253 | // get id of custom fields | |
0bd37c06 | 254 | $this->openCiviPage("admin/custom/group/field", array('reset' => 1, 'action' => 'browse', 'gid' => $customGrpId1)); |
6a488035 TO |
255 | $custom1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[1]/td[8]/span/a[text()='Edit Field']/@href")); |
256 | $custom1 = $custom1[1]; | |
257 | array_push($customId, $custom1); | |
258 | $custom2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[2]/td[8]/span/a[text()='Edit Field']/@href")); | |
259 | $custom2 = $custom2[1]; | |
260 | array_push($customId, $custom2); | |
261 | $custom3 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[3]/td[8]/span/a[text()='Edit Field']/@href")); | |
262 | $custom3 = $custom3[1]; | |
263 | array_push($customId, $custom3); | |
264 | ||
265 | return $customId; | |
266 | } | |
267 | ||
268 | function _testDeleteCustomData($customGrpId1, $customId) { | |
269 | // delete all custom data | |
0bd37c06 | 270 | $this->openCiviPage("admin/custom/group/field", array('action' => 'delete', 'reset' => '1', 'gid' => $customGrpId1, 'id' => $customId[0])); |
6a488035 TO |
271 | $this->click("_qf_DeleteField_next-bottom"); |
272 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
273 | ||
0bd37c06 | 274 | $this->openCiviPage("admin/custom/group/field", array('action' => 'delete', 'reset' => '1', 'gid' => $customGrpId1, 'id' => $customId[1])); |
6a488035 TO |
275 | $this->click("_qf_DeleteField_next-bottom"); |
276 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
277 | ||
0bd37c06 | 278 | $this->openCiviPage("admin/custom/group/field", array('action' => 'delete', 'reset' => '1', 'gid' => $customGrpId1, 'id' => $customId[2])); |
6a488035 TO |
279 | $this->click("_qf_DeleteField_next-bottom"); |
280 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
281 | ||
0bd37c06 | 282 | $this->openCiviPage("admin/custom/group", "action=delete&reset=1&id=" . $customGrpId1); |
6a488035 TO |
283 | $this->click("_qf_DeleteGroup_next-bottom"); |
284 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
285 | } | |
286 | ||
287 | function _testAdvansearchCaseData($customId, $custFname, $custMname, $custLname) { | |
6a488035 | 288 | // search casecontact |
d2771e94 | 289 | $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); |
6a488035 | 290 | $this->click("CiviCase"); |
0bd37c06 | 291 | $this->waitForElementPresent('case_from_relative'); |
6a488035 TO |
292 | $cusId_1 = 'custom_' . $customId[0]; |
293 | $cusId_2 = 'custom_' . $customId[1]; | |
294 | $cusId_3 = 'custom_' . $customId[2]; | |
295 | $this->type("{$cusId_1}", $custFname); | |
296 | $this->type("{$cusId_2}", $custMname); | |
297 | $this->type("{$cusId_3}", $custLname); | |
298 | $this->click("_qf_Advanced_refresh"); | |
299 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
d2771e94 | 300 | $this->assertElementContainsText('crm-container', '1 Contact'); |
6a488035 TO |
301 | } |
302 | } | |
303 |