Start migrating to use clickLink method
[civicrm-core.git] / tests / phpunit / WebTest / Case / AddCaseTest.php
CommitLineData
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
28require_once 'CiviTest/CiviSeleniumTestCase.php';
29class WebTest_Case_AddCaseTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testStandaloneCaseAdd() {
6a488035 36 // Log in as admin first to verify permissions for CiviCase
42daf119 37 $this->webtestLogin('admin');
6a488035
TO
38
39 // Enable CiviCase module if necessary
b9715b8a 40 $this->enableComponents("CiviCase");
6a488035
TO
41
42 // let's give full CiviCase permissions to demo user (registered user).
43 $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');
44 $this->changePermissions($permission);
45
42daf119
CW
46 // Log in as normal user
47 $this->webtestLogin();
48
6a488035 49 // Go to reserved New Individual Profile to set value for logged in user's contact name (we'll need that later)
d671d131 50 $this->openCiviPage('profile/edit', 'reset=1&gid=4', NULL);
6a488035
TO
51 $testUserFirstName = "Testuserfirst";
52 $testUserLastName = "Testuserlast";
53 $this->waitForPageToLoad($this->getTimeoutMsec());
54 $this->waitForElementPresent("_qf_Edit_next");
55 $this->type("first_name", $testUserFirstName);
56 $this->type("last_name", $testUserLastName);
225a8648 57 $this->clickLink("_qf_Edit_next", "profilewrap4");
6a488035 58 // Is status message correct?
d2771e94 59 $this->assertElementContainsText('crm-container', "Thank you. Your information has been saved.", "Save successful status message didn't show up after saving profile to update testUserName!");
6a488035 60
d2771e94 61 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
6a488035
TO
62
63 // Try submitting the form without creating or selecting a contact (test for CRM-7971)
225a8648 64 $this->clickLink("_qf_Case_upload-bottom", "css=span.crm-error");
d2771e94 65 $this->assertElementContainsText('Case', "Please select a contact or create new contact", "Expected form rule error for submit without selecting contact did not show up after clicking Save.");
6a488035
TO
66
67 // Adding contact with randomized first name (so we can then select that contact when creating case)
68 // We're using pop-up New Contact dialog
69 $firstName = substr(sha1(rand()), 0, 7);
70 $lastName = "Fraser";
71 $contactName = "{$lastName}, {$firstName}";
72 $displayName = "{$firstName} {$lastName}";
73 $email = "{$lastName}.{$firstName}@example.org";
74 $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4);
75
76 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
77 $caseTypeLabel = "Adult Day Care Referral";
78 // activity types we expect for this case type
42daf119
CW
79 $activityTypes = array("ADC referral", "Follow up", "Medical evaluation", "Mental health evaluation");
80 $caseRoles = array("Senior Services Coordinator", "Health Services Coordinator", "Benefits Specialist", "Client");
6a488035 81 $caseStatusLabel = "Ongoing";
42daf119 82 $subject = "Safe daytime setting - senior female";
6a488035
TO
83 $this->select("medium_id", "value=1");
84 $location = "Main offices";
85 $this->type("activity_location", $location);
86 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
87 $this->fireEvent('activity_details', 'focus');
88 $this->fillRichTextField("activity_details", $details, 'CKEditor');
89 $this->type("activity_subject", $subject);
90
91 $this->select("case_type_id", "label={$caseTypeLabel}");
92 $this->select("status_id", "label={$caseStatusLabel}");
93 // Choose Case Start Date.
94 // Using helper webtestFillDate function.
95 $this->webtestFillDate('start_date', 'now');
96 $today = date('F jS, Y', strtotime('now'));
97 // echo 'Today is ' . $today;
98 $this->type("duration", "20");
225a8648 99 $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom");
6a488035
TO
100
101 // Is status message correct?
d2771e94 102 $this->assertElementContainsText('crm-notification-container', "Case opened successfully.", "Save successful status message didn't show up after saving!");
6a488035
TO
103
104 $summaryStrings = array(
105 "Case Summary",
106 $displayName,
107 "Case Type: {$caseTypeLabel}",
108 "Start Date: {$today}",
109 "Status: {$caseStatusLabel}",
110 );
111
112 $this->_testVerifyCaseSummary($summaryStrings, $activityTypes);
113 $this->_testVerifyCaseRoles($caseRoles, "{$testUserLastName}, {$testUserFirstName}");
114 $this->_testVerifyCaseActivities($activityTypes);
115
116 $openCaseData = array(
117 "Client" => $displayName,
118 "Activity Type" => "Open Case",
119 "Subject" => $subject,
120 "Created By" => "{$testUserFirstName} {$testUserLastName}",
121 "Reported By" => "{$testUserFirstName} {$testUserLastName}",
122 "Medium" => "In Person",
123 "Location" => $location,
124 "Date and Time" => $today,
125 "Details" => $details,
126 "Status" => "Completed",
127 "Priority" => "Normal",
128 );
129
130 $this->_testVerifyOpenCaseActivity($subject, $openCaseData);
131
132 //change the case status to Resolved to get the end date
133 $this->click("xpath=//form[@id='CaseView']/div[2]/table/tbody/tr/td[4]/a");
134 $this->waitForElementPresent("_qf_Activity_cancel-bottom");
135 $this->select("case_status_id","value=2");
136 $this->click("_qf_Activity_upload-top");
137 $this->waitForPageToLoad($this->getTimeoutMsec());
138
139 $this->_testSearchbyDate($firstName, $lastName, "this.quarter");
140 $this->_testSearchbyDate($firstName, $lastName, "0");
141 $this->_testSearchbyDate($firstName, $lastName, "this.year");
142 }
143
144 function _testVerifyCaseSummary($validateStrings, $activityTypes) {
145 $this->assertStringsPresent($validateStrings);
146 foreach ($activityTypes as $aType) {
147 $this->assertText("activity_type_id", $aType);
148 }
149 $this->assertElementPresent("link=Assign to Another Client", "Assign to Another Client link is missing.");
150 $this->assertElementPresent("name=case_report_all", "Print Case Summary button is missing.");
151 }
152
153 function _testVerifyCaseRoles($caseRoles, $creatorName) {
154 $this->waitForElementPresent("xpath=//table[@id='caseRoles-selector']/tbody/tr[4]/td[2]/a");
155 // check that expected roles are listed in the Case Roles pane
156 foreach ($caseRoles as $role) {
157 $this->assertText("css=div.crm-case-roles-block", $role);
158 }
159 // check that case creator role has been assigned to logged in user
160 $this->verifyText("xpath=//table[@id='caseRoles-selector']/tbody/tr[4]/td[2]", $creatorName);
161 }
162
163 function _testVerifyCaseActivities($activityTypes) {
164 // check that expected auto-created activities are listed in the Case Activities table
165 foreach ($activityTypes as $aType) {
166 $this->assertText("activities-selector", $aType);
167 }
168 }
169
170 function _testVerifyOpenCaseActivity($subject, $openCaseData) {
171 // check that open case subject is present
172 $this->assertText("activities-selector", $subject);
173 // click open case activity pop-up dialog
174 $this->click("link=$subject");
175 $this->waitForElementPresent("view-activity");
176 $this->waitForElementPresent("css=tr.crm-case-activity-view-Activity");
177 // set page location of table containing activity view data
178 $activityViewPrefix = "//div[@id='activity-content']";
179 $activityViewTableId = "crm-activity-view-table";
180 // Probably don't need both tableId and prefix - but good examples for other situations where only one can be used
181
182 $this->webtestVerifyTabularData($openCaseData, '', $activityViewTableId);
183 $this->click("xpath=//span[@class='ui-icon ui-icon-closethick']");
184 }
185
186 function _testSearchbyDate($firstName, $lastName, $action) {
187 // Find Cases
188 if ($action != "0") {
d2771e94 189 $this->openCiviPage('case/search', 'reset=1');
6a488035
TO
190 $this->select("case_from_relative", "value=$action");
191 $this->select("case_to_relative", "value=$action");
192 $this->click("_qf_Search_refresh");
193 $this->waitForPageToLoad($this->getTimeoutMsec());
d2771e94 194 $this->assertElementContainsText('Search', "$lastName, $firstName");
6a488035
TO
195 }
196 else {
197 //select date range
d2771e94 198 $this->openCiviPage('case/search', 'reset=1', '_qf_Search_refresh-bottom');
6a488035
TO
199 $this->select("case_from_relative", "value=$action");
200 $this->webtestFillDate("case_from_start_date_low", "-1 month");
201 $this->webtestFillDate("case_from_start_date_high", "+1 month");
202 $this->select("case_to_relative", "value=$action");
203 $this->webtestFillDate("case_to_end_date_low", "-1 month");
204 $this->webtestFillDate("case_to_end_date_high", "+1 month");
205 $this->click("_qf_Search_refresh-bottom");
206 $this->waitForPageToLoad($this->getTimeoutMsec());
d2771e94 207 $this->assertElementContainsText('Search', "$lastName, $firstName");
6a488035
TO
208 }
209
210 //Advanced Search
d2771e94 211 $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh');
6a488035
TO
212 $this->click("CiviCase");
213 $this->waitForElementPresent("xpath=//div[@id='case-search']/table/tbody/tr[3]/td[2]/input[3]");
214 if ($action != "0") {
215 $this->select("case_from_relative", "value=$action");
216 $this->select("case_to_relative", "value=$action");
217 }
218 else {
219 $this->select("case_from_relative", "value=$action");
220 $this->webtestFillDate("case_from_start_date_low", "-1 month");
221 $this->webtestFillDate("case_from_start_date_high", "+1 month");
222 $this->select("case_to_relative", "value=$action");
223 $this->webtestFillDate("case_to_end_date_low", "-1 month");
224 $this->webtestFillDate("case_to_end_date_high", "+1 month");
225 }
226 $this->click("_qf_Advanced_refresh");
227 $this->waitForPageToLoad($this->getTimeoutMsec());
d2771e94 228 $this->assertElementContainsText('Advanced', "$lastName, $firstName");
6a488035
TO
229 }
230}
231