379664e09f8625c12665a4e090684cfdf038c4ef
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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_AddCaseTest
32 class WebTest_Case_AddCaseTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testStandaloneCaseAdd() {
39 // Log in as admin first to verify permissions for CiviCase
40 $this->webtestLogin('admin');
42 // Enable CiviCase module if necessary
43 $this->enableComponents("CiviCase");
45 // let's give full CiviCase permissions to demo user (registered user).
47 'edit-2-access-all-cases-and-activities',
48 'edit-2-access-my-cases-and-activities',
49 'edit-2-administer-civicase',
50 'edit-2-delete-in-civicase',
52 $this->changePermissions($permission);
54 // Log in as normal user
55 $this->webtestLogin();
57 // Go to reserved New Individual Profile to set value for logged in user's contact name (we'll need that later)
58 $this->openCiviPage('profile/edit', 'reset=1&gid=4', NULL);
59 $testUserFirstName = "Testuserfirst";
60 $testUserLastName = "Testuserlast";
61 $this->waitForElementPresent("_qf_Edit_next");
62 $this->type("first_name", $testUserFirstName);
63 $this->type("last_name", $testUserLastName);
64 $this->clickLink("_qf_Edit_next", "profilewrap4");
65 // Is status message correct?
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!");
68 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
70 // Try submitting the form without creating or selecting a contact (test for CRM-7971)
71 $this->clickLink("_qf_Case_upload-bottom", "css=span.crm-error");
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.");
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
76 $client = $this->createDialogContact("client_id");
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
81 $activityTypes = array("ADC referral", "Follow up", "Medical evaluation", "Mental health evaluation");
82 $caseRoles = array("Senior Services Coordinator", "Health Services Coordinator", "Benefits Specialist", "Client");
83 $caseStatusLabel = "Ongoing";
84 $subject = "Safe daytime setting - senior female";
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);
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'));
100 $this->type("duration", "20");
101 $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom");
103 // Is status message correct?
104 $this->waitForText('crm-notification-container', "Case opened successfully.");
106 $summaryStrings = array(
108 $client['display_name'],
109 "Type: {$caseTypeLabel}",
110 "Open Date: {$today}",
111 "Status: {$caseStatusLabel}",
114 $this->_testVerifyCaseSummary($summaryStrings, $activityTypes);
115 $this->_testVerifyCaseRoles($caseRoles, "{$testUserLastName}, {$testUserFirstName}");
116 $this->_testVerifyCaseActivities($activityTypes);
118 $openCaseData = array(
119 "Client" => $client['display_name'],
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",
132 $this->_testVerifyOpenCaseActivity($subject, $openCaseData);
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");
137 $this->select("case_status_id", "value=2");
138 $this->click("_qf_Activity_upload-top");
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);
146 public function testAjaxCustomGroupLoad() {
147 // Log in as admin first to verify permissions for CiviCase
148 $this->webtestLogin('admin');
150 // Enable CiviCase module if necessary
151 $this->enableComponents("CiviCase");
153 // let's give full CiviCase permissions to demo user (registered user).
155 'edit-2-access-all-cases-and-activities',
156 'edit-2-access-my-cases-and-activities',
157 'edit-2-administer-civicase',
158 'edit-2-delete-in-civicase',
160 $this->changePermissions($permission);
162 // Log in as normal user
163 $this->webtestLogin();
165 $triggerElement = array('name' => 'case_type_id', 'type' => 'select');
167 array('entity' => 'Case', 'subEntity' => 'Housing Support', 'triggerElement' => $triggerElement),
170 $pageUrl = array('url' => 'case/add', 'args' => "reset=1&action=add&atype=13&context=standalone");
171 $this->customFieldSetLoadOnTheFlyCheck($customSets, $pageUrl);
175 * @param $validateStrings
176 * @param $activityTypes
178 public function _testVerifyCaseSummary($validateStrings, $activityTypes) {
179 $this->assertStringsPresent($validateStrings);
180 foreach ($activityTypes as $aType) {
181 $this->assertElementPresent("xpath=//div[@class='case-control-panel']/div/p/select", $aType);
183 $this->assertElementPresent("link=Assign to Another Client", "Assign to Another Client link is missing.");
184 $this->assertElementPresent("xpath=//a[text()=' Print Report']", "Print Case Summary button is missing.");
189 * @param string $creatorName
191 public function _testVerifyCaseRoles($caseRoles, $creatorName) {
192 $id = $this->urlArg('id');
193 $this->click('css=div.crm-case-roles-block div.crm-accordion-header');
195 $this->waitForElementPresent("xpath=//table[@id='caseRoles-selector-$id']/tbody/tr[4]/td[2]/a");
196 // check that expected roles are listed in the Case Roles pane
197 foreach ($caseRoles as $role) {
198 $this->assertElementContainsText("xpath=//table[@id='caseRoles-selector-$id']/tbody/tr[4]/td[1]", $role);
200 // check that case creator role has been assigned to logged in user
201 $this->assertElementContainsText("xpath=//table[@id='caseRoles-selector-$id']/tbody/tr[4]/td[2]", $creatorName);
205 * @param $activityTypes
207 public function _testVerifyCaseActivities($activityTypes) {
208 $id = $this->urlArg('id');
209 // check that expected auto-created activities are listed in the Case Activities table
210 foreach ($activityTypes as $aType) {
211 $this->assertText("case_id_$id", $aType);
217 * @param $openCaseData
219 public function _testVerifyOpenCaseActivity($subject, $openCaseData) {
220 $id = $this->urlArg('id');
221 // check that open case subject is present
222 $this->assertText("case_id_$id", $subject);
223 // click open case activity pop-up dialog
224 $this->click("xpath=//table[@id='case_id_{$id}']/tbody//tr/td[2]/div[text()='{$subject}']/../../td[8]/a[text()='View']");
225 $this->waitForElementPresent("ActivityView");
226 $this->waitForElementPresent("css=tr.crm-case-activity-view-Activity");
227 // set page location of table containing activity view data
228 $activityViewPrefix = "//*[@id='ActivityView']";
229 $activityViewTableId = "crm-activity-view-table";
230 // Probably don't need both tableId and prefix - but good examples for other situations where only one can be used
232 $this->webtestVerifyTabularData($openCaseData, '', $activityViewTableId);
233 $this->click("xpath=//span[@class='ui-button-icon-primary ui-icon fa-times']");
237 * @param string $firstName
238 * @param string $lastName
241 public function _testSearchbyDate($firstName, $lastName, $action) {
243 if ($action != "0") {
244 $this->openCiviPage('case/search', 'reset=1');
245 $this->select("case_from_relative", "value=$action");
246 $this->select("case_to_relative", "value=$action");
247 $this->click("_qf_Search_refresh");
248 $this->waitForPageToLoad($this->getTimeoutMsec());
249 $this->assertElementContainsText('Search', "$lastName, $firstName");
253 $this->openCiviPage('case/search', 'reset=1', '_qf_Search_refresh-bottom');
254 $this->select("case_from_relative", "value=$action");
255 $this->webtestFillDate("case_from_start_date_low", "-1 month");
256 $this->webtestFillDate("case_from_start_date_high", "+1 month");
257 $this->select("case_to_relative", "value=$action");
258 $this->webtestFillDate("case_to_end_date_low", "-1 month");
259 $this->webtestFillDate("case_to_end_date_high", "+1 month");
260 $this->click("_qf_Search_refresh-bottom");
261 $this->waitForPageToLoad($this->getTimeoutMsec());
262 $this->assertElementContainsText('Search', "$lastName, $firstName");
266 $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh');
267 $this->click("CiviCase");
268 $this->waitForElementPresent("xpath=//div[@id='case-search']/table/tbody/tr[3]/td[2]/input[3]");
269 if ($action != "0") {
270 $this->select("case_from_relative", "value=$action");
271 $this->select("case_to_relative", "value=$action");
274 $this->select("case_from_relative", "value=$action");
275 $this->webtestFillDate("case_from_start_date_low", "-1 month");
276 $this->webtestFillDate("case_from_start_date_high", "+1 month");
277 $this->select("case_to_relative", "value=$action");
278 $this->webtestFillDate("case_to_end_date_low", "-1 month");
279 $this->webtestFillDate("case_to_end_date_high", "+1 month");
281 $this->clickLink("_qf_Advanced_refresh");
282 $this->assertElementContainsText('Advanced', "$lastName, $firstName");
286 * @param string $firstName
287 * @param string $lastName
288 * @param $caseTypeLabel
290 * test for assign case to another client
292 public function _testAssignToClient($firstName, $lastName, $caseTypeLabel) {
293 $this->openCiviPage('case/search', 'reset=1', '_qf_Search_refresh-bottom');
294 $this->type('sort_name', $firstName);
295 $this->clickLink('_qf_Search_refresh-bottom');
296 $this->waitForElementPresent("xpath=//table[@class='caseSelector']/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']");
298 $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')]");
299 $client = $this->createDialogContact("reassign_contact_id");
300 $this->clickLink('_qf_EditClient_done-bottom');
301 $this->assertElementContainsText('page-title', "{$client['display_name']} - $caseTypeLabel");