Merge pull request #11735 from mukeshcompucorp/CRM-21814-add-proper-container-to...
[civicrm-core.git] / tests / phpunit / WebTest / Contact / GroupAddTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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_Contact_GroupAddTest
31 */
32 class WebTest_Contact_GroupAddTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public 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?
72 $this->waitForText('crm-notification-container', "The Group '{$params['name']}' has been saved.");
73
74 $this->openCiviPage('group', 'reset=1');
75 $this->type('title', $params['name']);
76 $this->click('title');
77 $this->waitForAjaxContent();
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']");
81 $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/table[1]/tbody/tr[2]/td[contains(text(), '{$createdBy}')]");
82 $this->openCiviPage('group', 'reset=1');
83
84 //search groups using created by
85 $this->type('created_by', $createdBy);
86 $this->click('created_by');
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
91 $this->waitForVisible("xpath=//table[@class='crm-group-selector crm-ajax-table dataTable no-footer']");
92 $this->select("xpath=//div[@class='dataTables_length']/label/select", '100');
93 $this->waitForVisible("xpath=//table[@class='crm-group-selector crm-ajax-table dataTable no-footer']");
94
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}']");
98
99 //check link of the contact who created the group
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);
101 $name = explode(',', $createdBy);
102 $name1 = isset($name[1]) ? trim($name[1]) : NULL;
103 $name0 = trim($name[0]);
104 $displayName = isset($name1) ? "{$name1} {$name0}" : "{$name0}";
105 $this->assertElementContainsText("css=div.crm-summary-display_name", $displayName);
106 }
107
108 public function testGroupReserved() {
109 $this->webtestLogin('admin');
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");
141
142 // Clicking save.
143 $this->clickLink("_qf_Edit_upload");
144
145 // Is status message correct?
146 $this->waitForText('crm-notification-container', "The Group '{$params['name']}' has been saved.");
147
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);
154 $this->clickLink("edit-add", NULL);
155
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);
166
167 // Now logout as admin, login as regular user and verify that Group settings,
168 // delete and disable links are not available
169 $this->webtestLogin($user, 'Test12345');
170
171 $this->openCiviPage('group', 'reset=1');
172 $this->type('title', $params['name']);
173 $this->click('title');
174 $this->waitForTextPresent("Adding new reserved group.");
175 // Settings link should NOT be included in selector
176 // after search returns with only the reserved group.
177 $this->assertElementNotContainsText("css=td.crm-group-group_links", "Settings");
178
179 //login as admin and delete the role
180 $this->webtestLogin('admin');
181 $this->open($this->sboxPath . "admin/people/permissions/roles");
182 $this->_roleDelete($role);
183 }
184
185 /**
186 * @param int $roleid
187 *
188 * @return string
189 */
190 public function _testCreateUser($roleid) {
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 }
222
223 /**
224 * @param $role
225 */
226 public function _roleDelete($role) {
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 }
235
236 /**
237 * Webtest for add contact to group (CRM-15108)
238 */
239 public function testAddContactToGroup() {
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";
246 $firstName = "Adams" . substr(sha1(rand()), 0, 4);
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');
256 $this->waitForElementPresent("xpath=//div[@id='crm-main-content-wrapper']/div[@class='crm-submit-buttons']/a/span[text()=' Add Group']");
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]");
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);
277 $this->select('group', "Advisory Board");
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 }
282
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
320 }