remove duplicate assignments
[civicrm-core.git] / tests / phpunit / WebTest / Export / ContactTest.php
index 2178788173ce7b49c0d26229ebd6a8c9d8be3705..9dc3eb46c0d77069fd5e07e4d5d3d32e93d577d3 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -31,6 +31,118 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     parent::setUp();
   }
 
+  function testPrefixGenderSuffix(){
+    $this->webtestLogin();
+
+    // Create new  group
+    $parentGroupName = 'TestSuffixPrefixGender_' . substr(sha1(rand()), 0, 7);
+    $this->addContactGroup($parentGroupName);
+
+    // Adding Parent group contact
+    // We're using Quick Add block on the main page for this.
+    $firstContactName = 'TestExport' . substr(sha1(rand()), 0, 7);
+
+    list($emailContactFirst,$prefixLabelContactFrst,$suffixLabelContactFrst,$genderLabelContactFrst) = WebTest_Export_ContactTest::webtestAddContactWithGenderPrefixSuffix($firstContactName, "Smith", "$firstContactName.smith@example.org", Null);
+
+    $sortFirstName = "Smith, $firstContactName";
+    $displayFirstName = "$firstContactName Smith";
+
+    // Add contact to parent  group
+    // visit group tab.
+    $this->click("css=li#tab_group a");
+    $this->waitForElementPresent("group_id");
+
+    // Add to group.
+    $this->select("group_id", "label=$parentGroupName");
+    $this->click("_qf_GroupContact_next");
+    $this->waitForElementPresent("//*[@id='GroupContact']");
+
+    $secondContactName = 'TestExport2' . substr(sha1(rand()), 0, 7);
+    list($emailContactSecond,$prefixLabelContactScnd,$suffixLabelContactScnd,$genderLabelContactScnd) = WebTest_Export_ContactTest::webtestAddContactWithGenderPrefixSuffix($secondContactName, "John", "$secondContactName.john@example.org", Null);
+
+    $sortSecondName = "John, $secondContactName";
+    $displaySecondName = "$secondContactName John";
+
+    // Add contact to parent  group
+    // visit group tab.
+    $this->click("css=li#tab_group a");
+    $this->waitForElementPresent("group_id");
+
+    // Add to group.
+    $this->select("group_id", "label=$parentGroupName");
+    $this->click("_qf_GroupContact_next");
+    $this->waitForElementPresent("//*[@id='GroupContact']");
+
+    $this->openCiviPage("contact/search", "reset=1");
+
+    // Select contact type as Indiividual.
+    $this->select("contact_type", "value=Individual");
+
+    // Select group.
+    $this->select("group", "label=$parentGroupName");
+
+    // Click to search.
+    $this->click("_qf_Basic_refresh");
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+
+    // Is contact present in search result?
+    $this->assertElementContainsText('css=div.crm-search-results', $sortFirstName, "Contact did not found in search result!");
+
+    // Is contact present in search result?
+    $this->assertElementContainsText('css=div.crm-search-results', $sortSecondName, "Contact did not found in search result!");
+
+    // select to export all the contasct from search result.
+    $this->click("CIVICRM_QFID_ts_all_4");
+
+    // Select the task action to export.
+    $this->click("task");
+    $this->select("task", "label=Export Contacts");
+    $this->click("Go");
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+
+    $csvFile = $this->downloadCSV("_qf_Select_next-bottom");
+
+    // Build header row for assertion.
+    require_once 'CRM/Contact/BAO/Contact.php';
+    $expotableFields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE);
+
+    $checkHeaders = array();
+    foreach ($expotableFields as $key => $field) {
+      // Exclude custom fields.
+      if ($key && (substr($key, 0, 6) == 'custom')) {
+        continue;
+      }
+      $checkHeaders[] = $field['title'];
+    }
+
+    // All other rows to be check.
+    $checkRows = array(
+      1 => array(
+        'First Name' => $firstContactName,
+        'Last Name' => 'Smith',
+        'Email' => ''.strtolower($emailContactFirst).'',
+        'Sort Name' => $sortFirstName,
+        'Display Name' => $prefixLabelContactFrst.' '.$displayFirstName.' '.$suffixLabelContactFrst,
+        'Individual Prefix' => $prefixLabelContactFrst,
+        'Individual Suffix' => $suffixLabelContactFrst,
+        'Gender' => $genderLabelContactFrst,
+      ),
+      2 => array(
+        'First Name' => $secondContactName,
+        'Last Name' => 'John',
+        'Email' => ''.strtolower($emailContactSecond).'',
+        'Sort Name' => $sortSecondName,
+        'Display Name' => $prefixLabelContactScnd.' '.$displaySecondName.' '.$suffixLabelContactScnd,
+        'Individual Prefix' => $prefixLabelContactScnd,
+        'Individual Suffix' => $suffixLabelContactScnd,
+        'Gender' => $genderLabelContactScnd,
+      ),
+    );
+
+    // Read CSV and fire assertions.
+    $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
+  }
+
   /**
    *  Test Contact Export.
    */
