Webtest fix
[civicrm-core.git] / tests / phpunit / WebTest / Case / CaseDashboardTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Case_CaseDashboardTest
31 */
32 class WebTest_Case_CaseDashboardTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testAllOrMyCases() {
39 // Log in as admin first to verify permissions for CiviCase
40 $this->webtestLogin('true');
41
42 // Enable CiviCase module if necessary
43 $this->enableComponents("CiviCase");
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
49 // Log in as normal user
50 $this->webtestLogin();
51
52 $this->openCiviPage('case', 'reset=1');
53
54 // Should default to My Cases
55 $this->assertTrue($this->isChecked("name=allupcoming value=0"), 'Case dashboard should default to My Cases.');
56 // The header text of the table changes too
57 $this->assertElementContainsText('crm-container', "Summary of Involvement");
58
59 $this->clickLink("name=allupcoming value=1", "css=a.button");
60
61 $this->assertTrue($this->isChecked("name=allupcoming value=1"), 'Selection of All Cases failed.');
62 $this->assertElementContainsText('crm-container', "Summary of All Cases");
63
64 // Go back to dashboard
65 $this->openCiviPage('case', 'reset=1', 'css=a.button');
66
67 // Click on find my cases and check if right radio is checked
68 $this->clickLink("name=find_my_cases", "css=input.crm-form-submit");
69 $this->assertTrue($this->isChecked("name=case_owner value=2"), 'Find my cases button not properly setting search form value to my cases.');
70
71 //Add case to get drilldown cell on Case dashboard
72 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
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
76 $firstName = substr(sha1(rand()), 0, 7);
77 $lastName = "Fraser";
78 $contactName = "{$lastName}, {$firstName}";
79 $displayName = "{$firstName} {$lastName}";
80 $email = "{$lastName}.{$firstName}@example.org";
81 $this->webtestNewDialogContact($firstName, $lastName, $email, $type = 4, "s2id_client_id");
82
83 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
84 $caseTypeLabel = "Adult Day Care Referral";
85 // activity types we expect for this case type
86 $activityTypes = array("ADC referral", "Follow up", "Medical evaluation", "Mental health evaluation");
87 $caseRoles = array("Senior Services Coordinator", "Health Services Coordinator", "Benefits Specialist", "Client");
88 $caseStatusLabel = "Ongoing";
89 $subject = "Safe daytime setting - senior female";
90 $this->select("medium_id", "value=1");
91 $location = "Main offices";
92 $this->type("activity_location", $location);
93 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
94 $this->fireEvent('activity_details', 'focus');
95 $this->fillRichTextField("activity_details", $details, 'CKEditor');
96 $this->type("activity_subject", $subject);
97
98 $this->select("case_type_id", "label={$caseTypeLabel}");
99 $this->select("status_id", "label={$caseStatusLabel}");
100
101 // Choose Case Start Date.
102 // Using helper webtestFillDate function.
103 $this->webtestFillDate('start_date', 'now');
104 $today = date('F jS, Y', strtotime('now'));
105
106 $this->type("duration", "20");
107 $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom");
108
109 // Is status message correct?
110 $this->waitForText('crm-notification-container', "Case opened successfully.");
111
112 // Go back to dashboard
113 $this->openCivipage('case', 'reset=1', 'css=a.button');
114
115 // Click on a drilldown cell and check if right radio is checked
116 $this->clickLink("css=a.crm-case-summary-drilldown", "css=input.crm-form-submit");
117 $this->assertTrue($this->isChecked("name=case_owner value=1"), 'Drilldown on dashboard summary cells not properly setting search form value to all cases.');
118
119 // Go back to dashboard and reset to my cases
120 $this->openCiviPage('case', 'reset=1', 'css=a.button');
121 $this->clickLink("name=allupcoming value=0", "css=a.button");
122
123 // Click on a drilldown cell and check if right radio is checked
124 $this->clickLink("css=a.crm-case-summary-drilldown", "css=input.crm-form-submit");
125 $this->assertTrue($this->isChecked("name=case_owner value=2"), 'Drilldown on dashboard summary cells not properly setting search form value to my cases.');
126 }
127 }
128