Merge pull request #11742 from seanmadsen/NFC-CRM_PCP_Form_Event
[civicrm-core.git] / tests / phpunit / WebTest / Case / CaseDashboardTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 public function testAllOrMyCases() {
39 // Log in as admin first to verify permissions for CiviCase
40 $this->webtestLogin('admin');
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(
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',
51 );
52 $this->changePermissions($permission);
53
54 // Log in as normal user
55 $this->webtestLogin();
56
57 $this->openCiviPage('case', 'reset=1');
58
59 // Should default to My Cases
60 $this->assertTrue($this->isChecked("name=allupcoming value=0"), 'Case dashboard should default to My Cases.');
61 // The header text of the table changes too
62 $this->assertElementContainsText('crm-container', "Summary of Involvement");
63
64 $this->clickLink("name=allupcoming value=1", "css=a.button");
65
66 $this->assertTrue($this->isChecked("name=allupcoming value=1"), 'Selection of All Cases failed.');
67 $this->assertElementContainsText('crm-container', "Summary of All Cases");
68
69 // Go back to dashboard
70 $this->openCiviPage('case', 'reset=1', 'css=a.button');
71
72 // Click on find my cases and check if right radio is checked
73 $this->clickLink("name=find_my_cases", "css=input.crm-form-submit");
74 $this->assertTrue($this->isChecked("name=case_owner value=2"), 'Find my cases button not properly setting search form value to my cases.');
75
76 //Add case to get drilldown cell on Case dashboard
77 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
78
79 // We're using pop-up New Contact dialog
80 $params = $this->createDialogContact('client_id');
81
82 // Fill in other form values. We'll use a case type which is included in CiviCase sample data / xml files.
83 $caseTypeLabel = "Adult Day Care Referral";
84 // activity types we expect for this case type
85 $activityTypes = array("ADC referral", "Follow up", "Medical evaluation", "Mental health evaluation");
86 $caseRoles = array("Senior Services Coordinator", "Health Services Coordinator", "Benefits Specialist", "Client");
87 $caseStatusLabel = "Ongoing";
88 $subject = "Safe daytime setting - senior female";
89 $this->select("medium_id", "value=1");
90 $location = "Main offices";
91 $this->type("activity_location", $location);
92 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
93 $this->fireEvent('activity_details', 'focus');
94 $this->fillRichTextField("activity_details", $details, 'CKEditor');
95 $this->type("activity_subject", $subject);
96
97 $this->select("case_type_id", "label={$caseTypeLabel}");
98 $this->select("status_id", "label={$caseStatusLabel}");
99
100 // Choose Case Start Date.
101 // Using helper webtestFillDate function.
102 $this->webtestFillDate('start_date', 'now');
103 $today = date('F jS, Y', strtotime('now'));
104
105 $this->type("duration", "20");
106 $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom");
107
108 // Is status message correct?
109 $this->waitForText('crm-notification-container', "Case opened successfully.");
110
111 // Go back to dashboard
112 $this->openCiviPage('case', 'reset=1');
113 //Check whether case status link opens in search correctly
114 $this->clickLink("xpath=//table[@class='report']/tbody/tr[3]/td/a");
115 $this->assertElementContainsText('Search', "{$params['last_name']}, {$params['first_name']}");
116
117 // Go back to dashboard
118 $this->openCiviPage('case', 'reset=1');
119
120 // Click on a drilldown cell and check if right radio is checked
121 $this->clickLink("css=a.crm-case-summary-drilldown", "css=input.crm-form-submit");
122 $this->assertTrue($this->isChecked("name=case_owner value=1"), 'Drilldown on dashboard summary cells not properly setting search form value to all cases.');
123
124 // Go back to dashboard and reset to my cases
125 $this->openCiviPage('case', 'reset=1', 'css=a.button');
126 $this->clickLink("name=allupcoming value=0", "css=a.button");
127
128 // Click on a drilldown cell and check if right radio is checked
129 $this->clickLink("css=a.crm-case-summary-drilldown", "css=input.crm-form-submit");
130 $this->assertTrue($this->isChecked("name=case_owner value=2"), 'Drilldown on dashboard summary cells not properly setting search form value to my cases.');
131 }
132
133 }