Web Test Fix
[civicrm-core.git] / tests / phpunit / WebTest / Import / CustomDataTest.php
index d2acbd67cb594087c38f2580a8aa496108b92806..680b1192db3bc9192325adbc217f949553b84421 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -24,7 +24,6 @@
  +--------------------------------------------------------------------+
 */
 
-
 require_once 'WebTest/Import/ImportCiviSeleniumTestCase.php';
 class WebTest_Import_CustomDataTest extends ImportCiviSeleniumTestCase {
 
@@ -33,16 +32,6 @@ class WebTest_Import_CustomDataTest extends ImportCiviSeleniumTestCase {
   }
 
   function testCustomDataImport() {
-    // This is the path where our testing install resides.
-    // The rest of URL is defined in CiviSeleniumTestCase base class, in
-    // class attributes.
-    $this->open($this->sboxPath);
-
-    // Logging in. Remember to wait for page to load. In most cases,
-    // you can rely on 30000 as the value that allows your test to pass, however,
-    // sometimes your test might fail because of this. In such cases, it's better to pick one element
-    // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
-    // page contents loaded and you can continue your test execution.
     $this->webtestLogin();
 
     $firstName1       = 'Ma_' . substr(sha1(rand()), 0, 7);
@@ -52,16 +41,12 @@ class WebTest_Import_CustomDataTest extends ImportCiviSeleniumTestCase {
     $firstName3 = 'Ma' . substr(sha1(rand()), 0, 4);
     $this->webtestAddContact($firstName3, "Anderson", TRUE);
     $sortName3 = "$firstName3 Anderson";
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $url1 = explode('&cid=', $this->getLocation());
-    $id1 = $url1[1];
+    $id1 = $this->urlArg('cid');
 
     $firstName4 = 'Ma' . substr(sha1(rand()), 0, 4);
     $this->webtestAddContact($firstName4, "Anderson", TRUE);
     $sortName4 = "$firstName4 Anderson";
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $url2 = explode('&cid=', $this->getLocation());
-    $id2 = $url2[1];
+    $id2 = $this->urlArg('cid');
 
     // Get sample import data.
     list($headers, $rows, $customDataVerify) = $this->_individualCustomCSVData($customGroupTitle, $firstName1, $firstName2,
@@ -78,8 +63,7 @@ class WebTest_Import_CustomDataTest extends ImportCiviSeleniumTestCase {
     $this->importContacts($headers, $rows, 'Individual', 'Skip', array(), $other);
 
     // Find the contact
-    $this->open($this->sboxPath . "civicrm/contact/search?reset=1");
-    $this->waitForElementPresent('_qf_Basic_refresh');
+    $this->openCiviPage("contact/search", "reset=1", '_qf_Basic_refresh');
     $this->type('sort_name', $firstName1);
     $this->click('_qf_Basic_refresh');
     $this->waitForPageToLoad($this->getTimeoutMsec());
@@ -153,8 +137,8 @@ class WebTest_Import_CustomDataTest extends ImportCiviSeleniumTestCase {
   }
 
   function _addCustomData($customGroupTitle, $id1, $id2) {
-    // Go directly to the URL of the screen that you will be testing (New Custom Group).
-    $this->open($this->sboxPath . "civicrm/admin/custom/group?reset=1");
+
+    $this->openCiviPage("admin/custom/group", "reset=1");
 
     //add new custom data
     $this->click("//a[@id='newCustomDataGroup']/span");
@@ -206,14 +190,14 @@ class WebTest_Import_CustomDataTest extends ImportCiviSeleniumTestCase {
     $this->click('_qf_Field_next-bottom');
     $this->waitForElementPresent('newCustomField');
 
-    $this->assertTrue($this->isTextPresent("Your custom field '{$dateFieldLabel}' has been saved."));
-    
+    $this->assertTrue($this->isTextPresent("Custom field '{$dateFieldLabel}' has been saved."));
+
     $dateFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$dateFieldLabel']/../../td[8]/span/a@href"));
     $dateFieldId = $dateFieldId[1];
 
     // create another custom field - Integer Radio
     $this->click("//a[@id='newCustomField']/span");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent('_qf_Field_cancel-bottom');
     $this->click("data_type[0]");
     $this->select("data_type[0]", "value=1");
     $this->click("//option[@value='1']");
@@ -244,10 +228,11 @@ class WebTest_Import_CustomDataTest extends ImportCiviSeleniumTestCase {
 
     //clicking save
     $this->click("_qf_Field_next");
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent('newCustomField');
 
     //Is custom field created
-    $this->assertTrue($this->isTextPresent("Your custom field '$radioFieldLabel' has been saved."));
+    $this->waitForText("crm-notification-container", "Custom field '$radioFieldLabel' has been saved.");
+    $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$radioFieldLabel']/parent::td/parent::tr/td[8]/span/a");
     $radioFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$radioFieldLabel']/../../td[8]/span/a@href"));
     $radioFieldId = $radioFieldId[1];
 
@@ -284,9 +269,10 @@ class WebTest_Import_CustomDataTest extends ImportCiviSeleniumTestCase {
 
     // clicking save
     $this->click('_qf_Field_next-bottom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-    $this->assertTrue($this->isTextPresent("Your custom field '{$multiSelectLabel}' has been saved."));
-    $multiSelectFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$multiSelectLabel']/../../td[8]/span/a@href"));
+    $this->waitForElementPresent('newCustomField');
+    $this->waitForText("crm-notification-container", "Custom field '{$multiSelectLabel}' has been saved.");
+    $this->waitForElementPresent("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$multiSelectLabel']/parent::td/parent::tr/");
+    $multiSelectFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$multiSelectLabel']/parent::td/parent::tr/td[8]/span/a@href"));
     $multiSelectFieldId = $multiSelectFieldId[1];
 
     // create another custom field - contact reference
@@ -308,10 +294,10 @@ class WebTest_Import_CustomDataTest extends ImportCiviSeleniumTestCase {
 
     // clicking save
     $this->click('_qf_Field_next-bottom');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->waitForElementPresent('newCustomField');
 
-    $this->assertTrue($this->isTextPresent("Your custom field '{$contactReferenceLabel}' has been saved."));
-    $contactReferenceFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$contactReferenceLabel']/../../td[8]/span/a@href"));
+    $this->waitForText("crm-notification-container", "Custom field '{$contactReferenceLabel}' has been saved.");
+    $contactReferenceFieldId = explode('&id=', $this->getAttribute("xpath=//div[@id='field_page']//table/tbody//tr/td/span[text()='$contactReferenceLabel']/parent::td/parent::tr/td[8]/span/a@href"));
     $contactReferenceFieldId = $contactReferenceFieldId[1];
 
     $customDataParams = array(