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