@@ -61,7 +173,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to group.
     $this->select("group_id", "label=$parentGroupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("//*[@id='GroupContact']");
 
     // Adding child group contact
     // We're using Quick Add block on the main page for this.
@@ -79,7 +191,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to child group.
     $this->select("group_id", "label=regexp:$childGroupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("//*[@id='GroupContact']");
 
     // Visit contact search page.
     $this->openCiviPage("contact/search", "reset=1");
@@ -184,7 +296,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to group.
     $this->select("group_id", "label=$groupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("//*[@id='GroupContact']");
 
     $firstName1 = 'aa' . substr(sha1(rand()), 0, 5);
     $this->webtestAddContact($firstName1, "Smith", "{$firstName1}.smith@example.org");
@@ -200,7 +312,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to group.
     $this->select("group_id", "label=$groupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("//*[@id='GroupContact']");
 
     $firstName2 = 'bb' . substr(sha1(rand()), 0, 5);
 
@@ -216,8 +328,8 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     $this->click("//div[@id='addressBlockId']/div[1]");
 
     $this->click("address[1][use_shared_address]");
-    $this->waitForElementPresent("contact_1");
-    $this->webtestFillAutocomplete($houseHold);
+    $this->waitForElementPresent("address_1_master_contact_id");
+    $this->select2('address_1_master_contact_id', $houseHold);
     $this->waitForTextPresent("121A Sherman");
 
     $this->click('_qf_Contact_upload_view-bottom');
@@ -234,7 +346,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Add to group.
     $this->select("group_id", "label=$groupName");
     $this->click("_qf_GroupContact_next");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent("//*[@id='GroupContact']");
 
     $this->openCiviPage("contact/search", "reset=1", NULL);
 
@@ -299,7 +411,7 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     $this->reviewCSV($csvFile, $checkHeaders, $checkRows, 2);
   }
 
-  function addContactGroup($groupName = 'New Group', $parentGroupName = "- select -") {
+  function addContactGroup($groupName = 'New Group', $parentGroupName = "- select group -") {
     $this->openCiviPage("group/add", "reset=1", "_qf_Edit_upload");
 
     // Fill group name.
@@ -327,4 +439,55 @@ class WebTest_Export_ContactTest extends ExportCiviSeleniumTestCase {
     // Is status message correct?
     $this->waitForText('crm-notification-container', "The Group '$groupName' has been saved.");
   }
+
+  function webtestAddContactWithGenderPrefixSuffix($fname = 'Anthony', $lname = 'Anderson', $email = NULL, $contactSubtype = NULL) {
+    $url = $this->sboxPath . 'civicrm/contact/add?reset=1&ct=Individual';
+    if ($contactSubtype) {
+      $url = $url . "&cst={$contactSubtype}";
+    }
+    $this->open($url);
+    $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
+
+    $this->type('first_name', $fname);
+    $this->type('last_name', $lname);
+    if ($email === TRUE) {
+      $email = substr(sha1(rand()), 0, 7) . '@example.org';
+    }
+    if ($email) {
+      $this->type('email_1_email', $email);
+    }
+    $genderLabelArray = array(
+      1 => 'Female',
+      2 => 'Male',
+      3 => 'Transgender'
+    );
+    $prefix = rand(1, 4);
+    $suffix = rand(1, 8);
+    $gender = rand(1, 3);
+    $genderLabel = "civicrm_gender_".$genderLabelArray[$gender]."_$gender";
+    $this->select("prefix_id", "value=$prefix");
+    $this->select("suffix_id", "value=$suffix");
+    $this->click("demographics");
+    $this->waitForElementPresent("civicrm_gender_Female_1");
+    $this->click($genderLabel,"value=$gender");
+    $this->waitForElementPresent('_qf_Contact_upload_view-bottom');
+    $this->click('_qf_Contact_upload_view-bottom');
+    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $prefixLabel = WebTest_Export_ContactTest::getOptionLabel('individual_prefix',$prefix);
+    $suffixLabel = WebTest_Export_ContactTest::getOptionLabel('individual_suffix',$suffix);
+    $genderLabel = WebTest_Export_ContactTest::getOptionLabel('gender',$gender);
+    return array($email,$prefixLabel,$suffixLabel,$genderLabel);
+  }
+
+  function getOptionLabel($optionGroupName,$optionValue){
+    $params = array(
+      'version' => 3,
+      'sequential' => 1,
+      'option_group_name' => $optionGroupName,
+      'value' => $optionValue,
+      'return' => 'label'
+    );
+    $optionLabel = $this->webtest_civicrm_api("OptionValue", "getvalue",$params);
+    return $optionLabel;
+  }
 }