Merge pull request #5488 from eileenmcnaughton/CRM-16184
[civicrm-core.git] / tests / phpunit / WebTest / Case / AddCaseTypeTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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_AddCaseTest
31 */
32 class WebTest_Case_AddCaseTypeTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testAddEditCaseType() {
39 $caseRoles = array(1 => 'Parent of', 2 => 'Spouse of', 3 => 'Partner of');
40 $activityTypes = array(1 => 'Meeting', 2 => 'Contribution', 3 => 'Event Registration');
41 $timelineActivityTypes = array(1 => 'Meeting', 2 => 'Phone Call', 3 => 'Email');
42 // Log in as admin first to verify permissions for CiviCase
43 $this->webtestLogin('admin');
44
45 // Enable CiviCase module if necessary
46 $this->enableComponents("CiviCase");
47
48 // let's give full CiviCase permissions to demo user (registered user).
49 $permission = array(
50 'edit-2-access-all-cases-and-activities',
51 'edit-2-access-my-cases-and-activities',
52 'edit-2-administer-civicase',
53 'edit-2-delete-in-civicase',
54 );
55 $this->changePermissions($permission);
56
57 // Log in as normal user
58 $this->webtestLogin();
59
60 $this->openCiviPage('a/#/caseType/new');
61
62 $caseTypeLabel = "Case Type" . substr(sha1(rand()), 0, 7);
63 $this->waitForElementPresent('title');
64 $this->type('title', $caseTypeLabel);
65
66 foreach ($caseRoles as $cRoles) {
67 $this->select2("xpath=//tr[@class='addRow']/td/span/div/a", $cRoles, FALSE, TRUE);
68 }
69
70 foreach ($activityTypes as $aType) {
71 $this->select2("xpath=//tr[@class='addRow']/td[contains(text(),'Add activity type:')]/span/div/a", $aType, FALSE, TRUE);
72 }
73
74 $this->click("xpath=//a[text()='Standard Timeline']");
75 foreach ($timelineActivityTypes as $tActivityType) {
76 $this->select2("xpath=//tr[@class='addRow']/td[contains(text(),'Add activity:')]/span/div/a", $tActivityType, FALSE, TRUE);
77 }
78
79 $this->clickAjaxLink("xpath=//div[@class='crm-submit-buttons']/span/input[@value='Save']");
80
81 $this->openCiviPage('case/add', 'reset=1&action=add&atype=13&context=standalone', '_qf_Case_upload-bottom');
82 $client = $this->createDialogContact("client_id");
83
84 $caseStatusLabel = "Ongoing";
85 $subject = "Safe daytime setting - senior female";
86 $this->select("medium_id", "value=1");
87 $location = "Main offices";
88 $this->type("activity_location", $location);
89 $details = "65 year old female needs safe location during the day for herself and her dog. She is in good health but somewhat disoriented.";
90 $this->fireEvent('activity_details', 'focus');
91 $this->fillRichTextField("activity_details", $details, 'CKEditor');
92 $this->type("activity_subject", $subject);
93 $this->waitForElementPresent('case_type_id');
94 $this->select("case_type_id", "label={$caseTypeLabel}");
95 $this->waitForElementPresent('status_id');
96 $this->select("status_id", "label={$caseStatusLabel}");
97
98 $this->webtestFillDate('start_date', 'now');
99 $today = date('F jS, Y', strtotime('now'));
100
101 $this->type("duration", "20");
102 $this->clickLink("_qf_Case_upload-bottom", "_qf_CaseView_cancel-bottom");
103
104 // Is status message correct?
105 $this->waitForText('crm-notification-container', "Case opened successfully.");
106
107 foreach ($activityTypes as $aType) {
108 $this->assertElementPresent("xpath=//div[@class='case-control-panel']/div/p/select", $aType);
109 }
110
111 $this->click("xpath=//div[contains(text(), 'Roles')]");
112
113 // check that expected roles are listed in the Case Roles pane
114 foreach ($caseRoles as $key => $role) {
115 $this->assertText("css=div.crm-case-roles-block", $role);
116 }
117
118 $id = $this->urlArg('id');
119 // check that expected activities are listed in the Case Activities table
120 foreach ($timelineActivityTypes as $tActivityType) {
121 $this->assertText("case_id_$id", $tActivityType);
122 }
123
124 // for edit case type
125 $this->openCiviPage('a/#/caseType');
126 $this->waitForElementPresent("xpath=//*[@id='crm-main-content-wrapper']/div/div/div[2]/a/span[contains(text(),'New Case Type')]");
127
128 $this->click("xpath=//table/tbody//tr/td[1][text()='{$caseTypeLabel}']/../td[5]/span/a[text()='Edit']");
129 $this->waitForElementPresent("xpath=//div[@class='crm-submit-buttons']/span/input[@value='Save']");
130
131 $editCaseTypeLabel = "Case Type Edit" . substr(sha1(rand()), 0, 7);
132 $this->waitForElementPresent('title');
133 $this->type('title', $editCaseTypeLabel);
134
135 $this->select2("xpath=//div[@id='crm-main-content-wrapper']/div/div/form/div/div[4]/table/tfoot/tr/td/span/div/a", 'Sibling of', FALSE, TRUE);
136 $this->click("xpath=//*[@id='crm-main-content-wrapper']/div/div/form/div/div[4]/table/tbody/tr[4]/td[2]/input[@type='checkbox']");
137
138 $this->click("xpath=//a[text()='Standard Timeline']");
139 $this->select2("xpath=//tr[@class='addRow']/td[contains(text(),'Add activity:')]/span/div/a", 'SMS', FALSE, TRUE);
140
141 $this->click("xpath=//div[@class='crm-submit-buttons']/span/input[@value='Save']");
142 $this->waitForElementPresent("xpath=//*[@id='crm-main-content-wrapper']/div/div/div[2]/a/span[contains(text(),'New Case Type')]");
143
144 $this->verifyText("xpath=//table/tbody//tr/td[contains(text(),'$editCaseTypeLabel')]", $editCaseTypeLabel);
145 }
146
147 }