3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contact_GroupAddTest
extends CiviSeleniumTestCase
{
31 protected function setUp() {
35 function testGroupAdd() {
36 $this->webtestLogin();
38 $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload-bottom');
41 $params = array('name' => 'group_' . substr(sha1(rand()), 0, 7));
44 $this->type("title", $params['name']);
47 $this->type("description", "Adding new group.");
49 // check Access Control
50 if (isset($params['type1']) && $params['type1'] !== FALSE) {
51 $this->click("group_type[1]");
55 if (isset($params['type2']) && $params['type2'] !== FALSE) {
56 $this->click("group_type[2]");
59 // select Visibility as Public Pages
60 $params['visibility'] = 'Public Pages';
62 $this->select("visibility", "value={$params['visibility']}");
65 $this->click("_qf_Edit_upload");
66 $this->waitForPageToLoad($this->getTimeoutMsec());
68 // Is status message correct?
69 $this->assertElementContainsText('crm-notification-container', "The Group '{$params['name']}' has been saved.");
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[3]/a");
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");
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');
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}']"));
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 $displayName = isset($name[1]) ?
"{$name[1]} {$name[0]}" : "{$name[0]}";
94 $this->assertElementContainsText("css=div.crm-summary-display_name",$displayName);
97 function testGroupReserved() {
98 $this->webtestLogin(true);
100 $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload-bottom');
103 $params = array('name' => 'group_' . substr(sha1(rand()), 0, 7));
106 $this->type("title", $params['name']);
109 $this->type("description", "Adding new reserved group.");
111 // check Access Control
112 if (isset($params['type1']) && $params['type1'] !== FALSE) {
113 $this->click("group_type[1]");
116 // check Mailing List
117 if (isset($params['type2']) && $params['type2'] !== FALSE) {
118 $this->click("group_type[2]");
121 // select Visibility as Public Pages
122 if (empty($params['visibility'])) {
123 $params['visibility'] = 'Public Pages';
126 $this->select("visibility", "value={$params['visibility']}");
128 // Check Reserved box
129 $this->click("is_reserved");
132 $this->click("_qf_Edit_upload");
133 $this->waitForPageToLoad($this->getTimeoutMsec());
135 // Is status message correct?
136 $this->assertTrue($this->isTextPresent("The Group '{$params['name']}' has been saved."));
138 // Create a new role w/o reserved group permissions
139 $role = 'role' . substr(sha1(rand()), 0, 7);
140 $this->open($this->sboxPath
. "admin/people/permissions/roles");
142 $this->waitForElementPresent("edit-add");
143 $this->type("edit-name", $role);
144 $this->click("edit-add");
145 $this->waitForPageToLoad($this->getTimeoutMsec());
147 $this->open($this->sboxPath
. "admin/people/permissions/roles");
148 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']");
149 $roleId = explode('/', $this->getAttribute("xpath=//table[@id='user-roles']/tbody//tr/td[1][text()='{$role}']/../td[4]/a[text()='edit permissions']/@href"));
150 $roleId = end($roleId);
151 $user = $this->_testCreateUser($roleId);
152 $permissions = array(
153 "edit-{$roleId}-view-all-contacts",
154 "edit-{$roleId}-access-civicrm",
156 $this->changePermissions($permissions);
158 // Now logout as admin, login as regular user and verify that Group settings, delete and disable links are not available
159 $this->openCiviPage('logout', 'reset=1', NULL);
160 $this->open($this->sboxPath
);
161 $this->waitForElementPresent('edit-submit');
162 $this->type('edit-name', $user);
163 $this->type('edit-pass', 'Test12345');
164 $this->click('edit-submit');
165 $this->waitForPageToLoad($this->getTimeoutMsec());
167 $this->openCiviPage('group', 'reset=1');
168 $this->type('title', $params['name']);
169 $this->click('_qf_Search_refresh');
170 $this->waitForTextPresent("Adding new reserved group.");
171 // Settings link should NOT be included in selector after search returns with only the reserved group.
172 $this->assertElementNotContainsText("css=td.crm-group-group_links", "Settings");
174 //login as admin and delete the role
175 $this->openCiviPage('logout', 'reset=1', NULL);
176 $this->open($this->sboxPath
);
177 $this->webtestLogin(TRUE);
178 $this->open($this->sboxPath
. "admin/people/permissions/roles");
179 $this->_roleDelete($role);
183 function _testCreateUser($roleid) {
184 // Go directly to the URL of the screen that will Create User Authentically.
185 $this->open($this->sboxPath
. "admin/people/create");
187 $this->waitForElementPresent("edit-submit");
189 $name = "TestUser" . substr(sha1(rand()), 0, 4);
190 $this->type("edit-name", $name);
192 $emailId = substr(sha1(rand()), 0, 7) . '@web.com';
193 $this->type("edit-mail", $emailId);
194 $this->type("edit-pass-pass1", "Test12345");
195 $this->type("edit-pass-pass2", "Test12345");
196 $role = "edit-roles-" . $roleid;
197 $this->check("name=roles[$roleid] value={$roleid}");
199 //Add profile Details
200 $firstName = 'Ma' . substr(sha1(rand()), 0, 4);
201 $lastName = 'An' . substr(sha1(rand()), 0, 7);
203 $this->type("first_name", $firstName);
204 $this->type("last_name", $lastName);
207 $this->type("street_address-1", "902C El Camino Way SW");
208 $this->type("city-1", "Dumfries");
209 $this->type("postal_code-1", "1234");
210 $this->select("state_province-1", "value=1019");
212 $this->click("edit-submit");
213 $this->waitForPageToLoad($this->getTimeoutMsec());
217 function _roleDelete($role) {
218 $this->waitForElementPresent("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']");
219 $this->click("xpath=//table[@id='user-roles']/tbody//tr/td[text()='{$role}']/..//td/a[text()='edit role']");
220 $this->waitForElementPresent('edit-delete');
221 $this->click('edit-delete');
222 $this->waitForPageToLoad($this->getTimeoutMsec());
223 $this->click("edit-submit");
224 $this->waitForTextPresent("The role has been deleted.");