Merge pull request #12178 from jitendrapurohit/membership-4
[civicrm-core.git] / tests / phpunit / WebTest / Contact / GroupAddTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contact_GroupAddTest
31 */
6a488035
TO
32class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testGroupAdd() {
6a488035
TO
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 75 $this->type('title', $params['name']);
b02d5792 76 $this->click('title');
b9fdba0a 77 $this->waitForAjaxContent();
16dc87ac
WA
78 $this->waitForElementPresent("xpath=//table/tbody//tr/td/div[contains(text(), '{$params['name']}')]");
79 $createdBy = $this->getText("xpath=//table/tbody//tr/td[3]/a");
80 $this->click("xpath=//table/tbody//tr/td[7]//span/a[text()='Settings']");
fb93fc39 81 $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/table[1]/tbody/tr[2]/td[contains(text(), '{$createdBy}')]");
d8bd5fb9 82 $this->openCiviPage('group', 'reset=1');
6a488035
TO
83
84 //search groups using created by
85 $this->type('created_by', $createdBy);
b02d5792 86 $this->click('created_by');
237f3ea3
PJ
87
88 //show maximum no. of groups on first result set page
89 //as many groups can be created by same creator
90 //and checking is done on first result set page
b02d5792 91 $this->waitForVisible("xpath=//table[@class='crm-group-selector crm-ajax-table dataTable no-footer']");
aeaa5f5d 92 $this->select("xpath=//div[@class='dataTables_length']/label/select", '100');
b02d5792 93 $this->waitForVisible("xpath=//table[@class='crm-group-selector crm-ajax-table dataTable no-footer']");
237f3ea3 94
b02d5792 95 $this->waitForElementPresent("xpath=//table/tbody/tr/td/div[contains(text(), '{$params['name']}')]");
96 $this->click("xpath=//table/tbody/tr/td/div[contains(text(), '{$params['name']}')]/../following-sibling::td[2]/a[text()='{$createdBy}']");
97 $this->waitForElementPresent("xpath=//table/tbody/tr/td/div[contains(text(), '{$params['name']}')]/../following-sibling::td[2]/a[text()='{$createdBy}']");
6a488035
TO
98
99 //check link of the contact who created the group
b02d5792 100 $this->clickLink("xpath=//table/tbody//tr/td[1]/div[contains(text(),'{$params['name']}')]/../following-sibling::td[2]/a", "css=div.crm-summary-display_name", FALSE);
6a488035 101 $name = explode(',', $createdBy);
237f3ea3 102 $name1 = isset($name[1]) ? trim($name[1]) : NULL;
4f01dd50
PJ
103 $name0 = trim($name[0]);
104 $displayName = isset($name1) ? "{$name1} {$name0}" : "{$name0}";
105 $this->assertElementContainsText("css=div.crm-summary-display_name", $displayName);
6a488035
TO
106 }
107
00be9182 108 public function testGroupReserved() {
42daf119 109 $this->webtestLogin('admin');
6a488035
TO
110
111 $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload-bottom');
112
113 // take group name
114 $params = array('name' => 'group_' . substr(sha1(rand()), 0, 7));
115
116 // fill group name
117 $this->type("title", $params['name']);
118
119 // fill description
120 $this->type("description", "Adding new reserved group.");
121
122 // check Access Control
123 if (isset($params['type1']) && $params['type1'] !== FALSE) {
124 $this->click("group_type[1]");
125 }
126
127 // check Mailing List
128 if (isset($params['type2']) && $params['type2'] !== FALSE) {
129 $this->click("group_type[2]");
130 }
131
132 // select Visibility as Public Pages
133 if (empty($params['visibility'])) {
134 $params['visibility'] = 'Public Pages';
135 }
136
137 $this->select("visibility", "value={$params['visibility']}");
138
139 // Check Reserved box
140 $this->click("is_reserved");
4f01dd50 141
6a488035 142 // Clicking save.
c3ad8633 143 $this->clickLink("_qf_Edit_upload");
6a488035
TO
144
145 // Is status message correct?
c3ad8633 146 $this->waitForText('crm-notification-container', "The Group '{$params['name']}' has been saved.");
4f01dd50 147
6a488035
TO
148 // Create a new role w/o reserved group permissions
149 $role = 'role' . substr(sha1(rand()), 0, 7);
150 $this->open($this->sboxPath . "admin/people/permissions/roles");
151
152 $this->waitForElementPresent("edit-add");
153 $this->type("edit-name", $role);
c3ad8633 154 $this->clickLink("edit-add", NULL);
4f01dd50 155
6a488035
TO
156 $this->open($this->sboxPath . "admin/people/permissions/roles");
157 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']");
158 $roleId = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']/../td[4]/a[text()='edit permissions']/@href"));
159 $roleId = end($roleId);
160 $user = $this->_testCreateUser($roleId);
161 $permissions = array(
162 "edit-{$roleId}-view-all-contacts",
163 "edit-{$roleId}-access-civicrm",
164 );
165 $this->changePermissions($permissions);
4f01dd50 166
071a6d2e
CW
167 // Now logout as admin, login as regular user and verify that Group settings,
168 // delete and disable links are not available
42daf119 169 $this->webtestLogin($user, 'Test12345');
4f01dd50 170
d8bd5fb9 171 $this->openCiviPage('group', 'reset=1');
6a488035 172 $this->type('title', $params['name']);
b02d5792 173 $this->click('title');
6a488035 174 $this->waitForTextPresent("Adding new reserved group.");
071a6d2e
CW
175 // Settings link should NOT be included in selector
176 // after search returns with only the reserved group.
d8bd5fb9 177 $this->assertElementNotContainsText("css=td.crm-group-group_links", "Settings");
6a488035
TO
178
179 //login as admin and delete the role
42daf119 180 $this->webtestLogin('admin');
6a488035
TO
181 $this->open($this->sboxPath . "admin/people/permissions/roles");
182 $this->_roleDelete($role);
6a488035
TO
183 }
184
4cbe18b8 185 /**
100fef9d 186 * @param int $roleid
4cbe18b8
EM
187 *
188 * @return string
189 */
00be9182 190 public function _testCreateUser($roleid) {
6a488035
TO
191 $this->open($this->sboxPath . "admin/people/create");
192
193 $this->waitForElementPresent("edit-submit");
194
195 $name = "TestUser" . substr(sha1(rand()), 0, 4);
196 $this->type("edit-name", $name);
197
198 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
199 $this->type("edit-mail", $emailId);
200 $this->type("edit-pass-pass1", "Test12345");
201 $this->type("edit-pass-pass2", "Test12345");
202 $role = "edit-roles-" . $roleid;
203 $this->check("name=roles[$roleid] value={$roleid}");
204
205 //Add profile Details
206 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
207 $lastName = 'An' . substr(sha1(rand()), 0, 7);
208
209 $this->type("first_name", $firstName);
210 $this->type("last_name", $lastName);
211
212 //Address Details
213 $this->type("street_address-1", "902C El Camino Way SW");
214 $this->type("city-1", "Dumfries");
215 $this->type("postal_code-1", "1234");
216 $this->select("state_province-1", "value=1019");
217
218 $this->click("edit-submit");
219 $this->waitForPageToLoad($this->getTimeoutMsec());
220 return $name;
221 }
4f01dd50 222
4cbe18b8
EM
223 /**
224 * @param $role
225 */
00be9182 226 public function _roleDelete($role) {
6a488035
TO
227 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']");
228 $this->click("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']");
229 $this->waitForElementPresent('edit-delete');
230 $this->click('edit-delete');
231 $this->waitForPageToLoad($this->getTimeoutMsec());
232 $this->click("edit-submit");
233 $this->waitForTextPresent("The role has been deleted.");
234 }
ec635ea5 235
6c6e6187 236 /**
92915c55
TO
237 * Webtest for add contact to group (CRM-15108)
238 */
00be9182 239 public function testAddContactToGroup() {
ec635ea5
RK
240 $this->webtestLogin();
241 $this->openCiviPage("contact/add", "reset=1&ct=Individual");
242 $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
243
244 //Create contact.
245 $group = "Advisory Board";
92fcb95f 246 $firstName = "Adams" . substr(sha1(rand()), 0, 4);
ec635ea5
RK
247 $lastName = substr(sha1(rand()), 0, 4);
248 $email = "{$lastName}.{$firstName}@example.org";
249 $this->type('first_name', $firstName);
250 $this->type('last_name', $lastName);
251 $this->type('email_1_email', "{$firstName}.{$lastName}@example.com");
252 $this->click('_qf_Contact_upload_view-bottom');
253 $this->waitForText('crm-notification-container', "Contact Saved");
254
255 $this->openCiviPage('group', 'reset=1');
fb93fc39 256 $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div[@class='crm-submit-buttons']/a/span[text()=' Add Group']");
b02d5792 257 $this->waitForElementPresent("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[1]/div[contains(text(), '{$group}')]");
258 $this->click("xpath=//table[@id='DataTables_Table_0']/tbody//tr/td[1]/div[text()='{$group}']/../../td[7]/span[1]/a[1]");
ec635ea5
RK
259 $this->waitForPageToLoad($this->getTimeoutMsec());
260 $this->clickLink("xpath=//form[@id='Basic']/div[2]/a/span");
261 $this->waitForElementPresent("_qf_Basic_refresh");
262 $this->type('sort_name', $firstName);
263 $this->click('_qf_Basic_refresh');
264 $this->waitForPageToLoad($this->getTimeoutMsec());
265 $this->waitForElementPresent("_qf_Basic_next_action");
266
267 $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']"));
268 $this->click("xpath=//table/tbody//tr/td[1]/input[@type='checkbox']");
269 $this->click('_qf_Basic_next_action');
270 $this->waitForElementPresent("_qf_AddToGroup_back-bottom");
271 $this->click('_qf_AddToGroup_next-bottom');
272 $this->waitForText('crm-notification-container', "1 contact added to group");
273
274 $this->openCiviPage('contact/search', 'reset=1');
275 $this->waitForElementPresent("_qf_Basic_refresh");
276 $this->type('sort_name', $firstName);
6c6e6187 277 $this->select('group', "Advisory Board");
ec635ea5
RK
278 $this->click('_qf_Basic_refresh');
279 $this->waitForPageToLoad($this->getTimeoutMsec());
280 $this->assertTrue($this->isElementPresent("xpath=//table/tbody//tr/td[3]/a[text()='{$lastName}, {$firstName}']"));
281 }
96025800 282
d0f1a3ab 283 /**
284 * CRM-18585 - test to check OR operator on Smart Groups
285 */
286 public function testAddSmartGroup() {
287 $this->webtestLogin();
288 $this->openCiviPage('contact/search/advanced', 'reset=1');
289 $this->click("xpath=//input[@value='OR']");
290 $this->select('group', 'Advisory Board');
291 $this->select('contact_tags', 'Major Donor');
292 $this->clickLink("_qf_Advanced_refresh");
293 $this->waitForElementPresent("task");
294 $count = trim($this->getText("//div[@id='search-status']/table/tbody/tr/td"));
295
296 //create smart group for contacts resulted from OR operator search.
297 $this->click('radio_ts', 'ts_all');
298 $this->click('task');
299 $this->select('task', 'label=Group - create smart group');
300 $this->waitForPageToLoad($this->getTimeoutMsec());
301 $smartGroupTitle = "SmartGroup" . substr(sha1(rand()), 0, 4);
302 $this->type("title", $smartGroupTitle);
303 $this->clickLink("_qf_SaveSearch_next-bottom");
304 $this->waitForText('crm-notification-container', "Your smart group has been saved as '$smartGroupTitle'");
305 $this->clickLink("_qf_Result_done");
306 $expectedCount = explode('-', $this->getText("//div[@id='search-status']/table/tbody/tr/td"));
307 $this->assertEquals($count, trim($expectedCount[1]));
308
309 //Assert the count from Contacts link in Manage Group Page.
310 $this->openCiviPage('group', 'reset=1');
311 $this->waitForElementPresent("xpath=//table/tbody//tr//td/div[contains(text(), \"{$smartGroupTitle} (Smart Group)\")]");
312 $this->clickLink("xpath=//table/tbody//tr//td/div[contains(text(), \"{$smartGroupTitle} (Smart Group)\")]/../../td[@class='crm-group-group_links']/span/a[contains(text(), 'Contacts')]");
313 $this->waitForElementPresent("xpath=//span[contains(text(), \"Edit Smart Group Search Criteria for {$smartGroupTitle}\")]");
314 $this->clickLink("xpath=//a/span[contains(text(), \"Edit Smart Group Search Criteria for {$smartGroupTitle}\")]/");
315 $this->waitForElementPresent('search-status');
316 $expectedCount = explode('-', $this->getText("//div[@id='search-status']/table/tbody/tr/td"));
317 $this->assertEquals($count, trim($expectedCount[1]));
318 }
319
42daf119 320}