Merge pull request #6111 from colemanw/CRM-11856
[civicrm-core.git] / tests / phpunit / WebTest / ACL / AssignUsersToRolesTest.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_ACL_AssignUsersToRolesTest
31 */
32 class WebTest_ACL_AssignUsersToRolesTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testAssignUsersToRoles() {
39
40 $this->webtestLogin();
41
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());
48
49 $this->waitForText('crm-notification-container', "The Group '{$groupTitle}' has been saved.");
50
51 $this->openCiviPage("admin/options/acl_role", "action=add&reset=1", "_qf_Options_cancel-bottom");
52
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");
57
58 $this->waitForText('crm-notification-container', "The ACL Role '{$label}' has been saved.");
59
60 $this->openCiviPage("acl/entityrole", "action=add&reset=1");
61
62 $this->select("acl_role_id", "label=" . $label);
63 $this->select("entity_id", "label={$groupTitle}");
64
65 $this->clickLink("_qf_EntityRole_next-botttom");
66
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");
74 }
75
76 public function testACLforSmartGroups() {
77 $this->webtestLogin();
78
79 //Create role
80 $role = 'role' . substr(sha1(rand()), 0, 7);
81 $this->open($this->sboxPath . "admin/people/permissions/roles");
82 $this->waitForElementPresent("edit-submit");
83 $this->type("edit-name", $role);
84 $this->click("edit-add");
85 $this->waitForPageToLoad($this->getTimeoutMsec());
86 $this->open($this->sboxPath . "admin/people/permissions/roles");
87 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']");
88 $roleURL = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']/../td[4]/a[text()='edit permissions']/@href"));
89 $roleId = end($roleURL);
90
91 //create user with roleId
92 $this->open($this->sboxPath . "admin/people/create");
93 $this->waitForElementPresent("edit-submit");
94 $user = "TestUser" . substr(sha1(rand()), 0, 4);
95 $this->type("edit-name", $user);
96 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
97 $this->type("edit-mail", $emailId);
98 $this->type("edit-pass-pass1", "Test12345");
99 $this->type("edit-pass-pass2", "Test12345");
100 $role = "edit-roles-" . $roleId;
101 $this->check("name=roles[$roleId] value={$roleId}");
102 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
103 $lastName = 'An' . substr(sha1(rand()), 0, 7);
104 $this->type("first_name", $firstName);
105 $this->type("last_name", $lastName);
106 $this->click("edit-submit");
107 $this->waitForPageToLoad($this->getTimeoutMsec());
108 $permissions = array("edit-{$roleId}-access-civicrm");
109 $this->changePermissions($permissions);
110
111 //Create group and add your user's contact to that group
112 $this->openCiviPage("group/add", "reset=1");
113 $groupTitle = "testGroup" . substr(sha1(rand()), 0, 4);
114 $this->type("title", $groupTitle);
115 $this->click("group_type[1]");
116 $this->click("_qf_Edit_upload-bottom");
117 $this->waitForPageToLoad($this->getTimeoutMsec());
118 $this->waitForText('crm-notification-container', "The Group '{$groupTitle}' has been saved.");
119 $this->waitForElementPresent("_qf_Basic_refresh");
120 $this->type('sort_name', $firstName);
121 $this->click('_qf_Basic_refresh');
122 $this->waitForPageToLoad($this->getTimeoutMsec());
123 $this->waitForElementPresent("_qf_Basic_next_action");
124 $this->assertTrue($this->isElementPresent("xpath=//table[@class='selector row-highlight']/tbody/tr/td[3]/a[text()='{$lastName}, {$firstName}']"));
125 $this->click("xpath=//table[@class='selector row-highlight']/tbody//tr/td[1]/input[@type='checkbox']");
126 $this->click('_qf_Basic_next_action');
127 $this->waitForElementPresent("_qf_AddToGroup_back-bottom");
128 $this->click('_qf_AddToGroup_next-bottom');
129 $this->waitForText('crm-notification-container', "1 contact added to group");
130
131 //create Smart Group
132 $this->openCiviPage('contact/search/advanced', 'reset=1');
133 $this->click("location");
134 $this->waitForElementPresent("country");
135 $this->select("country", "United States");
136 $this->clickLink("_qf_Advanced_refresh");
137 $this->waitForElementPresent("task");
138 $this->click('radio_ts', 'ts_all');
139 $this->click('task');
140 $this->select('task', 'label=New Smart Group');
141 $this->waitForPageToLoad($this->getTimeoutMsec());
142 $smartGroupTitle = "SmartGroup" . substr(sha1(rand()), 0, 4);
143 $this->type("title", $smartGroupTitle);
144 $this->clickLink("_qf_SaveSearch_next-bottom");
145 $this->waitForText('crm-notification-container', "Your smart group has been saved as \'$smartGroupTitle\'");
146
147 //Create ACL role
148 $this->openCiviPage("admin/options/acl_role", "action=add&reset=1", "_qf_Options_cancel-bottom");
149 $label = "TestAclRole" . substr(sha1(rand()), 0, 4);
150 $this->type("label", $label);
151 $this->type("value", "Acl value" . $label);
152 $this->click("_qf_Options_next-bottom");
153 $this->waitForText('crm-notification-container', "The ACL Role '{$label}' has been saved.");
154
155 // Assign group to ACL role created
156 $this->openCiviPage("acl/entityrole", "action=add&reset=1");
157 $this->select("acl_role_id", "label=" . $label);
158 $this->select("entity_id", "label={$groupTitle}");
159 $this->clickLink("_qf_EntityRole_next-botttom");
160
161 //Create ACL granting 'Edit' access on smart group to the role
162 $this->openCiviPage("acl", "action=add&reset=1");
163 $this->click("group_id");
164 $this->select("group_id", "label={$smartGroupTitle}");
165 $this->select("operation", "label=Edit");
166 $this->select("entity_id", "label={$label}");
167 $this->type("name", "describe {$label}");
168 $this->clickLink("_qf_ACL_next-bottom");
169
170 //Login as your role user and do Find Contacts
171 $this->webtestLogin($user, 'Test12345');
172 $this->openCiviPage('contact/search/advanced', 'reset=1');
173 $this->click("location");
174 $this->waitForElementPresent("country");
175 $this->select("country", "United States");
176 $this->clickLink("_qf_Advanced_refresh");
177 $this->waitForElementPresent("xpath=//div[@class='crm-search-results']");
178 $this->assertElementNotContainsText("xpath=//form[@id='Advanced']/div[3]/div/div", "No matches found for");
179 $this->verifyText("xpath=//div[@class='crm-search-results']//table/tbody/tr[1]/td[8]", 'United States');
180 }
181
182 }