Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Report_RolePermissionReportTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Report_RolePermissionReportTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testRolePermissionReport() { |
42daf119 | 39 | $this->webtestLogin('admin'); |
6a488035 TO |
40 | |
41 | //create new roles | |
42 | $role1 = 'role1' . substr(sha1(rand()), 0, 7); | |
43 | $role2 = 'role2' . substr(sha1(rand()), 0, 7); | |
44 | $this->open($this->sboxPath . "admin/people/permissions/roles"); | |
45 | $this->waitForElementPresent("edit-add"); | |
46 | $this->type("edit-name", $role1); | |
47 | $this->click("edit-add"); | |
48 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
331a5c18 | 49 | |
6a488035 TO |
50 | $this->open($this->sboxPath . "admin/people/permissions/roles"); |
51 | $this->waitForElementPresent("edit-add"); | |
52 | $this->type("edit-name", $role2); | |
53 | $this->click("edit-add"); | |
54 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
55 | ||
56 | $this->open($this->sboxPath . "admin/people/permissions/roles"); | |
57 | ||
58 | $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role1}']"); | |
59 | $roleid = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role1}']/../td[4]/a[text()='edit permissions']/@href")); | |
60 | $roleId1 = end($roleid); | |
61 | $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role2}']"); | |
62 | $roleid = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role2}']/../td[4]/a[text()='edit permissions']/@href")); | |
63 | $roleId2 = end($roleid); | |
64 | ||
65 | $user1 = $this->_testCreateUser($roleId1); | |
66 | $user2 = $this->_testCreateUser($roleId2); | |
6a488035 TO |
67 | |
68 | // let's give full CiviReport permissions. | |
69 | $permissions = array( | |
70 | "edit-2-access-civireport", | |
71 | "edit-2-view-all-contacts", | |
72 | "edit-2-administer-civicrm", | |
73 | "edit-2-access-civicrm", | |
74 | ); | |
75 | $this->changePermissions($permissions); | |
76 | ||
77 | // change report setting to for a particular role | |
8fe1f83e | 78 | $this->openCiviPage('report/instance/1', 'reset=1'); |
b18eb8e1 | 79 | $this->click("xpath=//div[@id='mainTabContainer']/ul/li[6]/a"); |
6a488035 TO |
80 | $this->waitForElementPresent("_qf_Summary_submit_save"); |
81 | $this->select("permission", "value=access CiviCRM"); | |
82 | $this->select("grouprole-f", "value=$role1"); | |
83 | $this->click("add"); | |
84 | $this->click("_qf_Summary_submit_save"); | |
85 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
42daf119 | 86 | $this->webtestLogin($user2, 'Test12345'); |
8fe1f83e RN |
87 | $this->openCiviPage('report/instance/1', 'reset=1'); |
88 | $this->assertElementContainsText('crm-container', 'You do not have permission to access this report.'); | |
89 | $this->openCiviPage('report/list', 'reset=1'); | |
6a488035 TO |
90 | |
91 | //delete roles | |
42daf119 | 92 | $this->webtestLogin('admin'); |
6a488035 TO |
93 | $this->open($this->sboxPath . "admin/people/permissions/roles"); |
94 | $this->_roleDelete($role1); | |
95 | $this->_roleDelete($role2); | |
96 | } | |
331a5c18 | 97 | |
d424ffde | 98 | /** |
6a488035 TO |
99 | *check for CRM-10148 |
100 | */ | |
00be9182 | 101 | public function testReservedReportPermission() { |
42daf119 | 102 | $this->webtestLogin('admin'); |
6a488035 TO |
103 | |
104 | //create new role | |
105 | $role = 'role' . substr(sha1(rand()), 0, 7); | |
106 | $this->open($this->sboxPath . "admin/people/permissions/roles"); | |
107 | ||
108 | $this->waitForElementPresent("edit-add"); | |
109 | $this->type("edit-name", $role); | |
110 | $this->click("edit-add"); | |
111 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
331a5c18 | 112 | |
6a488035 TO |
113 | $this->open($this->sboxPath . "admin/people/permissions/roles"); |
114 | $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']"); | |
115 | $roleId = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']/../td[4]/a[text()='edit permissions']/@href")); | |
116 | $roleId = end($roleId); | |
117 | $user = $this->_testCreateUser($roleId); | |
8fe1f83e | 118 | $this->openCiviPage('report/instance/1', 'reset=1'); |
6a488035 TO |
119 | if ($this->isChecked("is_reserved")) { |
120 | $this->click("is_reserved"); | |
121 | $this->click("_qf_Summary_submit_save"); | |
122 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
123 | } | |
124 | $permissions = array( | |
125 | "edit-{$roleId}-access-civireport", | |
126 | "edit-{$roleId}-view-all-contacts", | |
127 | "edit-{$roleId}-administer-reports", | |
21dfd5f5 | 128 | "edit-{$roleId}-access-civicrm", |
331a5c18 | 129 | ); |
6a488035 | 130 | $this->changePermissions($permissions); |
331a5c18 | 131 | |
42daf119 | 132 | $this->webtestLogin($user, 'Test12345'); |
8fe1f83e | 133 | $this->openCiviPage('report/instance/1', 'reset=1'); |
6a488035 TO |
134 | |
135 | //check if the reserved report field is frozen | |
687bced0 | 136 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='report-tab-access']/table/tbody//tr/td[2]/span/tt[text()='[ ]']")); |
6a488035 | 137 | |
6a488035 TO |
138 | // let's give full CiviReport permissions. |
139 | $permissions = array( | |
140 | "edit-{$roleId}-access-civireport", | |
141 | "edit-{$roleId}-view-all-contacts", | |
142 | "edit-{$roleId}-administer-reports", | |
143 | "edit-{$roleId}-access-civicrm", | |
21dfd5f5 | 144 | "edit-{$roleId}-administer-reserved-reports", |
6a488035 TO |
145 | ); |
146 | $this->changePermissions($permissions); | |
331a5c18 | 147 | |
8fe1f83e | 148 | $this->openCiviPage('report/instance/1', 'reset=1'); |
6a488035 TO |
149 | |
150 | //make the report reserved | |
151 | $this->click("is_reserved"); | |
152 | $this->click("_qf_Summary_submit_save"); | |
153 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
331a5c18 | 154 | |
42daf119 | 155 | $this->webtestLogin($user, 'Test12345'); |
8fe1f83e | 156 | $this->openCiviPage('report/instance/1', 'reset=1'); |
6a488035 TO |
157 | |
158 | //check if the report criteria and settings is accessible | |
687bced0 | 159 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='report-tab-col-groups']/table/tbody//tr/td[3]/input[@id='fields_email']")); |
160 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='report-tab-format']/table/tbody//tr/td[2]/input[@id='title']")); | |
331a5c18 | 161 | |
6a488035 | 162 | //login as admin and remove reserved permission |
42daf119 | 163 | $this->webtestLogin('admin'); |
6a488035 TO |
164 | $this->open($this->sboxPath . "admin/people/permissions"); |
165 | $this->waitForElementPresent("edit-submit"); | |
331a5c18 | 166 | |
6a488035 TO |
167 | if ($this->isChecked("edit-2-administer-reserved-reports")) { |
168 | $this->click("edit-2-administer-reserved-reports"); | |
0db6c3e1 TO |
169 | } |
170 | else { | |
6a488035 TO |
171 | $this->click("edit-{$roleId}-administer-reserved-reports"); |
172 | } | |
173 | $this->click("edit-submit"); | |
174 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
175 | ||
176 | //login as user and check for absence of report criteria and settings | |
42daf119 | 177 | $this->webtestLogin($user, 'Test12345'); |
8fe1f83e | 178 | $this->openCiviPage('report/instance/1', 'reset=1'); |
331a5c18 | 179 | |
687bced0 | 180 | if ($this->isElementPresent("xpath=//div[@id='mainTabContainer']/ul/li")) { |
181 | $this->verifyNotText("xpath=//div[@id='mainTabContainer']/ul/li/a", "Columns"); | |
6a488035 | 182 | } |
687bced0 | 183 | if ($this->isElementPresent("xpath=//li[@id='tab_settings']")) { |
184 | $this->verifyNotText("xpath=//li[@id='tab_settings']/a", "Title and Format"); | |
6a488035 | 185 | } |
331a5c18 | 186 | |
687bced0 | 187 | $this->assertFalse($this->isElementPresent("xpath=//div[@id='report-tab-format']/table/tbody//tr/td[2]/input[@id='title']")); |
6a488035 TO |
188 | |
189 | //login as admin and turn the is_reserved flag off for the instance | |
42daf119 | 190 | $this->webtestLogin('admin'); |
8fe1f83e | 191 | $this->openCiviPage('report/instance/1', 'reset=1'); |
6a488035 TO |
192 | $this->click("is_reserved"); |
193 | $this->click("_qf_Summary_submit_save"); | |
194 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
331a5c18 | 195 | |
42daf119 | 196 | $this->webtestLogin($user, 'Test12345'); |
8fe1f83e | 197 | $this->openCiviPage('report/instance/1', 'reset=1'); |
6a488035 | 198 | |
687bced0 | 199 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='report-tab-col-groups']/table/tbody//tr/td[3]/input[@id='fields_email']")); |
200 | $this->assertTrue($this->isElementPresent("xpath=//div[@id='report-tab-format']/table/tbody//tr/td[2]/input[@id='title']")); | |
331a5c18 | 201 | |
6a488035 | 202 | //login as admin and delete the role |
42daf119 | 203 | $this->webtestLogin('admin'); |
6a488035 TO |
204 | $this->open($this->sboxPath . "admin/people/permissions/roles"); |
205 | $this->_roleDelete($role); | |
206 | } | |
331a5c18 | 207 | |
4cbe18b8 EM |
208 | /** |
209 | * @param $role | |
210 | */ | |
00be9182 | 211 | public function _roleDelete($role) { |
6a488035 TO |
212 | $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']"); |
213 | $this->click("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']"); | |
214 | $this->waitForElementPresent('edit-delete'); | |
215 | $this->click('edit-delete'); | |
216 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
217 | $this->click("edit-submit"); | |
218 | $this->waitForTextPresent("The role has been deleted."); | |
219 | } | |
220 | ||
4cbe18b8 | 221 | /** |
100fef9d | 222 | * @param int $roleid |
4cbe18b8 EM |
223 | * |
224 | * @return string | |
225 | */ | |
00be9182 | 226 | public function _testCreateUser($roleid) { |
6a488035 | 227 | |
6a488035 TO |
228 | $this->open($this->sboxPath . "admin/people/create"); |
229 | ||
230 | $this->waitForElementPresent("edit-submit"); | |
231 | ||
232 | $name = "TestUser" . substr(sha1(rand()), 0, 4); | |
233 | $this->type("edit-name", $name); | |
234 | ||
235 | $emailId = substr(sha1(rand()), 0, 7) . '@web.com'; | |
236 | $this->type("edit-mail", $emailId); | |
237 | $this->type("edit-pass-pass1", "Test12345"); | |
238 | $this->type("edit-pass-pass2", "Test12345"); | |
239 | $role = "edit-roles-" . $roleid; | |
240 | $this->check("name=roles[$roleid] value={$roleid}"); | |
241 | ||
242 | //Add profile Details | |
243 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
244 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
245 | ||
246 | $this->type("first_name", $firstName); | |
247 | $this->type("last_name", $lastName); | |
248 | ||
249 | //Address Details | |
250 | $this->type("street_address-1", "902C El Camino Way SW"); | |
251 | $this->type("city-1", "Dumfries"); | |
252 | $this->type("postal_code-1", "1234"); | |
253 | $this->select("state_province-1", "value=1019"); | |
254 | ||
255 | $this->click("edit-submit"); | |
256 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
257 | return $name; | |
258 | } | |
42daf119 | 259 | } |