Webtest cleanup and fixes
[civicrm-core.git] / tests / phpunit / WebTest / Import / ImportCiviSeleniumTestCase.php
index de90475c7a0cc35fdacb3406c18163a985600f69..7fb9f49ea7283460b529485b8e49cf2596491104 100644 (file)
@@ -69,12 +69,7 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
   ) {
 
     // Go to contact import page.
-    $this->open($this->sboxPath . $this->_getImportComponentUrl($component));
-
-    $this->waitForPageToLoad($this->getTimeoutMsec());
-
-    // check for upload field.
-    $this->waitForElementPresent("uploadFile");
+    $this->openCiviPage($this->_getImportComponentUrl($component), 'reset=1', "uploadFile");
 
     // Create csv file of sample data.
     $csvFile = $this->webtestCreateCSV($headers, $rows);
@@ -209,8 +204,7 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
    * @param array $other
    * @param string $type
    */
-  function importContacts($headers, $rows, $contactType = 'Individual', $mode = 'Skip', $fieldMapper = array(
-    ), $other = array(), $type = 'csv') {
+  function importContacts($headers, $rows, $contactType = 'Individual', $mode = 'Skip', $fieldMapper = array(), $other = array(), $type = 'csv') {
 
     // Go to contact import page.
     $this->openCiviPage("import/contact", "reset=1", "uploadFile");
@@ -251,15 +245,8 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
 
     // Select contact subtype
     if (isset($other['contactSubtype'])) {
-      if ($contactType != 'Individual') {
-        // Because it tends to cause problems, all uses of sleep() must be justified in comments
-        // Sleep should never be used for wait for anything to load from the server
-        // FIXME: this is bad, using sleep to wait for AJAX
-        // Need to use a better way to wait for contact subtypes to repopulate
-        sleep(5);
-      }
-      $this->waitForElementPresent("subType");
-      $this->select('subType', 'label=' . $other['contactSubtype']);
+      $this->waitForElementPresent("css=#subType option[value={$other['contactSubtype']}]");
+      $this->select('subType', $other['contactSubtype']);
     }
 
     if (isset($other['dedupe'])) {
@@ -289,8 +276,7 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
     }
 
     // Submit form.
-    $this->click('_qf_DataSource_upload');
-    $this->waitForPageToLoad($this->getTimeoutMsec());
+    $this->clickLink('_qf_DataSource_upload');
 
     if (isset($other['checkMapperHeaders'])) {
       $checkMapperHeaders = $other['checkMapperHeaders'];
@@ -461,13 +447,12 @@ class ImportCiviSeleniumTestCase extends CiviSeleniumTestCase {
    *
    * @return mixed
    */
-  function _getImportComponentUrl($component) {
-
+  private function _getImportComponentUrl($component) {
     $importComponentUrl = array(
-      'Event' => 'civicrm/event/import?reset=1',
-      'Contribution' => 'civicrm/contribute/import?reset=1',
-      'Membership' => 'civicrm/member/import?reset=1',
-      'Activity' => 'civicrm/import/activity?reset=1',
+      'Event' => 'event/import',
+      'Contribution' => 'contribute/import',
+      'Membership' => 'member/import',
+      'Activity' => 'import/activity',
     );
 
     return $importComponentUrl[$component];