From 862dad2c4c302eb4703ea7681186c69cf38a2e82 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 28 Jan 2016 17:27:37 -0800 Subject: [PATCH] CRM-17860 - Populate CiviSeleniumSettings using `cv` --- .../CiviTest/CiviSeleniumSettings.auto.php | 65 +++++++++++++++++++ .../phpunit/CiviTest/CiviSeleniumTestCase.php | 10 ++- tests/phpunit/WebTest/Utils/RedirectTest.php | 14 +++- 3 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 tests/phpunit/CiviTest/CiviSeleniumSettings.auto.php diff --git a/tests/phpunit/CiviTest/CiviSeleniumSettings.auto.php b/tests/phpunit/CiviTest/CiviSeleniumSettings.auto.php new file mode 100644 index 0000000000..cec0a0fa38 --- /dev/null +++ b/tests/phpunit/CiviTest/CiviSeleniumSettings.auto.php @@ -0,0 +1,65 @@ +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)), + // ); + // } + +} diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index a4d69e5775..98f32c1669 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -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; diff --git a/tests/phpunit/WebTest/Utils/RedirectTest.php b/tests/phpunit/WebTest/Utils/RedirectTest.php index 910d050bf2..c96c98f1f9 100644 --- a/tests/phpunit/WebTest/Utils/RedirectTest.php +++ b/tests/phpunit/WebTest/Utils/RedirectTest.php @@ -23,15 +23,13 @@ | 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; -- 2.25.1