| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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 'WebTest/Export/ExportCiviSeleniumTestCase.php'; |
| 28 | |
| 29 | /** |
| 30 | * Class WebTest_Export_ContactTest |
| 31 | */ |
| 32 | class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testPrefixGenderSuffix() { |
| 39 | $this->markTestSkipped('Skipping for now as it works fine locally.'); |
| 40 | $this->webtestLogin(); |
| 41 | |
| 42 | // Create new group |
| 43 | $parentGroupName = 'TestSuffixPrefixGender_' . substr(sha1(rand()), 0, 7); |
| 44 | $this->WebtestAddGroup($parentGroupName); |
| 45 | |
| 46 | // Adding Parent group contact |
| 47 | // We're using Quick Add block on the main page for this. |
| 48 | $firstContactName = 'TestExport' . substr(sha1(rand()), 0, 7); |
| 49 | |
| 50 | list($emailContactFirst, $prefixLabelContactFrst, $suffixLabelContactFrst, $genderLabelContactFrst) = WebTest_Export_ContactTest::webtestAddContactWithGenderPrefixSuffix($firstContactName, "Smith", "$firstContactName.smith@example.org", NULL); |
| 51 | |
| 52 | $sortFirstName = "Smith, $firstContactName"; |
| 53 | $displayFirstName = "$firstContactName Smith"; |
| 54 | |
| 55 | // Add contact to parent group |
| 56 | // visit group tab. |
| 57 | $this->click("css=li#tab_group a"); |
| 58 | $this->waitForElementPresent("group_id"); |
| 59 | |
| 60 | // Add to group. |
| 61 | $this->select("group_id", "label=$parentGroupName"); |
| 62 | $this->click("_qf_GroupContact_next"); |
| 63 | $this->waitForAjaxContent(); |
| 64 | |
| 65 | $secondContactName = 'TestExport2' . substr(sha1(rand()), 0, 7); |
| 66 | list($emailContactSecond, $prefixLabelContactScnd, $suffixLabelContactScnd, $genderLabelContactScnd) = WebTest_Export_ContactTest::webtestAddContactWithGenderPrefixSuffix($secondContactName, "John", "$secondContactName.john@example.org", NULL); |
| 67 | |
| 68 | $sortSecondName = "John, $secondContactName"; |
| 69 | $displaySecondName = "$secondContactName John"; |
| 70 | |
| 71 | // Add contact to parent group |
| 72 | // visit group tab. |
| 73 | $this->click("css=li#tab_group a"); |
| 74 | $this->waitForElementPresent("group_id"); |
| 75 | |
| 76 | // Add to group. |
| 77 | $this->select("group_id", "label=$parentGroupName"); |
| 78 | $this->click("_qf_GroupContact_next"); |
| 79 | $this->waitForAjaxContent(); |
| 80 | |
| 81 | $this->openCiviPage("contact/search", "reset=1"); |
| 82 | |
| 83 | // Select contact type as Indiividual. |
| 84 | $this->select("contact_type", "value=Individual"); |
| 85 | |
| 86 | // Select group. |
| 87 | $this->select("group", "label=$parentGroupName"); |
| 88 | |
| 89 | // Click to search. |
| 90 | $this->clickLink("_qf_Basic_refresh"); |
| 91 | |
| 92 | // Is contact present in search result? |
| 93 | $this->assertElementContainsText('css=div.crm-search-results', $sortFirstName, "Contact did not found in search result!"); |
| 94 | |
| 95 | // Is contact present in search result? |
| 96 | $this->assertElementContainsText('css=div.crm-search-results', $sortSecondName, "Contact did not found in search result!"); |
| 97 | |
| 98 | // select to export all the contasct from search result. |
| 99 | $this->click("CIVICRM_QFID_ts_all_4"); |
| 100 | |
| 101 | // Select the task action to export. |
| 102 | $this->click("task"); |
| 103 | $this->select("task", "label=Export Contacts"); |
| 104 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 105 | |
| 106 | $csvFile = $this->downloadCSV("_qf_Select_next-bottom"); |
| 107 | |
| 108 | // Build header row for assertion. |
| 109 | require_once 'CRM/Contact/BAO/Contact.php'; |
| 110 | $expotableFields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); |
| 111 | |
| 112 | $checkHeaders = array(); |
| 113 | foreach ($expotableFields as $key => $field) { |
| 114 | // Exclude custom fields. |
| 115 | if ($key && (substr($key, 0, 6) == 'custom')) { |
| 116 | continue; |
| 117 | } |
| 118 | $checkHeaders[] = $field['title']; |
| 119 | } |
| 120 | |
| 121 | // All other rows to be check. |
| 122 | $checkRows = array( |
| 123 | 1 => array( |
| 124 | 'First Name' => $secondContactName, |
| 125 | 'Last Name' => 'John', |
| 126 | 'Email' => '' . strtolower($emailContactSecond) . '', |
| 127 | 'Individual Suffix' => $suffixLabelContactScnd, |
| 128 | 'Gender' => $genderLabelContactScnd, |
| 129 | ), |
| 130 | 2 => array( |
| 131 | 'First Name' => $firstContactName, |
| 132 | 'Last Name' => 'Smith', |
| 133 | 'Email' => '' . strtolower($emailContactFirst) . '', |
| 134 | 'Sort Name' => $sortFirstName, |
| 135 | 'Display Name' => $prefixLabelContactFrst . ' ' . $displayFirstName . ' ' . $suffixLabelContactFrst, |
| 136 | 'Individual Prefix' => $prefixLabelContactFrst, |
| 137 | 'Individual Suffix' => $suffixLabelContactFrst, |
| 138 | 'Gender' => $genderLabelContactFrst, |
| 139 | ), |
| 140 | ); |
| 141 | |
| 142 | // Read CSV and fire assertions. |
| 143 | $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Test Contact Export. |
| 148 | */ |
| 149 | public function testContactExport() { |
| 150 | $this->markTestSkipped('Skipping for now as it works fine locally.'); |
| 151 | $this->webtestLogin(); |
| 152 | |
| 153 | // Create new group |
| 154 | $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7); |
| 155 | $this->WebtestAddGroup($parentGroupName); |
| 156 | |
| 157 | // Create new group and select the previously selected group as parent group for this new group. |
| 158 | $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7); |
| 159 | $this->WebtestAddGroup($childGroupName, $parentGroupName); |
| 160 | |
| 161 | // Adding Parent group contact |
| 162 | // We're using Quick Add block on the main page for this. |
| 163 | $firstName = 'a' . substr(sha1(rand()), 0, 7); |
| 164 | $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org"); |
| 165 | |
| 166 | $sortName = "Smith, $firstName"; |
| 167 | $displayName = "$firstName Smith"; |
| 168 | |
| 169 | // Add contact to parent group |
| 170 | // visit group tab. |
| 171 | $this->click("css=li#tab_group a"); |
| 172 | $this->waitForElementPresent("group_id"); |
| 173 | |
| 174 | // Add to group. |
| 175 | $this->select("group_id", "label=$parentGroupName"); |
| 176 | $this->click("_qf_GroupContact_next"); |
| 177 | $this->waitForAjaxContent(); |
| 178 | |
| 179 | // Adding child group contact |
| 180 | // We're using Quick Add block on the main page for this. |
| 181 | $childName = 'b' . substr(sha1(rand()), 0, 7); |
| 182 | $this->webtestAddContact($childName, "John", "$childName.john@example.org"); |
| 183 | |
| 184 | $childSortName = "John, $childName"; |
| 185 | $childDisplayName = "$childName John"; |
| 186 | |
| 187 | // Add contact to child group |
| 188 | // visit group tab. |
| 189 | $this->click("css=li#tab_group a"); |
| 190 | $this->waitForElementPresent("group_id"); |
| 191 | |
| 192 | // Add to child group. |
| 193 | $this->select("group_id", "label=regexp:$childGroupName"); |
| 194 | $this->click("_qf_GroupContact_next"); |
| 195 | $this->waitForAjaxContent(); |
| 196 | |
| 197 | // Visit contact search page. |
| 198 | $this->openCiviPage("contact/search", "reset=1"); |
| 199 | |
| 200 | // Select contact type as Indiividual. |
| 201 | $this->select("contact_type", "value=Individual"); |
| 202 | |
| 203 | // Select group. |
| 204 | $this->select("group", "label=$parentGroupName"); |
| 205 | |
| 206 | // Click to search. |
| 207 | $this->clickLink("_qf_Basic_refresh"); |
| 208 | |
| 209 | // Is contact present in search result? |
| 210 | $this->assertElementContainsText('css=div.crm-search-results', $sortName, "Contact did not found in search result!"); |
| 211 | |
| 212 | // Is contact present in search result? |
| 213 | $this->assertElementContainsText('css=div.crm-search-results', $childSortName, "Contact did not found in search result!"); |
| 214 | |
| 215 | // select to export all the contasct from search result. |
| 216 | $this->click("CIVICRM_QFID_ts_all_4"); |
| 217 | |
| 218 | // Select the task action to export. |
| 219 | $this->click("task"); |
| 220 | $this->select("task", "label=Export Contacts"); |
| 221 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 222 | |
| 223 | $csvFile = $this->downloadCSV("_qf_Select_next-bottom"); |
| 224 | |
| 225 | // Build header row for assertion. |
| 226 | require_once 'CRM/Contact/BAO/Contact.php'; |
| 227 | $expotableFields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); |
| 228 | |
| 229 | $checkHeaders = array(); |
| 230 | foreach ($expotableFields as $key => $field) { |
| 231 | // Exclude custom fields. |
| 232 | if ($key && (substr($key, 0, 6) == 'custom')) { |
| 233 | continue; |
| 234 | } |
| 235 | $checkHeaders[] = $field['title']; |
| 236 | } |
| 237 | |
| 238 | // All other rows to be check. |
| 239 | $checkRows = array( |
| 240 | 1 => array( |
| 241 | 'First Name' => $childName, |
| 242 | 'Last Name' => 'John', |
| 243 | 'Email' => "$childName.john@example.org", |
| 244 | 'Sort Name' => $childSortName, |
| 245 | 'Display Name' => $childDisplayName, |
| 246 | ), |
| 247 | 2 => array( |
| 248 | 'First Name' => $firstName, |
| 249 | 'Last Name' => 'Smith', |
| 250 | 'Email' => "$firstName.smith@example.org", |
| 251 | 'Sort Name' => $sortName, |
| 252 | 'Display Name' => $displayName, |
| 253 | ), |
| 254 | ); |
| 255 | |
| 256 | // Read CSV and fire assertions. |
| 257 | $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2); |
| 258 | } |
| 259 | |
| 260 | public function testMergeHousehold() { |
| 261 | $this->markTestSkipped('Skipping for now as it works fine locally.'); |
| 262 | $this->webtestLogin(); |
| 263 | |
| 264 | // Create new group |
| 265 | $groupName = 'TestGroup_' . substr(sha1(rand()), 0, 7); |
| 266 | $this->WebtestAddGroup($groupName); |
| 267 | |
| 268 | // Adding Parent group contact |
| 269 | // We're using Quick Add block on the main page for this. |
| 270 | $houseHold = 'H' . substr(sha1(rand()), 0, 5) . ' House'; |
| 271 | |
| 272 | $this->openCiviPage("contact/add", "reset=1&ct=Household"); |
| 273 | $this->click('household_name'); |
| 274 | $this->type('household_name', $houseHold); |
| 275 | |
| 276 | //address section |
| 277 | $this->click("addressBlock"); |
| 278 | $this->waitForElementPresent("address_1_street_address"); |
| 279 | |
| 280 | // fill in address |
| 281 | $this->click("//div[@id='addressBlockId']/div[1]"); |
| 282 | $this->type("address_1_street_address", "121A Sherman St. Apt. 12"); |
| 283 | $this->type("address_1_city", "Dumfries"); |
| 284 | $this->type("address_1_postal_code", "1234"); |
| 285 | $this->select("address_1_country_id", "UNITED STATES"); |
| 286 | $this->select("address_1_state_province_id", "value=1019"); |
| 287 | |
| 288 | $this->click('_qf_Contact_upload_view'); |
| 289 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 290 | |
| 291 | // Add contact to group |
| 292 | // visit group tab. |
| 293 | $this->click("css=li#tab_group a"); |
| 294 | $this->waitForElementPresent("group_id"); |
| 295 | |
| 296 | // Add to group. |
| 297 | $this->select("group_id", "label=$groupName"); |
| 298 | $this->click("_qf_GroupContact_next"); |
| 299 | $this->waitForAjaxContent(); |
| 300 | |
| 301 | $firstName1 = 'aa' . substr(sha1(rand()), 0, 5); |
| 302 | $this->webtestAddContact($firstName1, "Smith", "{$firstName1}.smith@example.org"); |
| 303 | |
| 304 | $sortName1 = "Smith, {$firstName1}"; |
| 305 | $displayName1 = "{$firstName1} Smith"; |
| 306 | |
| 307 | // Add contact to parent group |
| 308 | // visit group tab. |
| 309 | $this->click("css=li#tab_group a"); |
| 310 | $this->waitForElementPresent("group_id"); |
| 311 | |
| 312 | // Add to group. |
| 313 | $this->select("group_id", "label=$groupName"); |
| 314 | $this->click("_qf_GroupContact_next"); |
| 315 | $this->waitForAjaxContent(); |
| 316 | |
| 317 | $firstName2 = 'bb' . substr(sha1(rand()), 0, 5); |
| 318 | |
| 319 | $this->openCiviPage("contact/add", "reset=1&ct=Individual", "_qf_Contact_upload_view-bottom"); |
| 320 | $this->type('first_name', $firstName2); |
| 321 | $this->type('last_name', "Smith"); |
| 322 | $this->type('email_1_email', "{$firstName2}.smith@example.org"); |
| 323 | |
| 324 | //address section |
| 325 | $this->click("addressBlock"); |
| 326 | $this->waitForElementPresent("address_1_street_address"); |
| 327 | |
| 328 | $this->click("//div[@id='addressBlockId']/div[1]"); |
| 329 | |
| 330 | $this->click("address[1][use_shared_address]"); |
| 331 | $this->waitForElementPresent("address_1_master_contact_id"); |
| 332 | $this->select2('address_1_master_contact_id', $houseHold); |
| 333 | $this->waitForTextPresent("121A Sherman"); |
| 334 | |
| 335 | $this->click('_qf_Contact_upload_view-bottom'); |
| 336 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 337 | |
| 338 | $sortName2 = "Smith, {$firstName2}"; |
| 339 | $displayName2 = "{$firstName2} Smith"; |
| 340 | |
| 341 | // Add contact to parent group |
| 342 | // visit group tab. |
| 343 | $this->click("css=li#tab_group a"); |
| 344 | $this->waitForElementPresent("group_id"); |
| 345 | |
| 346 | // Add to group. |
| 347 | $this->select("group_id", "label=$groupName"); |
| 348 | $this->click("_qf_GroupContact_next"); |
| 349 | $this->waitForAjaxContent(); |
| 350 | |
| 351 | $this->openCiviPage("contact/search", "reset=1", NULL); |
| 352 | |
| 353 | // Select group. |
| 354 | $this->select("group", "label=$groupName"); |
| 355 | |
| 356 | // Click to search. |
| 357 | $this->clickLink("_qf_Basic_refresh"); |
| 358 | |
| 359 | // Is contact present in search result? |
| 360 | $this->assertElementContainsText('css=div.crm-search-results', $sortName1, "Contact did not found in search result!"); |
| 361 | |
| 362 | // Is contact present in search result? |
| 363 | $this->assertElementContainsText('css=div.crm-search-results', $sortName2, "Contact did not found in search result!"); |
| 364 | |
| 365 | // Is contact present in search result? |
| 366 | $this->assertElementContainsText('css=div.crm-search-results', $houseHold, "Contact did not found in search result!"); |
| 367 | |
| 368 | // select to export all the contasct from search result. |
| 369 | $this->click("CIVICRM_QFID_ts_all_4"); |
| 370 | |
| 371 | // Select the task action to export. |
| 372 | $this->click("task"); |
| 373 | $this->select("task", "label=Export Contacts"); |
| 374 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 375 | |
| 376 | $this->click("CIVICRM_QFID_2_10"); |
| 377 | |
| 378 | $csvFile = $this->downloadCSV("_qf_Select_next-bottom"); |
| 379 | |
| 380 | // Build header row for assertion. |
| 381 | require_once 'CRM/Contact/BAO/Contact.php'; |
| 382 | $expotableFields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); |
| 383 | |
| 384 | $checkHeaders = array(); |
| 385 | foreach ($expotableFields as $key => $field) { |
| 386 | // Exclude custom fields. |
| 387 | if ($key && (substr($key, 0, 6) == 'custom')) { |
| 388 | continue; |
| 389 | } |
| 390 | $checkHeaders[] = $field['title']; |
| 391 | } |
| 392 | |
| 393 | // All other rows to be check. |
| 394 | $checkRows = array( |
| 395 | 1 => array( |
| 396 | 'Contact Type' => 'Household', |
| 397 | 'Household Name' => $houseHold, |
| 398 | ), |
| 399 | 2 => array( |
| 400 | 'Contact Type' => 'Individual', |
| 401 | 'First Name' => $firstName1, |
| 402 | 'Email' => "{$firstName1}.smith@example.org", |
| 403 | 'Sort Name' => $sortName1, |
| 404 | 'Display Name' => $displayName1, |
| 405 | ), |
| 406 | ); |
| 407 | |
| 408 | // Read CSV and fire assertions. |
| 409 | $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2); |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * @param string $fname |
| 414 | * @param string $lname |
| 415 | * @param null $email |
| 416 | * @param null $contactSubtype |
| 417 | * |
| 418 | * @return array |
| 419 | */ |
| 420 | public function webtestAddContactWithGenderPrefixSuffix($fname = 'Anthony', $lname = 'Anderson', $email = NULL, $contactSubtype = NULL) { |
| 421 | $url = $this->sboxPath . 'civicrm/contact/add?reset=1&ct=Individual'; |
| 422 | if ($contactSubtype) { |
| 423 | $url = $url . "&cst={$contactSubtype}"; |
| 424 | } |
| 425 | $this->open($url); |
| 426 | $this->waitForElementPresent('_qf_Contact_upload_view-bottom'); |
| 427 | |
| 428 | $this->type('first_name', $fname); |
| 429 | $this->type('last_name', $lname); |
| 430 | if ($email === TRUE) { |
| 431 | $email = substr(sha1(rand()), 0, 7) . '@example.org'; |
| 432 | } |
| 433 | if ($email) { |
| 434 | $this->type('email_1_email', $email); |
| 435 | } |
| 436 | $genderLabelArray = array( |
| 437 | 1 => 'Female', |
| 438 | 2 => 'Male', |
| 439 | 3 => 'Transgender', |
| 440 | ); |
| 441 | $prefix = rand(1, 4); |
| 442 | $suffix = rand(1, 8); |
| 443 | $gender = rand(1, 3); |
| 444 | $genderLabel = "civicrm_gender_" . $genderLabelArray[$gender] . "_$gender"; |
| 445 | $this->select("prefix_id", "value=$prefix"); |
| 446 | $this->select("suffix_id", "value=$suffix"); |
| 447 | $this->click("demographics"); |
| 448 | $this->waitForElementPresent("civicrm_gender_Female_1"); |
| 449 | $this->click($genderLabel, "value=$gender"); |
| 450 | $this->waitForElementPresent('_qf_Contact_upload_view-bottom'); |
| 451 | $this->click('_qf_Contact_upload_view-bottom'); |
| 452 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 453 | $prefixLabel = WebTest_Export_ContactTest::getOptionLabel('individual_prefix', $prefix); |
| 454 | $suffixLabel = WebTest_Export_ContactTest::getOptionLabel('individual_suffix', $suffix); |
| 455 | $genderLabel = WebTest_Export_ContactTest::getOptionLabel('gender', $gender); |
| 456 | return array($email, $prefixLabel, $suffixLabel, $genderLabel); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * @param string $optionGroupName |
| 461 | * @param $optionValue |
| 462 | * |
| 463 | * @return array|int |
| 464 | */ |
| 465 | public function getOptionLabel($optionGroupName, $optionValue) { |
| 466 | $params = array( |
| 467 | 'version' => 3, |
| 468 | 'sequential' => 1, |
| 469 | 'option_group_name' => $optionGroupName, |
| 470 | 'value' => $optionValue, |
| 471 | 'return' => 'label', |
| 472 | ); |
| 473 | $optionLabel = $this->webtest_civicrm_api("OptionValue", "getvalue", $params); |
| 474 | return $optionLabel; |
| 475 | } |
| 476 | |
| 477 | } |