3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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';
28 class WebTest_Report_RolePermissionReportTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testRolePermissionReport() {
35 $this->webtestLogin('admin');
38 $role1 = 'role1' . substr(sha1(rand()), 0, 7);
39 $role2 = 'role2' . substr(sha1(rand()), 0, 7);
40 $this->open($this->sboxPath
. "admin/people/permissions/roles");
41 $this->waitForElementPresent("edit-add");
42 $this->type("edit-name", $role1);
43 $this->click("edit-add");
44 $this->waitForPageToLoad($this->getTimeoutMsec());
46 $this->open($this->sboxPath
. "admin/people/permissions/roles");
47 $this->waitForElementPresent("edit-add");
48 $this->type("edit-name", $role2);
49 $this->click("edit-add");
50 $this->waitForPageToLoad($this->getTimeoutMsec());
52 $this->open($this->sboxPath
. "admin/people/permissions/roles");
54 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role1}']");
55 $roleid = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role1}']/../td[4]/a[text()='edit permissions']/@href"));
56 $roleId1 = end($roleid);
57 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role2}']");
58 $roleid = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role2}']/../td[4]/a[text()='edit permissions']/@href"));
59 $roleId2 = end($roleid);
61 $user1 = $this->_testCreateUser($roleId1);
62 $user2 = $this->_testCreateUser($roleId2);
64 // let's give full CiviReport permissions.
66 "edit-2-access-civireport",
67 "edit-2-view-all-contacts",
68 "edit-2-administer-civicrm",
69 "edit-2-access-civicrm",
71 $this->changePermissions($permissions);
73 // change report setting to for a particular role
74 $this->openCiviPage('report/instance/1', 'reset=1');
75 $this->click("css=div.crm-report_setting-accordion div.crm-accordion-header");
76 $this->waitForElementPresent("_qf_Summary_submit_save");
77 $this->select("permission", "value=access CiviCRM");
78 $this->select("grouprole-f", "value=$role1");
80 $this->click("_qf_Summary_submit_save");
81 $this->waitForPageToLoad($this->getTimeoutMsec());
82 $this->webtestLogin($user2, 'Test12345');
83 $this->openCiviPage('report/instance/1', 'reset=1');
84 $this->assertElementContainsText('crm-container', 'You do not have permission to access this report.');
85 $this->openCiviPage('report/list', 'reset=1');
88 $this->webtestLogin('admin');
89 $this->open($this->sboxPath
. "admin/people/permissions/roles");
90 $this->_roleDelete($role1);
91 $this->_roleDelete($role2);
97 function testReservedReportPermission() {
98 $this->webtestLogin('admin');
101 $role = 'role' . substr(sha1(rand()), 0, 7);
102 $this->open($this->sboxPath
. "admin/people/permissions/roles");
104 $this->waitForElementPresent("edit-add");
105 $this->type("edit-name", $role);
106 $this->click("edit-add");
107 $this->waitForPageToLoad($this->getTimeoutMsec());
109 $this->open($this->sboxPath
. "admin/people/permissions/roles");
110 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']");
111 $roleId = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']/../td[4]/a[text()='edit permissions']/@href"));
112 $roleId = end($roleId);
113 $user = $this->_testCreateUser($roleId);
114 $this->openCiviPage('report/instance/1', 'reset=1');
115 if ($this->isChecked("is_reserved")) {
116 $this->click("is_reserved");
117 $this->click("_qf_Summary_submit_save");
118 $this->waitForPageToLoad($this->getTimeoutMsec());
120 $permissions = array(
121 "edit-{$roleId}-access-civireport",
122 "edit-{$roleId}-view-all-contacts",
123 "edit-{$roleId}-administer-reports",
124 "edit-{$roleId}-access-civicrm"
126 $this->changePermissions($permissions);
128 $this->webtestLogin($user, 'Test12345');
129 $this->openCiviPage('report/instance/1', 'reset=1');
131 //check if the reserved report field is frozen
132 $this->assertTrue($this->isElementPresent("xpath=//div[@id='instanceForm']//table[3]/tbody//tr/td[2]/tt[text()='[ ]']"));
134 // let's give full CiviReport permissions.
135 $permissions = array(
136 "edit-{$roleId}-access-civireport",
137 "edit-{$roleId}-view-all-contacts",
138 "edit-{$roleId}-administer-reports",
139 "edit-{$roleId}-access-civicrm",
140 "edit-{$roleId}-administer-reserved-reports"
142 $this->changePermissions($permissions);
144 $this->openCiviPage('report/instance/1', 'reset=1');
146 //make the report reserved
147 $this->click("is_reserved");
148 $this->click("_qf_Summary_submit_save");
149 $this->waitForPageToLoad($this->getTimeoutMsec());
151 $this->webtestLogin($user, 'Test12345');
152 $this->openCiviPage('report/instance/1', 'reset=1');
154 //check if the report criteria and settings is accessible
155 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Summary']//div[@id='id_default']//input[@id='fields_email']"));
156 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Summary']//div[@id='instanceForm']/table//input[@id='title']"));
158 //login as admin and remove reserved permission
159 $this->webtestLogin('admin');
160 $this->open($this->sboxPath
. "admin/people/permissions");
161 $this->waitForElementPresent("edit-submit");
163 if ($this->isChecked("edit-2-administer-reserved-reports")) {
164 $this->click("edit-2-administer-reserved-reports");
166 $this->click("edit-{$roleId}-administer-reserved-reports");
168 $this->click("edit-submit");
169 $this->waitForPageToLoad($this->getTimeoutMsec());
171 //login as user and check for absence of report criteria and settings
172 $this->webtestLogin($user, 'Test12345');
173 $this->openCiviPage('report/instance/1', 'reset=1');
175 if ($this->isElementPresent("xpath=//form[@id='Summary']/div[2]/div/div/div")) {
176 $this->verifyNotText("xpath=//form[@id='Summary']/div[2]/div/div/div", "Report Criteria");
178 if ($this->isElementPresent("xpath=//form[@id='Summary']/div[2]/div[2]/div")) {
179 $this->verifyNotText("xpath=//form[@id='Summary']/div[2]/div[2]/div", "Report Settings");
182 $this->assertFalse($this->isElementPresent("xpath=//form[@id='Summary']//div[@id='instanceForm']//input[@id='title']"));
184 //login as admin and turn the is_reserved flag off for the instance
185 $this->webtestLogin('admin');
186 $this->openCiviPage('report/instance/1', 'reset=1');
187 $this->click("is_reserved");
188 $this->click("_qf_Summary_submit_save");
189 $this->waitForPageToLoad($this->getTimeoutMsec());
191 $this->webtestLogin($user, 'Test12345');
192 $this->openCiviPage('report/instance/1', 'reset=1');
194 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Summary']//div[@id='id_default']//input[@id='fields_email']"));
195 $this->assertTrue($this->isElementPresent("xpath=//form[@id='Summary']//div[@id='instanceForm']//input[@id='title']"));
197 //login as admin and delete the role
198 $this->webtestLogin('admin');
199 $this->open($this->sboxPath
. "admin/people/permissions/roles");
200 $this->_roleDelete($role);
203 function _roleDelete($role) {
204 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']");
205 $this->click("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']");
206 $this->waitForElementPresent('edit-delete');
207 $this->click('edit-delete');
208 $this->waitForPageToLoad($this->getTimeoutMsec());
209 $this->click("edit-submit");
210 $this->waitForTextPresent("The role has been deleted.");
213 function _testCreateUser($roleid) {
215 $this->open($this->sboxPath
. "admin/people/create");
217 $this->waitForElementPresent("edit-submit");
219 $name = "TestUser" . substr(sha1(rand()), 0, 4);
220 $this->type("edit-name", $name);
222 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
223 $this->type("edit-mail", $emailId);
224 $this->type("edit-pass-pass1", "Test12345");
225 $this->type("edit-pass-pass2", "Test12345");
226 $role = "edit-roles-" . $roleid;
227 $this->check("name=roles[$roleid] value={$roleid}");
229 //Add profile Details
230 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
231 $lastName = 'An' . substr(sha1(rand()), 0, 7);
233 $this->type("first_name", $firstName);
234 $this->type("last_name", $lastName);
237 $this->type("street_address-1", "902C El Camino Way SW");
238 $this->type("city-1", "Dumfries");
239 $this->type("postal_code-1", "1234");
240 $this->select("state_province-1", "value=1019");
242 $this->click("edit-submit");
243 $this->waitForPageToLoad($this->getTimeoutMsec());