Mass switch to openCiviPage method
[civicrm-core.git] / tests / phpunit / WebTest / Contact / GroupAddTest.php
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?
69 $this->assertElementContainsText('crm-notification-container', "The Group '{$params['name']}' has been saved.");
70
71 $this->openCiviPage('group', 'reset=1');
72 $this->type('title', $params['name']);
73 $this->click('_qf_Search_refresh');
74 $this->waitForElementPresent("xpath=//table[@id='crm-group-selector']/tbody/tr/td[contains(text(), '{$params['name']}')]");
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
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');
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 $name1 = trim($name[1]);
94 $name0 = trim($name[0]);
95 $displayName = isset($name1) ? "{$name1} {$name0}" : "{$name0}";
96 $this->assertElementContainsText("css=div.crm-summary-display_name", $displayName);
97 }
98
99 function testGroupReserved() {
100 $this->webtestLogin('admin');
101
102 $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload-bottom');
103
104 // take group name
105 $params = array('name' => 'group_' . substr(sha1(rand()), 0, 7));
106
107 // fill group name
108 $this->type("title", $params['name']);
109
110 // fill description
111 $this->type("description", "Adding new reserved group.");
112
113 // check Access Control
114 if (isset($params['type1']) && $params['type1'] !== FALSE) {
115 $this->click("group_type[1]");
116 }
117
118 // check Mailing List
119 if (isset($params['type2']) && $params['type2'] !== FALSE) {
120 $this->click("group_type[2]");
121 }
122
123 // select Visibility as Public Pages
124 if (empty($params['visibility'])) {
125 $params['visibility'] = 'Public Pages';
126 }
127
128 $this->select("visibility", "value={$params['visibility']}");
129
130 // Check Reserved box
131 $this->click("is_reserved");
132
133 // Clicking save.
134 $this->click("_qf_Edit_upload");
135 $this->waitForPageToLoad($this->getTimeoutMsec());
136
137 // Is status message correct?
138 $this->assertTrue($this->isTextPresent("The Group '{$params['name']}' has been saved."));
139
140 // Create a new role w/o reserved group permissions
141 $role = 'role' . substr(sha1(rand()), 0, 7);
142 $this->open($this->sboxPath . "admin/people/permissions/roles");
143
144 $this->waitForElementPresent("edit-add");
145 $this->type("edit-name", $role);
146 $this->click("edit-add");
147 $this->waitForPageToLoad($this->getTimeoutMsec());
148
149 $this->open($this->sboxPath . "admin/people/permissions/roles");
150 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']");
151 $roleId = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']/../td[4]/a[text()='edit permissions']/@href"));
152 $roleId = end($roleId);
153 $user = $this->_testCreateUser($roleId);
154 $permissions = array(
155 "edit-{$roleId}-view-all-contacts",
156 "edit-{$roleId}-access-civicrm",
157 );
158 $this->changePermissions($permissions);
159
160 // Now logout as admin, login as regular user and verify that Group settings,
161 // delete and disable links are not available
162 $this->webtestLogin($user, 'Test12345');
163
164 $this->openCiviPage('group', 'reset=1');
165 $this->type('title', $params['name']);
166 $this->click('_qf_Search_refresh');
167 $this->waitForTextPresent("Adding new reserved group.");
168 // Settings link should NOT be included in selector
169 // after search returns with only the reserved group.
170 $this->assertElementNotContainsText("css=td.crm-group-group_links", "Settings");
171
172 //login as admin and delete the role
173 $this->webtestLogin('admin');
174 $this->open($this->sboxPath . "admin/people/permissions/roles");
175 $this->_roleDelete($role);
176 }
177
178 function _testCreateUser($roleid) {
179 $this->open($this->sboxPath . "admin/people/create");
180
181 $this->waitForElementPresent("edit-submit");
182
183 $name = "TestUser" . substr(sha1(rand()), 0, 4);
184 $this->type("edit-name", $name);
185
186 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
187 $this->type("edit-mail", $emailId);
188 $this->type("edit-pass-pass1", "Test12345");
189 $this->type("edit-pass-pass2", "Test12345");
190 $role = "edit-roles-" . $roleid;
191 $this->check("name=roles[$roleid] value={$roleid}");
192
193 //Add profile Details
194 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
195 $lastName = 'An' . substr(sha1(rand()), 0, 7);
196
197 $this->type("first_name", $firstName);
198 $this->type("last_name", $lastName);
199
200 //Address Details
201 $this->type("street_address-1", "902C El Camino Way SW");
202 $this->type("city-1", "Dumfries");
203 $this->type("postal_code-1", "1234");
204 $this->select("state_province-1", "value=1019");
205
206 $this->click("edit-submit");
207 $this->waitForPageToLoad($this->getTimeoutMsec());
208 return $name;
209 }
210
211 function _roleDelete($role) {
212 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']");
213 $this->click("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']");
214 $this->waitForElementPresent('edit-delete');
215 $this->click('edit-delete');
216 $this->waitForPageToLoad($this->getTimeoutMsec());
217 $this->click("edit-submit");
218 $this->waitForTextPresent("The role has been deleted.");
219 }
220 }