CRM-17860 - Populate CiviSeleniumSettings using `cv`
authorTim Otten <totten@civicrm.org>
Fri, 29 Jan 2016 01:27:37 +0000 (17:27 -0800)
committerTim Otten <totten@civicrm.org>
Tue, 2 Feb 2016 04:56:23 +0000 (21:56 -0700)
tests/phpunit/CiviTest/CiviSeleniumSettings.auto.php [new file with mode: 0644]
tests/phpunit/CiviTest/CiviSeleniumTestCase.php
tests/phpunit/WebTest/Utils/RedirectTest.php

diff --git a/tests/phpunit/CiviTest/CiviSeleniumSettings.auto.php b/tests/phpunit/CiviTest/CiviSeleniumSettings.auto.php
new file mode 100644 (file)
index 0000000..cec0a0f
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * This is a variant of CiviSeleniumSettings which autopopulates
+ * using data from $_ENV.
+ */
+class CiviSeleniumSettings {
+  public $publicSandbox = FALSE;
+  public $browser = '*firefox';
+  public $sandboxURL;
+  public $sandboxPATH;
+  public $username;
+  public $password;
+  public $adminUsername;
+  public $adminPassword;
+  public $adminApiKey;
+  public $siteKey;
+  public $UFemail = 'noreply@civicrm.org';
+  public $cookies;
+
+  public function __construct() {
+    $required = array();
+    foreach (array('CMS_URL', 'ADMIN_USER', 'ADMIN_PASS', 'DEMO_USER', 'DEMO_PASS') as $key) {
+      if (empty($GLOBALS['_CV'][$key])) {
+        $required[] = $key;
+      }
+    }
+    if (!empty($required)) {
+      throw new RuntimeException("CiviSeleniumSettings failed to find required values from cv: "
+        . implode(' ', $required));
+    }
+
+    $path = parse_url($GLOBALS['_CV']['CMS_URL'], PHP_URL_PATH);
+    $this->sandboxURL = substr($GLOBALS['_CV']['CMS_URL'], 0, strlen($GLOBALS['_CV']['CMS_URL']) - strlen($path));
+    $this->sandboxPATH = $path;
+    $this->fullSandboxPath = $GLOBALS['_CV']['CMS_URL'];
+    $this->adminUsername = $GLOBALS['_CV']['ADMIN_USER'];
+    $this->adminPassword = $GLOBALS['_CV']['ADMIN_PASS'];
+    $this->username = $GLOBALS['_CV']['DEMO_USER'];
+    $this->password = $GLOBALS['_CV']['DEMO_PASS'];
+    $this->siteKey = CIVICRM_SITE_KEY;
+    $this->adminApiKey = md5('apikeyadmin' . $GLOBALS['_CV']['CMS_DB_DSN'] . CIVICRM_SITE_KEY);
+    $this->cookies = array();
+  }
+
+  //  /**
+  //   * @return array
+  //   */
+  //  function createConstCookie() {
+  //    global $civibuild;
+  //    $now = time();
+  //    $civiConsts = array(
+  //      'CIVICRM_DSN' => CIVICRM_DSN,
+  //      'CIVICRM_UF_DSN' => CIVICRM_UF_DSN,
+  //      'ts' => $now,
+  //      'sig' => md5(implode(';;', array(CIVICRM_DSN, CIVICRM_UF_DSN, $civibuild['SITE_TOKEN'], $now))),
+  //    );
+  //
+  //    return array(
+  //      'name' => 'civiConsts',
+  //      'value' => urlencode(json_encode($civiConsts)),
+  //    );
+  //  }
+
+}
index a4d69e577555be1d5fcbcf0a89be2d235b21c541..98f32c166969ace9c9cc62d938c086cce6ae248a 100644 (file)
@@ -59,7 +59,15 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase {
     parent::__construct($name, $data, $dataName, $browser);
     $this->loggedInAs = NULL;
 
-    require_once 'CiviSeleniumSettings.php';
+    if (!empty($GLOBALS['_CV'])) {
+      require_once 'CiviSeleniumSettings.auto.php';
+    }
+    elseif (CRM_Utils_File::isIncludable('CiviSeleniumSettings.php')) {
+      require_once 'CiviSeleniumSettings.php';
+    }
+    else {
+      throw new RuntimeException("Cannot initialize Selenium test. Please setup CiviSeleniumSettings.php or configure \"cv\".");
+    }
     $this->settings = new CiviSeleniumSettings();
     if (property_exists($this->settings, 'serverStartupTimeOut') && $this->settings->serverStartupTimeOut) {
       global $CiviSeleniumTestCase_polled;
index 910d050bf2594cd50cd6b990383fe94ae59adb46..c96c98f1f90a5e755981dc7560d6ab3eec706d80 100644 (file)
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
  */
-require_once 'CiviTest/CiviUnitTestCase.php';
-require_once 'CiviTest/CiviSeleniumSettings.php';
 
 define('CIVICRM_WEBTEST', 1);
 
 /**
  * Check that we handle redirects appropriately.
  */
-class WebTest_Utils_RedirectTest extends CiviUnitTestCase {
+class WebTest_Utils_RedirectTest extends PHPUnit_Framework_TestCase {
   protected $url;
   protected $ch;
 
@@ -41,6 +39,16 @@ class WebTest_Utils_RedirectTest extends CiviUnitTestCase {
   public function __construct($name = NULL) {
     parent::__construct($name);
 
+    // TODO: Just use $GLOBALS['_CV'] and don't bother with CiviSeleniumSettings.
+    if (!empty($GLOBALS['_CV'])) {
+      require_once 'CiviTest/CiviSeleniumSettings.auto.php';
+    }
+    elseif (CRM_Utils_File::isIncludable('CiviTest/CiviSeleniumSettings.php')) {
+      require_once 'CiviTest/CiviSeleniumSettings.php';
+    }
+    else {
+      throw new RuntimeException("Cannot initialize Selenium test. Please setup CiviSeleniumSettings.php or configure \"cv\".");
+    }
     $this->settings = new CiviSeleniumSettings();
     if (property_exists($this->settings, 'serverStartupTimeOut') && $this->settings->serverStartupTimeOut) {
       global $CiviSeleniumTestCase_polled;