3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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';
30 * Class WebTest_ACL_AssignUsersToRolesTest
32 class WebTest_ACL_AssignUsersToRolesTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testAssignUsersToRoles() {
40 $this->webtestLogin();
42 $this->openCiviPage("group/add", "reset=1");
43 $groupTitle = "testGroup" . substr(sha1(rand()), 0, 4);
44 $this->type("title", $groupTitle);
45 $this->click("group_type[1]");
46 $this->click("_qf_Edit_upload-bottom");
47 $this->waitForPageToLoad($this->getTimeoutMsec());
49 $this->waitForText('crm-notification-container', "The Group '{$groupTitle}' has been saved.");
51 $this->openCiviPage("admin/options/acl_role", "action=add&reset=1", "_qf_Options_cancel-bottom");
53 $label = "TestAclRole" . substr(sha1(rand()), 0, 4);
54 $this->type("label", $label);
55 $this->type("value", "Acl value" . $label);
56 $this->click("_qf_Options_next-bottom");
58 $this->waitForText('crm-notification-container', "The ACL Role '{$label}' has been saved.");
60 $this->openCiviPage("acl/entityrole", "action=add&reset=1");
62 $this->select("acl_role_id", "label=" . $label);
63 $this->select("entity_id", "label={$groupTitle}");
65 $this->clickLink("_qf_EntityRole_next-botttom");
67 $this->openCiviPage("acl", "action=add&reset=1");
68 $this->click("group_id");
69 $this->select("group_id", "label={$groupTitle}");
70 $this->select("operation", "label=View");
71 $this->select("entity_id", "label={$label}");
72 $this->type("name", "describe {$label}");
73 $this->clickLink("_qf_ACL_next-bottom");
77 * Check ACL for Smart Groups and Profiles.
79 public function testACLforSmartGroupsAndProfiles() {
80 $this->webtestLogin();
83 $role = 'role' . substr(sha1(rand()), 0, 7);
84 $this->open($this->sboxPath
. "admin/people/permissions/roles");
85 $this->waitForAjaxContent();
86 $this->type("edit-name", $role);
87 $this->click("edit-add");
88 $this->waitForPageToLoad($this->getTimeoutMsec());
89 $this->open($this->sboxPath
. "admin/people/permissions/roles");
90 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']");
91 $roleURL = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']/../td[4]/a[text()='edit permissions']/@href"));
92 $roleId = end($roleURL);
94 //create user with roleId
95 $this->open($this->sboxPath
. "admin/people/create");
96 $this->waitForElementPresent("edit-submit");
97 $user = "TestUser" . substr(sha1(rand()), 0, 4);
98 $this->type("edit-name", $user);
99 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
100 $this->type("edit-mail", $emailId);
101 $this->type("edit-pass-pass1", "Test12345");
102 $this->type("edit-pass-pass2", "Test12345");
103 $role = "edit-roles-" . $roleId;
104 $this->check("name=roles[$roleId] value={$roleId}");
105 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
106 $lastName = 'An' . substr(sha1(rand()), 0, 7);
107 $this->type("first_name", $firstName);
108 $this->type("last_name", $lastName);
109 $this->click("edit-submit");
110 $this->waitForPageToLoad($this->getTimeoutMsec());
111 $permissions = array("edit-{$roleId}-access-civicrm");
112 $this->changePermissions($permissions);
114 //Create group and add your user's contact to that group
115 $this->openCiviPage("group/add", "reset=1");
116 $groupTitle = "testGroup" . substr(sha1(rand()), 0, 4);
117 $this->type("title", $groupTitle);
118 $this->click("group_type[1]");
119 $this->click("_qf_Edit_upload-bottom");
120 $this->waitForPageToLoad($this->getTimeoutMsec());
121 $this->waitForText('crm-notification-container', "The Group '{$groupTitle}' has been saved.");
122 $this->waitForElementPresent("_qf_Basic_refresh");
123 $this->type('sort_name', $firstName);
124 $this->click('_qf_Basic_refresh');
125 $this->waitForPageToLoad($this->getTimeoutMsec());
126 $this->waitForElementPresent("_qf_Basic_next_action");
127 $this->assertTrue($this->isElementPresent("xpath=//table[@class='selector row-highlight']/tbody/tr/td[3]/a[text()='{$lastName}, {$firstName}']"));
128 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr/td[1]/input[@type='checkbox']");
129 $this->click('_qf_Basic_next_action');
130 $this->waitForElementPresent("_qf_AddToGroup_back-bottom");
131 $this->click('_qf_AddToGroup_next-bottom');
132 $this->waitForText('crm-notification-container', "1 contact added to group");
135 $this->openCiviPage('contact/search/advanced', 'reset=1');
136 $this->click("location");
137 $this->waitForElementPresent("country");
138 $this->select("country", "United States");
139 $this->clickLink("_qf_Advanced_refresh");
140 $this->waitForElementPresent("task");
141 $this->click('radio_ts', 'ts_all');
142 $this->click('task');
143 $this->select('task', 'label=New Smart Group');
144 $this->waitForPageToLoad($this->getTimeoutMsec());
145 $smartGroupTitle = "SmartGroup" . substr(sha1(rand()), 0, 4);
146 $this->type("title", $smartGroupTitle);
147 $this->clickLink("_qf_SaveSearch_next-bottom");
148 $this->waitForText('crm-notification-container', "Your smart group has been saved as \'$smartGroupTitle\'");
151 $this->openCiviPage("admin/options/acl_role", "reset=1", "xpath=//a[@class='button new-option']");
152 $this->click("xpath=//a[@class='button new-option']");
153 $label = "TestAclRole" . substr(sha1(rand()), 0, 4);
154 $this->waitForElementPresent("label");
155 $this->type("label", $label);
156 $this->type("value", "Acl value" . $label);
157 $this->click("_qf_Options_next-bottom");
158 $this->waitForText('crm-notification-container', "The ACL Role '{$label}' has been saved.");
160 // Assign group to ACL role created
161 $this->openCiviPage("acl/entityrole", "reset=1", 'newACL');
162 $this->click('newACL');
163 $this->waitForElementPresent("acl_role_id");
164 $this->select("acl_role_id", "label=" . $label);
165 $this->select("entity_id", "label={$groupTitle}");
166 $this->clickLink("_qf_EntityRole_next-botttom", 'newACL', FALSE);
168 //Create ACL granting 'Edit' access on smart group to the role
169 $this->openCiviPage("acl", "reset=1");
170 $this->click('newACL');
171 $this->waitForElementPresent("group_id");
172 $this->select("group_id", "label={$smartGroupTitle}");
173 $this->select("operation", "label=Edit");
174 $this->select("entity_id", "label={$label}");
175 $this->type("name", "describe {$label}");
176 $this->clickLink("_qf_ACL_next-bottom", 'newACL', FALSE);
178 //ACL granting edit permission on events.
179 $this->click('newACL');
180 $this->waitForElementPresent('name');
181 $this->type("name", "Edit All Events $label");
182 $this->select("entity_id", "label={$label}");
183 $this->select("operation", "label=Edit");
184 $this->click("xpath=//label[contains(text(), 'Events')]");
185 $this->select("event_id", "value=0");
186 $this->clickLink("_qf_ACL_next-bottom", 'newACL', FALSE);
188 $this->webtestLogin($user, 'Test12345');
189 $this->openCiviPage('event/manage/registration', 'reset=1&action=update&id=3');
190 //ensure all the three buttons are not displayed
191 $this->waitForElementPresent('registration_screen');
192 $this->verifyElementNotPresent("xpath=//div[@id='registration_screen']/table[2]/tbody/tr/td[2]/div/div/button[contains(text(), 'Edit')]");
193 $this->verifyElementNotPresent("xpath=//div[@id='registration_screen']/table[2]/tbody/tr/td[2]/div/div//button[contains(text(), 'Copy')]");
194 $this->verifyElementNotPresent("xpath=//div[@id='registration_screen']/table[2]/tbody/tr/td[2]/div/div//button[contains(text(), 'Create')]");
195 $this->webtestLogout();
197 $this->webtestLogin();
199 //Create ACL granting Edit permission on Profiles
200 $this->openCiviPage("acl", "reset=1", 'newACL');
201 $this->click('newACL');
202 $this->waitForElementPresent('name');
203 $this->type("name", "Edit All Profiles $label");
204 $this->select("entity_id", "label={$label}");
205 $this->select("operation", "label=Edit");
206 $this->click("xpath=//label[contains(text(), 'A profile')]");
207 $this->select("uf_group_id", "value=0");
208 $this->clickLink("_qf_ACL_next-bottom", 'newACL', FALSE);
210 //Login as your role user and do Find Contacts
211 $this->webtestLogin($user, 'Test12345');
212 $this->openCiviPage('contact/search/advanced', 'reset=1');
213 $this->click("location");
214 $this->waitForElementPresent("country");
215 $this->select("country", "United States");
216 $this->clickLink("_qf_Advanced_refresh");
217 $this->waitForElementPresent("xpath=//div[@class='crm-search-results']");
218 $this->assertElementNotContainsText("xpath=//form[@id='Advanced']/div[3]/div/div", "No matches found for");
219 $this->verifyText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[8]", 'United States');
221 $this->checkEditOnEventProfile();
225 * CRM-16776 - Check Profile Edit on Events with 'manage event profile' permission.
227 public function testEventProfilePermission() {
228 $this->webtestLogin();
231 $role = 'role' . substr(sha1(rand()), 0, 7);
232 $this->open($this->sboxPath
. "admin/people/permissions/roles");
234 $this->waitForAjaxContent();
235 $this->type("edit-name", $role);
236 $this->click("edit-add");
237 $this->waitForPageToLoad($this->getTimeoutMsec());
239 $this->open($this->sboxPath
. "admin/people/permissions/roles");
240 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']");
241 $roleId = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']/../td[4]/a[text()='edit permissions']/@href"));
242 $roleId = end($roleId);
244 $this->open($this->sboxPath
. "admin/people/create");
245 $this->waitForElementPresent("edit-submit");
246 $name = "TestUser" . substr(sha1(rand()), 0, 4);
247 $this->type("edit-name", $name);
248 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
249 $this->type("edit-mail", $emailId);
250 $this->type("edit-pass-pass1", "Test12345");
251 $this->type("edit-pass-pass2", "Test12345");
252 $role = "edit-roles-" . $roleId;
253 $this->check("name=roles[$roleId] value={$roleId}");
255 //Add profile Details
256 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
257 $lastName = 'An' . substr(sha1(rand()), 0, 7);
258 $this->type("first_name", $firstName);
259 $this->type("last_name", $lastName);
261 $this->click("edit-submit");
262 $this->waitForPageToLoad($this->getTimeoutMsec());
264 $permissions = array("edit-{$roleId}-access-civicrm", "edit-{$roleId}-edit-all-events", "edit-{$roleId}-manage-event-profiles");
265 $this->changePermissions($permissions);
266 $this->webtestLogout();
267 $this->webtestLogin($name, 'Test12345');
268 $this->checkEditOnEventProfile();
272 * Check Profile Edit on OnlineRegistration Tab
274 public function checkEditOnEventProfile() {
275 $this->openCiviPage('event/manage/registration', 'reset=1&action=update&id=3');
276 //ensure all the three buttons are displayed
277 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[2]/tbody/tr/td[2]/div/div/button[contains(text(), 'Edit')]");
278 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[2]/tbody/tr/td[2]/div/div//button[contains(text(), 'Copy')]");
279 $this->waitForElementPresent("xpath=//div[@id='registration_screen']/table[2]/tbody/tr/td[2]/div/div//button[contains(text(), 'Create')]");
281 $this->click("xpath=//div[@id='registration_screen']/table[2]/tbody/tr/td[2]/div/div/button[contains(text(), 'Edit')]");
282 $this->waitForAjaxContent();
283 $this->waitForElementPresent("//div[@class='crm-designer-fields-region']");
284 if ($this->isElementPresent("xpath=//span[@class='crm-designer-label'][contains(text(), 'City')]")) {
285 $this->click("xpath=//span[@class='crm-designer-label'][contains(text(), 'City')]/../../span//a[@title='Remove']");
286 $this->waitForElementNotPresent("xpath=//span[@class='crm-designer-label'][contains(text(), 'City')]");
289 $this->click("xpath=//li[@class='crm-designer-palette-section jstree-closed']/a[contains(text(), 'Individual')]");
290 $this->waitForAjaxContent();
291 $this->doubleClick("xpath=//a[contains(text(), 'Individual')]/../ul//li/a[contains(text(), 'City')]");
292 $this->waitForAjaxContent();
294 $this->click("xpath=//button/span[contains(text(), 'Save')]");
295 $this->waitForElementPresent("crm-notification-container");
296 $this->assertElementNotContainsText("crm-notification-container", 'API permission check failed for UFGroup/create call; insufficient permission: require administer CiviCRM');
297 $this->click("_qf_Registration_upload-top");
298 $this->waitForTextPresent("'Online Registration' information has been saved.");
302 * CRM-16777: Allow to add schedule reminder for event through ACLs 'edit' permission
304 public function testACLforReminders() {
305 $this->webtestLogin('admin');
307 //Details for ACLUser1
308 $ACLrole1 = 'ACLrole1' . substr(sha1(rand()), 0, 7);
309 $ACLUser1 = "ACLUser1" . substr(sha1(rand()), 0, 4);
310 $emailId1 = substr(sha1(rand()), 0, 7) . '@web.com';
312 //create ACLrole1 (with 'Access CiviCRM' and 'Access CiviEvent' permissions only).
313 $this->open($this->sboxPath
. "admin/people/permissions/roles");
314 $this->type("edit-name", $ACLrole1);
315 $this->waitForElementPresent("edit-add");
316 $this->click("edit-add");
317 $this->waitForPageToLoad($this->getTimeoutMsec());
318 $this->open($this->sboxPath
. "admin/people/permissions/roles");
319 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$ACLrole1}']");
320 $roleId = explode("people/permissions/", $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$ACLrole1}']/../td[4]/a[text()='edit permissions']/@href"));
321 $permissions = array(
322 "edit-{$roleId[1]}-access-civicrm",
323 "edit-{$roleId[1]}-access-civievent",
325 $this->changePermissions($permissions);
328 $this->open($this->sboxPath
. "admin/people/create");
329 $this->waitForElementPresent("edit-submit");
330 $this->type("edit-name", $ACLUser1);
331 $this->type("edit-mail", $emailId1);
332 $this->type("edit-pass-pass1", "Test12345");
333 $this->type("edit-pass-pass2", "Test12345");
334 $this->click("xpath=//div[@class='form-item form-type-checkboxes form-item-roles']/div//div/label[contains(text(), '{$ACLrole1}')]");
335 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
336 $lastName = 'An' . substr(sha1(rand()), 0, 7);
337 $this->type("first_name", $firstName);
338 $this->type("last_name", $lastName);
339 $this->type("street_address-1", "902C El Camino Way SW");
340 $this->type("city-1", "Dumfries");
341 $this->type("postal_code-1", "1234");
342 $this->select("state_province-1", "value=1019");
343 $this->click("edit-submit");
344 $this->waitForPageToLoad($this->getTimeoutMsec());
346 //Create group and add contact.
347 $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload-bottom');
348 $groupTitle = 'ACLGroup' . substr(sha1(rand()), 0, 7);
349 $this->type("title", $groupTitle);
350 $this->click("group_type_1");
351 $this->click("_qf_Edit_upload-bottom");
352 $this->waitForElementPresent('_qf_Basic_refresh');
353 $this->type("sort_name", $firstName);
354 $this->click('_qf_Basic_refresh');
355 $this->waitForElementPresent('toggleSelect');
356 $this->click('_qf_Basic_next_action');
357 $this->waitForElementPresent('_qf_AddToGroup_back-bottom');
358 $this->click('_qf_AddToGroup_next-bottom');
359 $this->waitForTextPresent("1 contact added to group");
362 $this->openCiviPage("admin/options/acl_role", "action=add&reset=1", "_qf_Options_cancel-bottom");
363 $label = "TestAclRole" . substr(sha1(rand()), 0, 4);
364 $this->type("label", $label);
365 $this->type("value", "Acl value" . $label);
366 $this->click("_qf_Options_next-bottom");
367 $this->waitForText('crm-notification-container', "The ACL Role '{$label}' has been saved.");
368 $this->waitForAjaxContent();
369 $this->openCiviPage("acl/entityrole", "action=add&reset=1");
370 $this->waitForAjaxContent();
371 $this->select("acl_role_id", "label=" . $label);
372 $this->waitForAjaxContent();
373 $this->select("entity_id", "label={$groupTitle}");
374 $this->clickLink("_qf_EntityRole_next-botttom");
375 $this->openCiviPage("acl", "action=add&reset=1");
376 $this->type("name", "Edit Events{$label}");
377 $this->select("operation", "label=Edit");
378 $this->select("entity_id", "label={$label}");
379 $this->click("xpath=//tr[@class='crm-acl-form-block-object_type']/td[2]/label[contains(text(), 'Events')]");
380 $this->select("event_id", "label=All Events");
381 $this->clickLink("_qf_ACL_next-bottom");
382 $this->webtestLogout();
383 $this->webtestLogin($ACLUser1, 'Test12345');
385 //Add scheduled reminder
386 $this->openCiviPage("event/manage/reminder", "reset=1&action=browse&setTab=1&id=1");
387 $reminderTitle = "Fall Fundraiser Dinner" . substr(sha1(rand()), 0, 4);
388 $this->waitForElementPresent('newScheduleReminder');
389 $this->click("newScheduleReminder");
390 $this->waitForElementPresent("_qf_ScheduleReminders_next-bottom");
391 $this->type("title", $reminderTitle);
392 $this->select('entity', 'label=Registered');
393 $this->select('start_action_offset', 'label=1');
394 $this->select('start_action_condition', 'label=after');
395 $this->click('is_repeat');
396 $this->select('repetition_frequency_interval', 'label=2');
397 $this->select('end_date', 'label=Event End Date');
398 $this->click('recipient');
399 $this->select('recipient', 'label=Participant Role');
400 $subject = 'subject' . substr(sha1(rand()), 0, 4);
401 $this->type('subject', $subject);
402 $this->fillRichTextField("html_message", "This is the test HTML version here!!!", 'CKEditor');
403 $this->type("text_message", "This is the test text version here!!!");
404 $this->click('_qf_ScheduleReminders_next-bottom');
405 $this->webtestLogout();
408 $this->webtestLogin('admin');
409 $this->openCiviPage("acl", "reset=1");
410 $this->waitForAjaxContent();
411 $this->click("xpath=//div[contains(text(), 'Edit Events{$label}')]/../../td[7]/span/a[2][contains(text(), 'Disable')]");
412 $this->waitForTextPresent("Are you sure you want to disable this ACL?");
413 $this->click("xpath=//button//span[contains(text(), 'Yes')]");
415 //Login with same test-user created above
416 $this->webtestLogin($ACLUser1, 'Test12345');
417 $this->openCiviPage("event/manage", "reset=1");
418 $this->waitForElementPresent("xpath=//div[@id='event_status_id']/div[@class='dataTables_wrapper no-footer']");
419 $this->verifyText("xpath=//div[@id='event_status_id']/div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td", "None found.");