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