Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
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_Contact_GroupAddTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testGroupAdd() { | |
39 | $this->webtestLogin(); | |
40 | ||
41 | $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload-bottom'); | |
42 | ||
43 | // Group name | |
44 | $params = array('name' => 'group_' . substr(sha1(rand()), 0, 7)); | |
45 | ||
46 | // fill group name | |
47 | $this->type("title", $params['name']); | |
48 | ||
49 | // fill description | |
50 | $this->type("description", "Adding new group."); | |
51 | ||
52 | // check Access Control | |
53 | if (isset($params['type1']) && $params['type1'] !== FALSE) { | |
54 | $this->click("group_type[1]"); | |
55 | } | |
56 | ||
57 | // check Mailing List | |
58 | if (isset($params['type2']) && $params['type2'] !== FALSE) { | |
59 | $this->click("group_type[2]"); | |
60 | } | |
61 | ||
62 | // select Visibility as Public Pages | |
63 | $params['visibility'] = 'Public Pages'; | |
64 | ||
65 | $this->select("visibility", "value={$params['visibility']}"); | |
66 | ||
67 | // Clicking save. | |
68 | $this->click("_qf_Edit_upload"); | |
69 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
70 | ||
71 | // Is status message correct? | |
6c5f7368 | 72 | $this->waitForText('crm-notification-container', "The Group '{$params['name']}' has been saved."); |
6a488035 | 73 | |
d8bd5fb9 | 74 | $this->openCiviPage('group', 'reset=1'); |
6a488035 TO |
75 | $this->type('title', $params['name']); |
76 | $this->click('_qf_Search_refresh'); | |
aeaa5f5d JP |
77 | $this->waitForElementPresent("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]"); |
78 | $createdBy = $this->getText("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td[3]/a"); | |
79 | $this->click("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td[7]/span/a[2]"); | |
6a488035 TO |
80 | $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/table[2]/tbody/tr/td[2]/select"); |
81 | ||
82 | //assert created by in the edit page | |
51063434 | 83 | $this->assertTrue($this->isElementPresent( |
cd2cbabd | 84 | "xpath=//form[@id='Edit']/div[2]/div/table/tbody/tr[2]/td[contains(text(), '{$createdBy}')]")); |
d8bd5fb9 | 85 | $this->openCiviPage('group', 'reset=1'); |
6a488035 TO |
86 | |
87 | //search groups using created by | |
88 | $this->type('created_by', $createdBy); | |
89 | $this->click('_qf_Search_refresh'); | |
237f3ea3 PJ |
90 | |
91 | //show maximum no. of groups on first result set page | |
92 | //as many groups can be created by same creator | |
93 | //and checking is done on first result set page | |
aeaa5f5d JP |
94 | $this->waitForVisible("xpath=//table[@class='crm-group-selector no-footer dataTable']"); |
95 | $this->select("xpath=//div[@class='dataTables_length']/label/select", '100'); | |
96 | $this->waitForVisible("xpath=//table[@class='crm-group-selector no-footer dataTable']"); | |
237f3ea3 | 97 | |
aeaa5f5d JP |
98 | $this->waitForElementPresent("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]"); |
99 | $this->click("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]/../following-sibling::td[2]/a[text()='{$createdBy}']"); | |
100 | $this->assertTrue($this->isElementPresent("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody/tr/td/span[contains(text(), '{$params['name']}')]/../following-sibling::td[2]/a[text()='{$createdBy}']")); | |
6a488035 TO |
101 | |
102 | //check link of the contact who created the group | |
aeaa5f5d | 103 | $this->click("xpath=//table[@class='crm-group-selector no-footer dataTable']/tbody//tr/td[1]/span[contains(text(),'{$params['name']}')]/../following-sibling::td[2]/a"); |
6a488035 TO |
104 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
105 | $name = explode(',', $createdBy); | |
237f3ea3 | 106 | $name1 = isset($name[1]) ? trim($name[1]) : NULL; |
4f01dd50 PJ |
107 | $name0 = trim($name[0]); |
108 | $displayName = isset($name1) ? "{$name1} {$name0}" : "{$name0}"; | |
109 | $this->assertElementContainsText("css=div.crm-summary-display_name", $displayName); | |
6a488035 TO |
110 | } |
111 | ||
112 | function testGroupReserved() { | |
42daf119 | 113 | $this->webtestLogin('admin'); |
6a488035 TO |
114 | |
115 | $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload-bottom'); | |
116 | ||
117 | // take group name | |
118 | $params = array('name' => 'group_' . substr(sha1(rand()), 0, 7)); | |
119 | ||
120 | // fill group name | |
121 | $this->type("title", $params['name']); | |
122 | ||
123 | // fill description | |
124 | $this->type("description", "Adding new reserved group."); | |
125 | ||
126 | // check Access Control | |
127 | if (isset($params['type1']) && $params['type1'] !== FALSE) { | |
128 | $this->click("group_type[1]"); | |
129 | } | |
130 | ||
131 | // check Mailing List | |
132 | if (isset($params['type2']) && $params['type2'] !== FALSE) { | |
133 | $this->click("group_type[2]"); | |
134 | } | |
135 | ||
136 | // select Visibility as Public Pages | |
137 | if (empty($params['visibility'])) { | |
138 | $params['visibility'] = 'Public Pages'; | |
139 | } | |
140 | ||
141 | $this->select("visibility", "value={$params['visibility']}"); | |
142 | ||
143 | // Check Reserved box | |
144 | $this->click("is_reserved"); | |
4f01dd50 | 145 | |
6a488035 TO |
146 | // Clicking save. |
147 | $this->click("_qf_Edit_upload"); | |
148 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
149 | ||
150 | // Is status message correct? | |
151 | $this->assertTrue($this->isTextPresent("The Group '{$params['name']}' has been saved.")); | |
4f01dd50 | 152 | |
6a488035 TO |
153 | // Create a new role w/o reserved group permissions |
154 | $role = 'role' . substr(sha1(rand()), 0, 7); | |
155 | $this->open($this->sboxPath . "admin/people/permissions/roles"); | |
156 | ||
157 | $this->waitForElementPresent("edit-add"); | |
158 | $this->type("edit-name", $role); | |
159 | $this->click("edit-add"); | |
160 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
4f01dd50 | 161 | |
6a488035 TO |
162 | $this->open($this->sboxPath . "admin/people/permissions/roles"); |
163 | $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']"); | |
164 | $roleId = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']/../td[4]/a[text()='edit permissions']/@href")); | |
165 | $roleId = end($roleId); | |
166 | $user = $this->_testCreateUser($roleId); | |
167 | $permissions = array( | |
168 | "edit-{$roleId}-view-all-contacts", | |
169 | "edit-{$roleId}-access-civicrm", | |
170 | ); | |
171 | $this->changePermissions($permissions); | |
4f01dd50 | 172 | |
071a6d2e CW |
173 | // Now logout as admin, login as regular user and verify that Group settings, |
174 | // delete and disable links are not available | |
42daf119 | 175 | $this->webtestLogin($user, 'Test12345'); |
4f01dd50 | 176 | |
d8bd5fb9 | 177 | $this->openCiviPage('group', 'reset=1'); |
6a488035 TO |
178 | $this->type('title', $params['name']); |
179 | $this->click('_qf_Search_refresh'); | |
180 | $this->waitForTextPresent("Adding new reserved group."); | |
071a6d2e CW |
181 | // Settings link should NOT be included in selector |
182 | // after search returns with only the reserved group. | |
d8bd5fb9 | 183 | $this->assertElementNotContainsText("css=td.crm-group-group_links", "Settings"); |
6a488035 TO |
184 | |
185 | //login as admin and delete the role | |
42daf119 | 186 | $this->webtestLogin('admin'); |
6a488035 TO |
187 | $this->open($this->sboxPath . "admin/people/permissions/roles"); |
188 | $this->_roleDelete($role); | |
6a488035 TO |
189 | } |
190 | ||
4cbe18b8 EM |
191 | /** |
192 | * @param $roleid | |
193 | * | |
194 | * @return string | |
195 | */ | |
6a488035 | 196 | function _testCreateUser($roleid) { |
6a488035 TO |
197 | $this->open($this->sboxPath . "admin/people/create"); |
198 | ||
199 | $this->waitForElementPresent("edit-submit"); | |
200 | ||
201 | $name = "TestUser" . substr(sha1(rand()), 0, 4); | |
202 | $this->type("edit-name", $name); | |
203 | ||
204 | $emailId = substr(sha1(rand()), 0, 7) . '@web.com'; | |
205 | $this->type("edit-mail", $emailId); | |
206 | $this->type("edit-pass-pass1", "Test12345"); | |
207 | $this->type("edit-pass-pass2", "Test12345"); | |
208 | $role = "edit-roles-" . $roleid; | |
209 | $this->check("name=roles[$roleid] value={$roleid}"); | |
210 | ||
211 | //Add profile Details | |
212 | $firstName = 'Ma' . substr(sha1(rand()), 0, 4); | |
213 | $lastName = 'An' . substr(sha1(rand()), 0, 7); | |
214 | ||
215 | $this->type("first_name", $firstName); | |
216 | $this->type("last_name", $lastName); | |
217 | ||
218 | //Address Details | |
219 | $this->type("street_address-1", "902C El Camino Way SW"); | |
220 | $this->type("city-1", "Dumfries"); | |
221 | $this->type("postal_code-1", "1234"); | |
222 | $this->select("state_province-1", "value=1019"); | |
223 | ||
224 | $this->click("edit-submit"); | |
225 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
226 | return $name; | |
227 | } | |
4f01dd50 | 228 | |
4cbe18b8 EM |
229 | /** |
230 | * @param $role | |
231 | */ | |
6a488035 TO |
232 | function _roleDelete($role) { |
233 | $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']"); | |
234 | $this->click("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']"); | |
235 | $this->waitForElementPresent('edit-delete'); | |
236 | $this->click('edit-delete'); | |
237 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
238 | $this->click("edit-submit"); | |
239 | $this->waitForTextPresent("The role has been deleted."); | |
240 | } | |
ec635ea5 RK |
241 | |
242 | /** | |
243 | * Webtest for add contact to group (CRM-15108) | |
244 | */ | |
245 | function testAddContactToGroup() { | |
246 | $this->webtestLogin(); | |
247 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); | |
248 | $this->waitForElementPresent('_qf_Contact_upload_view-bottom'); | |
249 | ||
250 | //Create contact. | |
251 | $group = "Advisory Board"; | |
252 | $firstName = "Adams".substr(sha1(rand()), 0, 4); | |
253 | $lastName = substr(sha1(rand()), 0, 4); | |
254 | $email = "{$lastName}.{$firstName}@example.org"; | |
255 | $this->type('first_name', $firstName); | |
256 | $this->type('last_name', $lastName); | |
257 | $this->type('email_1_email', "{$firstName}.{$lastName}@example.com"); | |
258 | $this->click('_qf_Contact_upload_view-bottom'); | |
259 | $this->waitForText('crm-notification-container', "Contact Saved"); | |
260 | ||
261 | $this->openCiviPage('group', 'reset=1'); | |
262 | $this->waitForElementPresent("xpath=//a/span[text()='Add Group']"); | |
263 | $this->waitForElementPresent("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[1]/span[contains(text(), '{$group}')]"); | |
264 | $this->click("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[1]/span[text()='{$group}']/../../td[7]/span[1]/a[1]"); | |
265 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
266 | $this->clickLink("xpath=//form[@id='Basic']/div[2]/a/span"); | |
267 | $this->waitForElementPresent("_qf_Basic_refresh"); | |
268 | $this->type('sort_name', $firstName); | |
269 | $this->click('_qf_Basic_refresh'); | |
270 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
271 | $this->waitForElementPresent("_qf_Basic_next_action"); | |
272 | ||
273 | $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']")); | |
274 | $this->click("xpath=//table/tbody//tr/td[1]/input[@type='checkbox']"); | |
275 | $this->click('_qf_Basic_next_action'); | |
276 | $this->waitForElementPresent("_qf_AddToGroup_back-bottom"); | |
277 | $this->click('_qf_AddToGroup_next-bottom'); | |
278 | $this->waitForText('crm-notification-container', "1 contact added to group"); | |
279 | ||
280 | $this->openCiviPage('contact/search', 'reset=1'); | |
281 | $this->waitForElementPresent("_qf_Basic_refresh"); | |
282 | $this->type('sort_name', $firstName); | |
283 | $this->select('group',"Advisory Board"); | |
284 | $this->click('_qf_Basic_refresh'); | |
285 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
286 | $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']")); | |
287 | } | |
42daf119 | 288 | } |