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