| 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 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
| 28 | class WebTest_Profile_ProfileAddTest extends CiviSeleniumTestCase { |
| 29 | |
| 30 | protected function setUp() { |
| 31 | parent::setUp(); |
| 32 | } |
| 33 | |
| 34 | function testAddNewProfile() { |
| 35 | $this->webtestLogin(); |
| 36 | |
| 37 | // Add new profile. |
| 38 | $this->openCiviPage('admin/uf/group', 'reset=1'); |
| 39 | |
| 40 | $this->click('newCiviCRMProfile-top'); |
| 41 | |
| 42 | $this->waitForElementPresent('_qf_Group_next-bottom'); |
| 43 | |
| 44 | //Name of profile |
| 45 | $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7); |
| 46 | $this->type('title', $profileTitle); |
| 47 | |
| 48 | //profile Used for |
| 49 | $this->click('uf_group_type_User Registration'); |
| 50 | $this->click('uf_group_type_User Account'); |
| 51 | |
| 52 | //Profile Advance Settings |
| 53 | $this->click("//form[@id='Group']/div[2]/div[2]/div[1]"); |
| 54 | |
| 55 | //Select a group if you are using this profile for search and listings. |
| 56 | $this->select('group', 'value=1'); |
| 57 | |
| 58 | //Select a group if you are using this profile for adding new contacts. |
| 59 | $this->select('add_contact_to_group', 'value=1'); |
| 60 | |
| 61 | //If you want member(s) of your organization to receive a |
| 62 | //notification email whenever this Profile |
| 63 | //form is used to enter or update contact information, enter one or more email addresses here. |
| 64 | $this->type('notify', 'This is notify email'); |
| 65 | |
| 66 | //If you are using this profile as a contact signup or edit |
| 67 | //form, and want to redirec the user to a static URL after |
| 68 | //they've submitted the form - enter the complete URL here. |
| 69 | $this->type('post_URL', 'This is Post Url'); |
| 70 | |
| 71 | // If you are using this profile as a contact signup or edit |
| 72 | // form, and want to redirect the user to a |
| 73 | //static URL if they click the Cancel button - enter the complete URL here. |
| 74 | $this->type('cancel_URL', 'This is cancle Url'); |
| 75 | |
| 76 | //reCaptcha settings |
| 77 | $this->click('add_captcha'); |
| 78 | |
| 79 | //Drupal user account registration option |
| 80 | $this->click('CIVICRM_QFID_0_8'); |
| 81 | |
| 82 | //What to do upon duplicate match |
| 83 | $this->click('CIVICRM_QFID_0_2'); |
| 84 | |
| 85 | //Proximity search options |
| 86 | $this->click('CIVICRM_QFID_0_14'); |
| 87 | |
| 88 | // enable maping for contact |
| 89 | $this->click('is_map'); |
| 90 | |
| 91 | // include a link in the listings to Edit profile fields |
| 92 | $this->click('is_edit_link'); |
| 93 | |
| 94 | //to view contacts' Drupal user account information |
| 95 | $this->click('is_uf_link'); |
| 96 | |
| 97 | //click on save |
| 98 | $this->click('_qf_Group_next'); |
| 99 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 100 | |
| 101 | //check for profile create |
| 102 | $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."); |
| 103 | |
| 104 | //Add field to profile |
| 105 | $this->click('field_name[0]'); |
| 106 | $this->select('field_name[0]', 'value=Contact'); |
| 107 | $this->click("//option[@value='Contact']"); |
| 108 | $this->click('is_required'); |
| 109 | $this->type('help_post', 'This is help for profile field'); |
| 110 | |
| 111 | //click on save |
| 112 | $this->click('_qf_Field_next'); |
| 113 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 114 | |
| 115 | // delete the profile |
| 116 | $this->openCiviPage('admin/uf/group', 'reset=1'); |
| 117 | $this->_testdeleteProfile($profileTitle); |
| 118 | } |
| 119 | |
| 120 | function testProfileAddContactstoGroup() { |
| 121 | $this->webtestLogin(); |
| 122 | |
| 123 | // take group name and create group |
| 124 | $groupName = 'group_' . substr(sha1(rand()), 0, 7); |
| 125 | $this->WebtestAddGroup($groupName); |
| 126 | |
| 127 | // Add new profile. |
| 128 | $this->openCiviPage('admin/uf/group', 'reset=1'); |
| 129 | |
| 130 | $this->click('newCiviCRMProfile-top'); |
| 131 | |
| 132 | $this->waitForElementPresent('_qf_Group_next-bottom'); |
| 133 | |
| 134 | //Name of profile |
| 135 | $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7); |
| 136 | $this->type('title', $profileTitle); |
| 137 | |
| 138 | //Profile Advance Settings |
| 139 | $this->click("//form[@id='Group']/div[2]/div[2]/div[1]"); |
| 140 | |
| 141 | //Select the newly created group for adding new contacts into it. |
| 142 | $this->select('add_contact_to_group', "label=$groupName"); |
| 143 | |
| 144 | //click on save |
| 145 | $this->clickLink('_qf_Group_next'); |
| 146 | |
| 147 | //check for profile create |
| 148 | $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now."); |
| 149 | |
| 150 | //Add fields to profile |
| 151 | $fields = array( |
| 152 | 'first_name' => 'Individual', |
| 153 | 'last_name' => 'Individual', |
| 154 | 'email' => 'Contact' |
| 155 | ); |
| 156 | foreach ($fields as $field => $type) { |
| 157 | $this->click('field_name_0'); |
| 158 | $this->select('field_name_0', "value=$type"); |
| 159 | $this->click("//option[@value='$type']"); |
| 160 | $this->click('field_name_1'); |
| 161 | $this->select('field_name_1', "value=$field"); |
| 162 | $this->clickLink('_qf_Field_next_new-top'); |
| 163 | } |
| 164 | |
| 165 | // create mode |
| 166 | $gid = $this->urlArg('gid'); |
| 167 | $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL); |
| 168 | $firstName1 = "John_" . substr(sha1(rand()), 0, 7); |
| 169 | $lastName1 = "Smiths_x" . substr(sha1(rand()), 0, 7); |
| 170 | $this->type('first_name', $firstName1); |
| 171 | $this->type('last_name', $lastName1); |
| 172 | $this->type('email-Primary', "$firstName1.$lastName1@example.com"); |
| 173 | $this->clickLink('_qf_Edit_next', NULL); |
| 174 | |
| 175 | //anonymous contact |
| 176 | $this->webtestLogout(); |
| 177 | $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL); |
| 178 | $firstName2 = "John12_" . substr(sha1(rand()), 0, 7); |
| 179 | $lastName2 = "Smiths34_x" . substr(sha1(rand()), 0, 7); |
| 180 | $this->type('first_name', $firstName2); |
| 181 | $this->type('last_name', $lastName2); |
| 182 | $this->type('email-Primary', "$firstName2.$lastName2@example.com"); |
| 183 | $this->clickLink('_qf_Edit_next', NULL); |
| 184 | |
| 185 | $this->webtestLogin(); |
| 186 | //check the existence of the two contacts in the group |
| 187 | $this->openCiviPage('group', 'reset=1'); |
| 188 | $this->type('title', $groupName); |
| 189 | $this->click('_qf_Search_refresh'); |
| 190 | $this->waitForVisible('crm-group-selector_processing'); |
| 191 | $this->waitForElementPresent("xpath=//table[@id='crm-group-selector']/tbody/tr/td[contains(text(), '$groupName')]/following-sibling::td[@class='crm-group-group_links']/span/a"); |
| 192 | $this->clickLink("xpath=//table[@id='crm-group-selector']/tbody/tr/td[1][text()= '$groupName']/following-sibling::td[@class='crm-group-group_links']/span/a"); |
| 193 | $contactEmails = array( |
| 194 | 1 => "$lastName1, $firstName1", |
| 195 | 2 => "$lastName2, $firstName2" |
| 196 | ); |
| 197 | foreach ($contactEmails as $row => $name) { |
| 198 | $this->assertTrue($this->isElementPresent("xpath=//div[@class='crm-search-results']/table/tbody/tr[$row]/td[4]/a[contains(text(), '$name')]")); |
| 199 | } |
| 200 | |
| 201 | //add the api keys in the recaptcha settings |
| 202 | $this->openCiviPage('admin/setting/misc', 'reset=1'); |
| 203 | $this->type('recaptchaPublicKey', '6Lcexd8SAAAAAOwcoLCRALkyRrmPX7jY7b4V5iju'); |
| 204 | $this->type('recaptchaPrivateKey', '6Lcexd8SAAAAANZXtyU5SVrnl9-_ckwFxUAZgxQp'); |
| 205 | $this->clickLink('_qf_Miscellaneous_next-bottom'); |
| 206 | |
| 207 | //enable recaptcha in the profile |
| 208 | $this->openCiviPage('admin/uf/group', 'reset=1'); |
| 209 | $this->clickLink("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text()= '$profileTitle']/../following-sibling::td[6]/span/a[2]"); |
| 210 | $this->click("//form[@id='Group']/div[2]/div[2]/div[1]"); |
| 211 | //reCaptcha settings |
| 212 | $this->click('add_captcha'); |
| 213 | $this->clickLink('_qf_Group_next-bottom'); |
| 214 | |
| 215 | //check if recaptcha loads for anonymous profile |
| 216 | $this->webtestLogout(); |
| 217 | $this->openCiviPage('profile/create', "gid=$gid&reset=1", NULL); |
| 218 | $this->waitForElementPresent('recaptcha_widget_div'); |
| 219 | $this->assertTrue($this->isElementPresent('recaptcha_area')); |
| 220 | |
| 221 | // delete the profile |
| 222 | $this->webtestLogin(); |
| 223 | $this->openCiviPage('admin/uf/group', 'reset=1'); |
| 224 | $this->_testdeleteProfile($profileTitle); |
| 225 | } |
| 226 | |
| 227 | function _testdeleteProfile($profileTitle) { |
| 228 | //$this->waitForPageToLoad($this->getTimeoutMsec()); |
| 229 | $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/span[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul/li[4]/a[text()='Delete']"); |
| 230 | $this->click("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/span[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul/li[4]/a[text()='Delete']"); |
| 231 | |
| 232 | $this->waitForElementPresent('_qf_Group_next-bottom'); |
| 233 | $this->click('_qf_Group_next-bottom'); |
| 234 | $this->waitForElementPresent('newCiviCRMProfile-bottom'); |
| 235 | $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted."); |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * CRM-12439 |
| 240 | * Test to check profile description field |
| 241 | * which has a rich text editor (CKEditor) |
| 242 | */ |
| 243 | function testCheckDescAndCreatedIdFields() { |
| 244 | // Log in using webtestLogin() method |
| 245 | $this->webtestLogin(); |
| 246 | |
| 247 | // open Add Profile page |
| 248 | $this->openCiviPage("admin/uf/group/add", "action=add&reset=1"); |
| 249 | |
| 250 | $this->waitForElementPresent('_qf_Group_next-bottom'); |
| 251 | $profileTitle = 'Test Profile' . substr(sha1(rand()), 0, 7); |
| 252 | $this->type('title', $profileTitle); |
| 253 | |
| 254 | // check if description field is present |
| 255 | $this->waitForElementPresent('description'); |
| 256 | |
| 257 | $profileDescription = "Test Profile description" . substr(sha1(rand()), 0, 7); |
| 258 | $this->type('description', $profileDescription); |
| 259 | $this->check('uf_group_type_Search Profile'); |
| 260 | |
| 261 | // click save button |
| 262 | $this->clickLink('_qf_Group_next-bottom'); |
| 263 | |
| 264 | // Wait for "saved" status msg |
| 265 | $this->waitForText('crm-notification-container', 'Profile Added'); |
| 266 | |
| 267 | $this->waitForElementPresent('_qf_Field_next-bottom'); |
| 268 | |
| 269 | // select field(s) to be added in profile |
| 270 | $this->select("field_name_0", "value=Contact"); |
| 271 | $this->select("field_name_1", "value=email"); |
| 272 | $this->select("field_name_2", "value=2"); |
| 273 | |
| 274 | // click on Save buttonProfile Field Saved |
| 275 | $this->clickLink('_qf_Field_next-bottom'); |
| 276 | |
| 277 | // Wait for "saved" status msg |
| 278 | $this->waitForText('crm-notification-container', "Profile Field Saved"); |
| 279 | |
| 280 | $this->waitForElementPresent("xpath=//div[@id='field_page']/div[4]/a[2]"); |
| 281 | $this->waitForElementPresent("xpath=//div[@id='field_page']/div[4]/a[4]"); |
| 282 | |
| 283 | $this->waitForElementPresent("xpath=//div[@id='field_page']/div[3]/table/tbody/tr[1]/td[9]/span/a[text()='Edit']"); |
| 284 | // extract profile Id |
| 285 | $id = explode("gid=", $this->getAttribute("xpath=//div[@id='field_page']/div[3]/table/tbody/tr/td[9]/span/a[text()='Edit']/@href")); |
| 286 | $id = $id[1]; |
| 287 | |
| 288 | // click on Edit Settings |
| 289 | $this->clickLink("xpath=//div[@id='field_page']/div[4]/a[2]", '_qf_Group_next-bottom'); |
| 290 | |
| 291 | // check for description field |
| 292 | $this->waitForElementPresent('description'); |
| 293 | // check value of description field is retrieved correctly |
| 294 | $this->assertEquals($this->getValue('description'), $profileDescription); |
| 295 | |
| 296 | // click on save button |
| 297 | $this->clickLink('_qf_Group_next-bottom'); |
| 298 | |
| 299 | // Wait for "saved" status msg |
| 300 | $this->waitForText('crm-notification-container', 'Profile Saved'); |
| 301 | |
| 302 | $this->waitForElementPresent("xpath=//div[@class='crm-submit-buttons']/a[@id='newCiviCRMProfile-bottom']"); |
| 303 | $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[2]/a"); |
| 304 | $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[3]"); |
| 305 | |
| 306 | // check description is displayed on profile listing page |
| 307 | $this->assertEquals($this->getText("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[3]"), $profileDescription); |
| 308 | // fetch created by |
| 309 | $createdBy = $this->getText("xpath=//div[@id='user-profiles']/div/div/table/tbody/tr[@id='UFGroup-$id']/td[2]/a"); |
| 310 | |
| 311 | // check if created by contact exists |
| 312 | $this->openCiviPage("dashboard", "reset=1"); |
| 313 | |
| 314 | // type sortname in autocomplete |
| 315 | $this->click("css=input#sort_name_navigation"); |
| 316 | $this->type("css=input#sort_name_navigation", $createdBy); |
| 317 | $this->typeKeys("css=input#sort_name_navigation", $createdBy); |
| 318 | |
| 319 | // wait for result list |
| 320 | $this->waitForElementPresent("css=div.ac_results-inner li"); |
| 321 | |
| 322 | // visit contact summary page |
| 323 | $this->clickLink("css=div.ac_results-inner li"); |
| 324 | |
| 325 | // Is contact present? |
| 326 | $this->assertTrue($this->isTextPresent("$createdBy"), "Contact did not find!"); |
| 327 | |
| 328 | $this->openCiviPage('admin/uf/group', 'reset=1'); |
| 329 | // delete created profile |
| 330 | $this->_testdeleteProfile($profileTitle); |
| 331 | } |
| 332 | } |