3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Case_CaseCustomFieldsTest
32 class WebTest_Case_CaseCustomFieldsTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testAddCase() {
39 $this->webtestLogin('admin');
41 // Enable CiviCase module if necessary
42 $this->enableComponents("CiviCase");
44 $customGrp1 = "CaseCustom_Data1_" . substr(sha1(rand()), 0, 7);
46 // create custom group1
47 $this->openCiviPage('admin/custom/group', 'reset=1');
48 $this->clickLink("newCustomDataGroup");
49 $this->type("title", $customGrp1);
50 $this->select("extends[0]", "value=Case");
51 $this->waitForAjaxContent();
52 $this->select("extends_1", "value=2");
53 $this->clickLink("_qf_Group_next-bottom");
55 // get custom group id
56 $customGrpId1 = $this->urlArg('gid');
58 $customId = $this->_testGetCustomFieldId($customGrpId1);
59 $cusId_1 = 'custom_' . $customId[0] . '_-1';
60 $cusId_2 = 'custom_' . $customId[1] . '_-1';
61 $cusId_3 = 'custom_' . $customId[2] . '_-1';
63 // let's give full CiviCase permissions.
65 'edit-2-access-all-cases-and-activities',
66 'edit-2-access-my-cases-and-activities',
67 'edit-2-administer-civicase',
68 'edit-2-delete-in-civicase',
70 $this->changePermissions($permission);
72 // Log in as normal user
73 $this->webtestLogin();
75 // Go to reserved New Individual Profile to set value for logged in user's contact name (we'll need that later)
76 $this->openCiviPage('profile/edit', 'reset=1&gid=4', '_qf_Edit_next');
77 $testUserFirstName = "Testuserfirst";
78 $testUserLastName = "Testuserlast";
79 $this->type("first_name", $testUserFirstName);
80 $this->type("last_name", $testUserLastName);
81 $this->clickLink("_qf_Edit_next", "profilewrap4");
83 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
85 // Adding contact with randomized first name (so we can then select that contact when creating case)
86 $custFname = "Mike" . substr(sha1(rand()), 0, 7);
87 $custMname = "Dav" . substr(sha1(rand()), 0, 7);
88 $custLname = "Krist" . substr(sha1(rand()), 0, 7);
89 // We're using pop-up New Contact dialog
90 $client = $this->createDialogContact("client_id");
92 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
93 $caseTypeLabel = "Adult Day Care Referral";
95 $caseStatusLabel = "Ongoing";
96 $subject = "Safe daytime setting - senior female";
97 $this->select("medium_id", "value=1");
98 $location = "Main offices";
99 $this->type("activity_location", $location);
100 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
101 $this->fillRichTextField("activity_details", $details, 'CKEditor');
102 $this->type("activity_subject", $subject);
104 $this->select("case_type_id", "label={$caseTypeLabel}");
105 $this->waitForAjaxContent();
106 $this->select("status_id", "label={$caseStatusLabel}");
108 // Choose Case Start Date.
109 // Using helper webtestFillDate function.
110 $this->webtestFillDate('start_date', 'now');
111 $today = date('F jS, Y', strtotime('now'));
113 $this->type("duration", "20");
114 $this->type("{$cusId_1}", $custFname);
115 $this->type("{$cusId_2}", $custMname);
116 $this->type("{$cusId_3}", $custLname);
117 $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom");
119 // Is status message correct?
120 $this->checkCRMAlert("Case opened successfully.");
121 $this->clickLink("_qf_CaseView_cancel-bottom");
122 $this->openCiviPage('case', 'reset=1', "xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[8]/a[text()='Open Case']");
123 $this->clickPopupLink("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[8]/a[text()='Open Case']");
125 $openCaseData = array(
126 "Client" => $client['display_name'],
127 "Activity Type" => "Open Case",
128 "Subject" => $subject,
129 "Created By" => "{$testUserFirstName} {$testUserLastName}",
130 "Reported By" => "{$testUserFirstName} {$testUserLastName}",
131 "Medium" => "In Person",
132 "Location" => $location,
133 "Date and Time" => $today,
134 "Status" => "Completed",
135 "Priority" => "Normal",
137 $this->webtestVerifyTabularData($openCaseData);
138 $this->click("xpath=//span[@class='ui-button-icon-primary ui-icon fa-times']");
140 // verify if custom data is present
141 $this->openCiviPage('case', 'reset=1');
142 $this->waitForElementPresent("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[9]/span/a[1][text()='Manage']");
143 $this->clickLink("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[9]/span/a[1][text()='Manage']");
145 $this->clickAjaxLink("css=#{$customGrp1} .crm-accordion-header", "css=#{$customGrp1} a.button");
146 $cusId_1 = 'custom_' . $customId[0] . '_1';
147 $cusId_2 = 'custom_' . $customId[1] . '_1';
148 $cusId_3 = 'custom_' . $customId[2] . '_1';
149 $this->clickAjaxLink("css=#{$customGrp1} a.button", $cusId_1);
151 $custFname = "Miky" . substr(sha1(rand()), 0, 7);
152 $custMname = "Davy" . substr(sha1(rand()), 0, 7);
153 $custLname = "Kristy" . substr(sha1(rand()), 0, 7);
154 $this->type("{$cusId_1}", $custFname);
155 $this->type("{$cusId_2}", $custMname);
156 $this->type("{$cusId_3}", $custLname);
157 $this->clickAjaxLink("_qf_CustomData_upload");
159 $this->openCiviPage('case', 'reset=1');
160 $this->clickAjaxLink("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[8]/a[text()='Change Custom Data']");
162 $openCaseChangeData = array(
163 "Client" => $client['display_name'],
164 "Activity Type" => "Change Custom Data",
165 "Subject" => $customGrp1 . " : change data",
166 "Created By" => "{$testUserFirstName} {$testUserLastName}",
167 "Reported By" => "{$testUserFirstName} {$testUserLastName}",
168 "Date and Time" => $today,
169 "Status" => "Completed",
170 "Priority" => "Normal",
172 $this->webtestVerifyTabularData($openCaseChangeData);
173 $this->_testAdvansearchCaseData($customId, $custFname, $custMname, $custLname);
174 $this->_testDeleteCustomData($customGrpId1, $customId);
178 * @param $customGrpId1
179 * @param bool $noteRichEditor
183 public function _testGetCustomFieldId($customGrpId1, $noteRichEditor = FALSE) {
185 $this->openCiviPage('admin/custom/group/field/add', array('reset' => 1, 'action' => 'add', 'gid' => $customGrpId1));
187 if ($noteRichEditor) {
188 // Create a custom data to add in profile
189 $field1 = "Note_Textarea" . substr(sha1(rand()), 0, 7);
190 $field2 = "Note_Richtexteditor" . substr(sha1(rand()), 0, 7);
192 // add custom fields for group 1
193 $this->type("label", $field1);
194 $this->select("data_type_0", "value=4");
195 $this->select("data_type_1", "value=TextArea");
196 $this->check("is_searchable");
197 $this->clickLink("_qf_Field_next_new-bottom");
199 $this->type("label", $field2);
200 $this->select("data_type_0", "value=4");
201 //$this->select("data_type_1", "value=TextArea");
202 $this->select("data_type_1", "value=RichTextEditor");
203 $this->check("is_searchable");
204 $this->clickLink("_qf_Field_next_new-bottom");
206 // get id of custom fields
207 $this->openCiviPage("admin/custom/group/field", array(
209 'action' => 'browse',
210 'gid' => $customGrpId1,
212 $custom1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[1]/td[8]/span/a[text()='Edit Field']/@href"));
213 $custom1 = $custom1[1];
214 array_push($customId, $custom1);
215 $custom2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[2]/td[8]/span/a[text()='Edit Field']/@href"));
216 $custom2 = $custom2[1];
217 array_push($customId, $custom2);
220 // Create a custom data to add in profile
221 $field1 = "Fname" . substr(sha1(rand()), 0, 7);
222 $field2 = "Mname" . substr(sha1(rand()), 0, 7);
223 $field3 = "Lname" . substr(sha1(rand()), 0, 7);
225 // add custom fields for group 1
226 $this->type("label", $field1);
227 $this->check("is_searchable");
228 $this->clickLink("_qf_Field_next_new-bottom");
230 $this->type("label", $field2);
231 $this->check("is_searchable");
232 $this->clickLink("_qf_Field_next_new-bottom");
234 $this->type("label", $field3);
235 $this->check("is_searchable");
236 $this->clickLink("_qf_Field_done-bottom");
238 // get id of custom fields
239 $this->openCiviPage("admin/custom/group/field", array(
241 'action' => 'browse',
242 'gid' => $customGrpId1,
244 $custom1 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[1]/td[8]/span/a[text()='Edit Field']/@href"));
245 $custom1 = $custom1[1];
246 array_push($customId, $custom1);
247 $custom2 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[2]/td[8]/span/a[text()='Edit Field']/@href"));
248 $custom2 = $custom2[1];
249 array_push($customId, $custom2);
250 $custom3 = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr[3]/td[8]/span/a[text()='Edit Field']/@href"));
251 $custom3 = $custom3[1];
252 array_push($customId, $custom3);
259 * @param $customGrpId1
260 * @param array $customId
262 public function _testDeleteCustomData($customGrpId1, $customId) {
263 // delete all custom data
264 foreach ($customId as $cKey => $cValue) {
265 $this->openCiviPage("admin/custom/group/field", array(
266 'action' => 'delete',
268 'gid' => $customGrpId1,
271 $this->clickLink("_qf_DeleteField_next-bottom");
274 // delete custom group
275 $this->openCiviPage("admin/custom/group", "action=delete&reset=1&id=" . $customGrpId1);
276 $this->clickLink("_qf_DeleteGroup_next-bottom");
282 public function testCaseCustomNoteRichEditor() {
283 $this->webtestLogin('admin');
285 //setting ckeditor as WYSIWYG
286 $this->openCiviPage('admin/setting/preferences/display', 'reset=1', '_qf_Display_next-bottom');
287 $this->select('editor_id', 'CKEditor');
288 $this->clickLink('_qf_Display_next-bottom');
290 // Enable CiviCase module if necessary
291 $this->enableComponents("CiviCase");
293 $customGrp1 = "CaseCustom_Data1_" . substr(sha1(rand()), 0, 7);
295 // create custom group1
296 $this->openCiviPage('admin/custom/group', 'reset=1');
297 $this->clickLink("newCustomDataGroup");
298 $this->type("title", $customGrp1);
299 $this->select("extends[0]", "value=Case");
300 $this->select("extends_1", "value=2");
301 $this->clickLink("_qf_Group_next-bottom");
303 // get custom group id
304 $customGrpId1 = $this->urlArg('gid');
306 $customId = $this->_testGetCustomFieldId($customGrpId1, TRUE);
307 $cusId_1 = 'custom_' . $customId[0] . '_-1';
308 $cusId_2 = 'custom_' . $customId[1] . '_-1';
310 // let's give full CiviCase permissions.
312 'edit-2-access-all-cases-and-activities',
313 'edit-2-access-my-cases-and-activities',
314 'edit-2-administer-civicase',
315 'edit-2-delete-in-civicase',
317 $this->changePermissions($permission);
319 // Log in as normal user
320 $this->webtestLogin();
322 // Go to reserved New Individual Profile to set value for logged in user's contact name (we'll need that later)
323 $this->openCiviPage('profile/edit', 'reset=1&gid=4', '_qf_Edit_next');
324 $testUserFirstName = "Testuserfirst";
325 $testUserLastName = "Testuserlast";
326 $this->type("first_name", $testUserFirstName);
327 $this->type("last_name", $testUserLastName);
328 $this->clickLink("_qf_Edit_next", "profilewrap4");
330 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
332 // Adding contact with randomized first name (so we can then select that contact when creating case)
333 $custFname = "Mike" . substr(sha1(rand()), 0, 7);
334 $custLname = "Krist" . substr(sha1(rand()), 0, 7);
335 // We're using pop-up New Contact dialog
336 $client = $this->createDialogContact("client_id");
338 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
339 $caseTypeLabel = "Adult Day Care Referral";
341 $caseStatusLabel = "Ongoing";
342 $subject = "Safe daytime setting - senior female";
343 $this->select("medium_id", "value=1");
344 $location = "Main offices";
345 $this->type("activity_location", $location);
346 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
347 $this->fillRichTextField("activity_details", $details, 'CKEditor');
348 $this->type("activity_subject", $subject);
350 $this->select("case_type_id", "label={$caseTypeLabel}");
351 $this->select("status_id", "label={$caseStatusLabel}");
353 // Choose Case Start Date.
354 // Using helper webtestFillDate function.
355 $this->webtestFillDate('start_date', 'now');
356 $today = date('F jS, Y', strtotime('now'));
358 $this->type("duration", "20");
359 $this->type("{$cusId_1}", $custFname);
360 $this->type("{$cusId_2}", $custLname);
361 $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom");
363 // Is status message correct?
364 $this->checkCRMAlert("Case opened successfully.");
365 $this->clickLink("_qf_CaseView_cancel-bottom");
367 $this->openCiviPage('case', 'reset=1');
368 $this->waitForElementPresent("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[8]/a[text()='Open Case']");
370 $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[8]/a[text()='Open Case']");
372 $openCaseData = array(
373 "Client" => $client['display_name'],
374 "Activity Type" => "Open Case",
375 "Subject" => $subject,
376 "Created By" => "{$testUserFirstName} {$testUserLastName}",
377 "Reported By" => "{$testUserFirstName} {$testUserLastName}",
378 "Medium" => "In Person",
379 "Location" => $location,
380 "Date and Time" => $today,
381 "Status" => "Completed",
382 "Priority" => "Normal",
384 // wait for elements to load
385 foreach ($openCaseData as $label => $value) {
386 $this->waitForElementPresent("xpath=//table/tbody/tr/td[text()='{$label}']/following-sibling::td");
388 $this->webtestVerifyTabularData($openCaseData);
390 // verify if custom data is present
391 $this->openCiviPage('case', 'reset=1');
392 $this->clickLink("xpath=//table[@class='caseSelector']/tbody//tr/td[2]/a[text()='{$client['sort_name']}']/../../td[9]/span/a[text()='Manage']", "css=#{$customGrp1} .crm-accordion-header");
394 $this->click("css=#{$customGrp1} .crm-accordion-header");
396 $cusId_1 = 'custom_' . $customId[0] . '_1';
397 $cusId_2 = 'custom_' . $customId[1] . '_1';
398 $this->clickLink("css=#{$customGrp1} a.button", '_qf_CustomData_cancel-bottom', FALSE);
399 $this->waitForElementPresent("xpath=//span[@class='ui-dialog-title']");
400 $this->assertElementContainsText("xpath=//span[@class='ui-dialog-title']", "Edit $customGrp1");
402 $custFname = "Miky" . substr(sha1(rand()), 0, 7);
403 $custLname = "Kristy" . substr(sha1(rand()), 0, 7);
404 $this->type("{$cusId_1}", $custFname);
406 // Wait for rich text editor element
407 $this->waitForElementPresent("css=div#cke_{$cusId_2}");
409 $this->fillRichTextField("{$cusId_2}", $custLname, 'CKEditor');
410 $this->click("_qf_CustomData_upload");
411 // delete custom data
412 $this->_testDeleteCustomData($customGrpId1, $customId);
416 * @param int $customId
417 * @param string $custFname
418 * @param string $custMname
421 public function _testAdvansearchCaseData($customId, $custFname, $custMname, $custLname) {
422 // search casecontact
423 $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh');
424 $this->click("CiviCase");
425 $this->waitForElementPresent('case_from_relative');
426 $cusId_1 = 'custom_' . $customId[0];
427 $cusId_2 = 'custom_' . $customId[1];
428 $cusId_3 = 'custom_' . $customId[2];
429 $this->type("{$cusId_1}", $custFname);
430 $this->type("{$cusId_2}", $custMname);
431 $this->type("{$cusId_3}", $custLname);
432 $this->click("_qf_Advanced_refresh");
433 $this->waitForPageToLoad($this->getTimeoutMsec());
434 $this->assertElementContainsText('crm-container', '1 Contact');