Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | ||
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Case_AddCaseTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Case_AddCaseTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testStandaloneCaseAdd() { | |
6a488035 | 39 | // Log in as admin first to verify permissions for CiviCase |
42daf119 | 40 | $this->webtestLogin('admin'); |
6a488035 TO |
41 | |
42 | // Enable CiviCase module if necessary | |
b9715b8a | 43 | $this->enableComponents("CiviCase"); |
6a488035 TO |
44 | |
45 | // let's give full CiviCase permissions to demo user (registered user). | |
46 | $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'); | |
47 | $this->changePermissions($permission); | |
48 | ||
42daf119 CW |
49 | // Log in as normal user |
50 | $this->webtestLogin(); | |
51 | ||
6a488035 | 52 | // Go to reserved New Individual Profile to set value for logged in user's contact name (we'll need that later) |
d671d131 | 53 | $this->openCiviPage('profile/edit', 'reset=1&gid=4', NULL); |
6a488035 TO |
54 | $testUserFirstName = "Testuserfirst"; |
55 | $testUserLastName = "Testuserlast"; | |
56 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
57 | $this->waitForElementPresent("_qf_Edit_next"); | |
58 | $this->type("first_name", $testUserFirstName); | |
59 | $this->type("last_name", $testUserLastName); | |
225a8648 | 60 | $this->clickLink("_qf_Edit_next", "profilewrap4"); |
6a488035 | 61 | // Is status message correct? |
d2771e94 | 62 | $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 | 63 | |
d2771e94 | 64 | $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom'); |
6a488035 TO |
65 | |
66 | // Try submitting the form without creating or selecting a contact (test for CRM-7971) | |
225a8648 | 67 | $this->clickLink("_qf_Case_upload-bottom", "css=span.crm-error"); |
cba9346d | 68 | $this->assertElementContainsText('Case', "Client is a required field.", "Expected form rule error for submit without selecting contact did not show up after clicking Save."); |
6a488035 TO |
69 | |
70 | // Adding contact with randomized first name (so we can then select that contact when creating case) | |
71 | // We're using pop-up New Contact dialog | |
72 | $firstName = substr(sha1(rand()), 0, 7); | |
73 | $lastName = "Fraser"; | |
74 | $contactName = "{$lastName}, {$firstName}"; | |
75 | $displayName = "{$firstName} {$lastName}"; | |
76 | $email = "{$lastName}.{$firstName}@example.org"; | |
cba9346d | 77 | $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4, "s2id_client_id"); |
6a488035 TO |
78 | |
79 | // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files. | |
80 | $caseTypeLabel = "Adult Day Care Referral"; | |
81 | // activity types we expect for this case type | |
42daf119 CW |
82 | $activityTypes = array("ADC referral", "Follow up", "Medical evaluation", "Mental health evaluation"); |
83 | $caseRoles = array("Senior Services Coordinator", "Health Services Coordinator", "Benefits Specialist", "Client"); | |
6a488035 | 84 | $caseStatusLabel = "Ongoing"; |
42daf119 | 85 | $subject = "Safe daytime setting - senior female"; |
6a488035 TO |
86 | $this->select("medium_id", "value=1"); |
87 | $location = "Main offices"; | |
88 | $this->type("activity_location", $location); | |
89 | $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented."; | |
90 | $this->fireEvent('activity_details', 'focus'); | |
91 | $this->fillRichTextField("activity_details", $details, 'CKEditor'); | |
92 | $this->type("activity_subject", $subject); | |
93 | ||
94 | $this->select("case_type_id", "label={$caseTypeLabel}"); | |
95 | $this->select("status_id", "label={$caseStatusLabel}"); | |
96 | // Choose Case Start Date. | |
97 | // Using helper webtestFillDate function. | |
98 | $this->webtestFillDate('start_date', 'now'); | |
99 | $today = date('F jS, Y', strtotime('now')); | |
76e86fd8 | 100 | |
6a488035 | 101 | $this->type("duration", "20"); |
225a8648 | 102 | $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom"); |
6a488035 TO |
103 | |
104 | // Is status message correct? | |
6c5f7368 | 105 | $this->waitForText('crm-notification-container', "Case opened successfully."); |
6a488035 TO |
106 | |
107 | $summaryStrings = array( | |
cba9346d | 108 | "Summary", |
6a488035 | 109 | $displayName, |
cba9346d | 110 | "Type: {$caseTypeLabel}", |
111 | "Open Date: {$today}", | |
6a488035 TO |
112 | "Status: {$caseStatusLabel}", |
113 | ); | |
114 | ||
115 | $this->_testVerifyCaseSummary($summaryStrings, $activityTypes); | |
116 | $this->_testVerifyCaseRoles($caseRoles, "{$testUserLastName}, {$testUserFirstName}"); | |
117 | $this->_testVerifyCaseActivities($activityTypes); | |
118 | ||
119 | $openCaseData = array( | |
120 | "Client" => $displayName, | |
121 | "Activity Type" => "Open Case", | |
122 | "Subject" => $subject, | |
123 | "Created By" => "{$testUserFirstName} {$testUserLastName}", | |
124 | "Reported By" => "{$testUserFirstName} {$testUserLastName}", | |
125 | "Medium" => "In Person", | |
126 | "Location" => $location, | |
127 | "Date and Time" => $today, | |
128 | "Details" => $details, | |
129 | "Status" => "Completed", | |
130 | "Priority" => "Normal", | |
131 | ); | |
132 | ||
133 | $this->_testVerifyOpenCaseActivity($subject, $openCaseData); | |
76e86fd8 | 134 | |
6a488035 TO |
135 | //change the case status to Resolved to get the end date |
136 | $this->click("xpath=//form[@id='CaseView']/div[2]/table/tbody/tr/td[4]/a"); | |
137 | $this->waitForElementPresent("_qf_Activity_cancel-bottom"); | |
138 | $this->select("case_status_id","value=2"); | |
139 | $this->click("_qf_Activity_upload-top"); | |
76e86fd8 | 140 | |
6a488035 TO |
141 | $this->_testSearchbyDate($firstName, $lastName, "this.quarter"); |
142 | $this->_testSearchbyDate($firstName, $lastName, "0"); | |
143 | $this->_testSearchbyDate($firstName, $lastName, "this.year"); | |
f6262e1a | 144 | $this->_testAssignToClient($firstName, $lastName, $caseTypeLabel); |
6a488035 TO |
145 | } |
146 | ||
c4e6d4e8 PJ |
147 | function testAjaxCustomGroupLoad() { |
148 | $this->webtestLogin(); | |
149 | ||
150 | // Enable CiviCase module if necessary | |
151 | $this->enableComponents("CiviCase"); | |
152 | ||
153 | $triggerElement = array('name' => 'case_type_id', 'type' => 'select'); | |
154 | $customSets = array( | |
155 | array('entity' => 'Case', 'subEntity' => 'Housing Support', 'triggerElement' => $triggerElement), | |
156 | ); | |
157 | ||
158 | $pageUrl = array('url' => 'case/add', 'args' => "reset=1&action=add&atype=13&context=standalone"); | |
159 | $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl); | |
160 | } | |
161 | ||
4cbe18b8 EM |
162 | /** |
163 | * @param $validateStrings | |
164 | * @param $activityTypes | |
165 | */ | |
6a488035 TO |
166 | function _testVerifyCaseSummary($validateStrings, $activityTypes) { |
167 | $this->assertStringsPresent($validateStrings); | |
168 | foreach ($activityTypes as $aType) { | |
cba9346d | 169 | $this->assertText("add_activity_type_id", $aType); |
6a488035 TO |
170 | } |
171 | $this->assertElementPresent("link=Assign to Another Client", "Assign to Another Client link is missing."); | |
cba9346d | 172 | $this->assertElementPresent("xpath=//a[text()=' Print Report']", "Print Case Summary button is missing."); |
6a488035 TO |
173 | } |
174 | ||
4cbe18b8 EM |
175 | /** |
176 | * @param $caseRoles | |
177 | * @param $creatorName | |
178 | */ | |
6a488035 | 179 | function _testVerifyCaseRoles($caseRoles, $creatorName) { |
f6262e1a RK |
180 | $id = $this->urlArg('id'); |
181 | $this->waitForElementPresent("xpath=//table[@id='caseRoles-selector-$id']/tbody/tr[4]/td[2]/a"); | |
6a488035 TO |
182 | // check that expected roles are listed in the Case Roles pane |
183 | foreach ($caseRoles as $role) { | |
184 | $this->assertText("css=div.crm-case-roles-block", $role); | |
185 | } | |
186 | // check that case creator role has been assigned to logged in user | |
f6262e1a | 187 | $this->verifyText("xpath=//table[@id='caseRoles-selector-$id']/tbody/tr[4]/td[2]", $creatorName); |
6a488035 TO |
188 | } |
189 | ||
4cbe18b8 EM |
190 | /** |
191 | * @param $activityTypes | |
192 | */ | |
6a488035 | 193 | function _testVerifyCaseActivities($activityTypes) { |
cba9346d | 194 | $id = $this->urlArg('id'); |
6a488035 TO |
195 | // check that expected auto-created activities are listed in the Case Activities table |
196 | foreach ($activityTypes as $aType) { | |
cba9346d | 197 | $this->assertText("case_id_$id", $aType); |
6a488035 TO |
198 | } |
199 | } | |
200 | ||
4cbe18b8 EM |
201 | /** |
202 | * @param $subject | |
203 | * @param $openCaseData | |
204 | */ | |
6a488035 | 205 | function _testVerifyOpenCaseActivity($subject, $openCaseData) { |
cba9346d | 206 | $id = $this->urlArg('id'); |
6a488035 | 207 | // check that open case subject is present |
cba9346d | 208 | $this->assertText("case_id_$id", $subject); |
6a488035 TO |
209 | // click open case activity pop-up dialog |
210 | $this->click("link=$subject"); | |
cba9346d | 211 | $this->waitForElementPresent("ActivityView"); |
6a488035 TO |
212 | $this->waitForElementPresent("css=tr.crm-case-activity-view-Activity"); |
213 | // set page location of table containing activity view data | |
cba9346d | 214 | $activityViewPrefix = "//*[@id='ActivityView']"; |
6a488035 TO |
215 | $activityViewTableId = "crm-activity-view-table"; |
216 | // Probably don't need both tableId and prefix - but good examples for other situations where only one can be used | |
217 | ||
218 | $this->webtestVerifyTabularData($openCaseData, '', $activityViewTableId); | |
cba9346d | 219 | $this->click("xpath=//span[@class='ui-button-icon-primary ui-icon ui-icon-closethick']"); |
6a488035 TO |
220 | } |
221 | ||
4cbe18b8 EM |
222 | /** |
223 | * @param $firstName | |
224 | * @param $lastName | |
225 | * @param $action | |
226 | */ | |
6a488035 TO |
227 | function _testSearchbyDate($firstName, $lastName, $action) { |
228 | // Find Cases | |
229 | if ($action != "0") { | |
d2771e94 | 230 | $this->openCiviPage('case/search', 'reset=1'); |
6a488035 TO |
231 | $this->select("case_from_relative", "value=$action"); |
232 | $this->select("case_to_relative", "value=$action"); | |
233 | $this->click("_qf_Search_refresh"); | |
234 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
d2771e94 | 235 | $this->assertElementContainsText('Search', "$lastName, $firstName"); |
6a488035 TO |
236 | } |
237 | else { | |
238 | //select date range | |
d2771e94 | 239 | $this->openCiviPage('case/search', 'reset=1', '_qf_Search_refresh-bottom'); |
6a488035 TO |
240 | $this->select("case_from_relative", "value=$action"); |
241 | $this->webtestFillDate("case_from_start_date_low", "-1 month"); | |
242 | $this->webtestFillDate("case_from_start_date_high", "+1 month"); | |
243 | $this->select("case_to_relative", "value=$action"); | |
244 | $this->webtestFillDate("case_to_end_date_low", "-1 month"); | |
245 | $this->webtestFillDate("case_to_end_date_high", "+1 month"); | |
246 | $this->click("_qf_Search_refresh-bottom"); | |
247 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
d2771e94 | 248 | $this->assertElementContainsText('Search', "$lastName, $firstName"); |
6a488035 | 249 | } |
76e86fd8 | 250 | |
6a488035 | 251 | //Advanced Search |
d2771e94 | 252 | $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh'); |
6a488035 TO |
253 | $this->click("CiviCase"); |
254 | $this->waitForElementPresent("xpath=//div[@id='case-search']/table/tbody/tr[3]/td[2]/input[3]"); | |
255 | if ($action != "0") { | |
256 | $this->select("case_from_relative", "value=$action"); | |
257 | $this->select("case_to_relative", "value=$action"); | |
258 | } | |
259 | else { | |
260 | $this->select("case_from_relative", "value=$action"); | |
261 | $this->webtestFillDate("case_from_start_date_low", "-1 month"); | |
262 | $this->webtestFillDate("case_from_start_date_high", "+1 month"); | |
263 | $this->select("case_to_relative", "value=$action"); | |
264 | $this->webtestFillDate("case_to_end_date_low", "-1 month"); | |
265 | $this->webtestFillDate("case_to_end_date_high", "+1 month"); | |
266 | } | |
267 | $this->click("_qf_Advanced_refresh"); | |
268 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
d2771e94 | 269 | $this->assertElementContainsText('Advanced', "$lastName, $firstName"); |
6a488035 | 270 | } |
f6262e1a RK |
271 | |
272 | /** | |
273 | * @param $firstName | |
274 | * @param $lastName | |
275 | * @param $caseTypeLabel | |
276 | * | |
277 | * test for assign case to another client | |
278 | */ | |
279 | function _testAssignToClient($firstName, $lastName, $caseTypeLabel) { | |
280 | $this->openCiviPage('case/search', 'reset=1', '_qf_Search_refresh-bottom'); | |
281 | $this->type('sort_name', $firstName); | |
282 | $this->click('_qf_Search_refresh-bottom'); | |
283 | $this->waitForElementPresent("xpath=//table[@class='caseSelector']/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']"); | |
284 | ||
285 | $this->click("xpath=//table[@class='caseSelector']/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']/../../td[11]/span[2]/ul/li/a[contains(text(),'Assign to Another Client')]"); | |
286 | $clientFirstName = substr(sha1(rand()), 0, 7); | |
287 | $clientLastName = "Fraser"; | |
288 | $clientEmail = "{$clientLastName}.{$clientFirstName}@example.org"; | |
289 | $this->waitForElementPresent('_qf_EditClient_done-bottom'); | |
290 | $this->webtestNewDialogContact($clientFirstName, $clientLastName, $clientEmail, $type = 4, "s2id_reassign_contact_id"); | |
291 | $this->clickLink('_qf_EditClient_done-bottom'); | |
292 | $this->assertElementContainsText('page-title', "$clientFirstName $clientLastName - $caseTypeLabel"); | |
293 | } | |
6a488035 TO |
294 | } |
295 |