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