Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testGroupAdd() { | |
36 | $this->webtestLogin(); | |
37 | ||
38 | $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload-bottom'); | |
39 | ||
40 | // Group name | |
41 | $params = array('name' => 'group_' . substr(sha1(rand()), 0, 7)); | |
42 | ||
43 | // fill group name | |
44 | $this->type("title", $params['name']); | |
45 | ||
46 | // fill description | |
47 | $this->type("description", "Adding new group."); | |
48 | ||
49 | // check Access Control | |
50 | if (isset($params['type1']) && $params['type1'] !== FALSE) { | |
51 | $this->click("group_type[1]"); | |
52 | } | |
53 | ||
54 | // check Mailing List | |
55 | if (isset($params['type2']) && $params['type2'] !== FALSE) { | |
56 | $this->click("group_type[2]"); | |
57 | } | |
58 | ||
59 | // select Visibility as Public Pages | |
60 | $params['visibility'] = 'Public Pages'; | |
61 | ||
62 | $this->select("visibility", "value={$params['visibility']}"); | |
63 | ||
64 | // Clicking save. | |
65 | $this->click("_qf_Edit_upload"); | |
66 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
67 | ||
68 | // Is status message correct? | |
d8bd5fb9 | 69 | $this->assertElementContainsText('crm-notification-container', "The Group '{$params['name']}' has been saved."); |
6a488035 | 70 | |
d8bd5fb9 | 71 | $this->openCiviPage('group', 'reset=1'); |
6a488035 TO |
72 | $this->type('title', $params['name']); |
73 | $this->click('_qf_Search_refresh'); | |
74 | $this->waitForElementPresent("xpath=//table[@id='crm-group-selector']/tbody/tr/td[3]/a"); | |
75 | $createdBy = $this->getText("xpath=//table[@id='crm-group-selector']/tbody/tr/td[3]/a"); | |
76 | $this->click("xpath=//table[@id='crm-group-selector']/tbody/tr/td[7]/span/a[2]"); | |
77 | $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/table[2]/tbody/tr/td[2]/select"); | |
78 | ||
79 | //assert created by in the edit page | |
d8bd5fb9 RN |
80 | $this->assertTrue($this->isElementPresent("xpath=//form[@id='Edit']/div[2]/div/table/tbody/tr[2]/td[contains(text(),'Created By')]/following-sibling::td[contains(text(),'{$createdBy}')]")); |
81 | $this->openCiviPage('group', 'reset=1'); | |
6a488035 TO |
82 | |
83 | //search groups using created by | |
84 | $this->type('created_by', $createdBy); | |
85 | $this->click('_qf_Search_refresh'); | |
86 | $this->waitForElementPresent("xpath=//table[@id='crm-group-selector']/tbody//tr//td[3]/a"); | |
87 | $this->assertTrue($this->isElementPresent("xpath=//table[@id='crm-group-selector']/tbody//tr/td[1][text()='{$params['name']}']/following-sibling::td[2]/a[text()='{$createdBy}']")); | |
88 | ||
89 | //check link of the contact who created the group | |
90 | $this->click("xpath=//table[@id='crm-group-selector']/tbody//tr/td[1][text()='{$params['name']}']/following-sibling::td[2]/a"); | |
91 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
92 | $name = explode(',', $createdBy); | |
93 | $displayName = isset($name[1]) ? "{$name[1]} {$name[0]}" : "{$name[0]}"; | |
d8bd5fb9 | 94 | $this->assertElementContainsText("css=div.crm-summary-display_name",$displayName); |
6a488035 TO |
95 | } |
96 | ||
97 | function testGroupReserved() { | |
98 | $this->webtestLogin(true); | |
99 | ||
100 | $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload-bottom'); | |
101 | ||
102 | // take group name | |
103 | $params = array('name' => 'group_' . substr(sha1(rand()), 0, 7)); | |
104 | ||
105 | // fill group name | |
106 | $this->type("title", $params['name']); | |
107 | ||
108 | // fill description | |
109 | $this->type("description", "Adding new reserved group."); | |
110 | ||
111 | // check Access Control | |
112 | if (isset($params['type1']) && $params['type1'] !== FALSE) { | |
113 | $this->click("group_type[1]"); | |
114 | } | |
115 | ||
116 | // check Mailing List | |
117 | if (isset($params['type2']) && $params['type2'] !== FALSE) { | |
118 | $this->click("group_type[2]"); | |
119 | } | |
120 | ||
121 | // select Visibility as Public Pages | |
122 | if (empty($params['visibility'])) { | |
123 | $params['visibility'] = 'Public Pages'; | |
124 | } | |
125 | ||
126 | $this->select("visibility", "value={$params['visibility']}"); | |
127 | ||
128 | // Check Reserved box | |
129 | $this->click("is_reserved"); | |
130 | ||
131 | // Clicking save. | |
132 | $this->click("_qf_Edit_upload"); | |
133 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
134 | ||
135 | // Is status message correct? | |
136 | $this->assertTrue($this->isTextPresent("The Group '{$params['name']}' has been saved.")); | |
137 | ||
138 | // Create a new role w/o reserved group permissions | |
139 | $role = 'role' . substr(sha1(rand()), 0, 7); | |
140 | $this->open($this->sboxPath . "admin/people/permissions/roles"); | |
141 | ||
142 | $this->waitForElementPresent("edit-add"); | |
143 | $this->type("edit-name", $role); | |
144 | $this->click("edit-add"); | |
145 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
146 | ||
147 | $this->open($this->sboxPath . "admin/people/permissions/roles"); | |
148 | $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']"); | |
149 | $roleId = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']/../td[4]/a[text()='edit permissions']/@href")); | |
150 | $roleId = end($roleId); | |
151 | $user = $this->_testCreateUser($roleId); | |
152 | $permissions = array( | |
153 | "edit-{$roleId}-view-all-contacts", | |
154 | "edit-{$roleId}-access-civicrm", | |
155 | ); | |
156 | $this->changePermissions($permissions); | |
157 | ||
158 | // Now logout as admin, login as regular user and verify that Group settings, delete and disable links are not available | |
d8bd5fb9 | 159 | $this->openCiviPage('logout', 'reset=1', NULL); |
6a488035 TO |
160 | $this->open($this->sboxPath); |
161 | $this->waitForElementPresent('edit-submit'); | |
162 | $this->type('edit-name', $user); | |
163 | $this->type('edit-pass', 'Test12345'); | |
164 | $this->click('edit-submit'); | |
165 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
166 | ||
d8bd5fb9 | 167 | $this->openCiviPage('group', 'reset=1'); |
6a488035 TO |
168 | $this->type('title', $params['name']); |
169 | $this->click('_qf_Search_refresh'); | |
170 | $this->waitForTextPresent("Adding new reserved group."); | |
171 | // Settings link should NOT be included in selector after search returns with only the reserved group. | |
d8bd5fb9 | 172 | $this->assertElementNotContainsText("css=td.crm-group-group_links", "Settings"); |
6a488035 TO |
173 | |
174 | //login as admin and delete the role | |
d8bd5fb9 | 175 | $this->openCiviPage('logout', 'reset=1', NULL); |
6a488035 TO |
176 | $this->open($this->sboxPath); |
177 | $this->webtestLogin(TRUE); | |
178 | $this->open($this->sboxPath . "admin/people/permissions/roles"); | |
179 | $this->_roleDelete($role); | |
180 | ||
181 | } | |
182 | ||
183 | function _testCreateUser($roleid) { | |
184 | // Go directly to the URL of the screen that will Create User Authentically. | |
185 | $this->open($this->sboxPath . "admin/people/create"); | |
186 | ||
187 | $this->waitForElementPresent("edit-submit"); | |
188 | ||
189 | $name = "TestUser" . substr(sha1(rand()), 0, 4); | |
190 | $this->type("edit-name", $name); | |
191 | ||
192 | $emailId = substr(sha1(rand()), 0, 7) . '@web.com'; | |
193 | $this->type("edit-mail", $emailId); | |
194 | $this->type("edit-pass-pass1", "Test12345"); | |
195 | $this->type("edit-pass-pass2", "Test12345"); | |
196 | $role = "edit-roles-" . $roleid; | |
197 | $this->check("name=roles[$roleid] value={$roleid}"); | |
198 | ||
199 | //Add profile Details | |
200 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
201 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
202 | ||
203 | $this->type("first_name", $firstName); | |
204 | $this->type("last_name", $lastName); | |
205 | ||
206 | //Address Details | |
207 | $this->type("street_address-1", "902C El Camino Way SW"); | |
208 | $this->type("city-1", "Dumfries"); | |
209 | $this->type("postal_code-1", "1234"); | |
210 | $this->select("state_province-1", "value=1019"); | |
211 | ||
212 | $this->click("edit-submit"); | |
213 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
214 | return $name; | |
215 | } | |
216 | ||
217 | function _roleDelete($role) { | |
218 | $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']"); | |
219 | $this->click("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']"); | |
220 | $this->waitForElementPresent('edit-delete'); | |
221 | $this->click('edit-delete'); | |
222 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
223 | $this->click("edit-submit"); | |
224 | $this->waitForTextPresent("The role has been deleted."); | |
225 | } | |
226 | ||
227 | } | |
228 | ||
229 |