diff --git a/tests/README.md b/tests/README.md index fd87b59ea6..9949f54f54 100644 --- a/tests/README.md +++ b/tests/README.md @@ -12,18 +12,23 @@ clean, empty tests database. ## Running Tests -First, configure your test environment. Copy `tests/config.tests.sample.inc.php` to `tests/config.tests.inc.php` and +First, configure your test environment. + +Copy `tests/config.tests.sample.inc.php` to `tests/config.tests.inc.php` and set the appropriate values. You will need a clean, empty database to run your tests. By default, name it `thinkup_tests` and set the `$TEST_DATABASE` config variable to that name. +In `webapp/config.inc.php`, in the DEVELOPER CONFIG section, set the name of your tests database, and the username and +password to access it. This database name should match the one you just set in `tests/config.tests.inc.php`. + ### Test Assumptions In order for the tests to pass, you must: * Have a `tests/config.tests.inc.php` file with the correct values set * Set the crawler log file in `webapp/config.inc.php` and make that file writable -* Set the database name to an empty tests database which the tests will destroy each run in `webapp/config.inc.php` -* Set the database user to a user with all privileges in the test database and global CREATE, DROP, and FILE privs +* Set the test database name to an empty tests database which the tests will destroy each run in `webapp/config.inc.php` +* Set the test database user to a user with all privileges in the test database and global CREATE, DROP, and FILE privs * Set caching to false in `webapp/config.inc.php` * Have a local installation of ThinkUp using your test database * Have a working internet connection diff --git a/tests/WebTestOfUpgradeDatabase.php b/tests/WebTestOfUpgradeDatabase.php index 532c67b251..ebebbc6f7e 100644 --- a/tests/WebTestOfUpgradeDatabase.php +++ b/tests/WebTestOfUpgradeDatabase.php @@ -135,6 +135,12 @@ private function setUpApp($version, $MIGRATIONS) { $this->assertFalse(file_exists($THINKUP_CFG['source_root_path']. 'webapp/test_installer/thinkup/config.inc.php')); + //Set test mode + $this->get($this->url.'/test_installer/thinkup/install/setmode.php?m=tests'); + //Include config again to get test db credentials + require THINKUP_WEBAPP_PATH.'config.inc.php'; + //$this->showText(); + //Start installation process $this->get($this->url.'/test_installer/thinkup/'); $this->assertTitle("ThinkUp"); @@ -142,6 +148,12 @@ private function setUpApp($version, $MIGRATIONS) { $this->clickLink("installing ThinkUp."); $this->assertText('Great! Your system has everything it needs to run ThinkUp. You may proceed to the next '. 'step.'); + + //Set test mode + putenv("MODE=TESTS"); + //Include config again to get test db credentials + require THINKUP_WEBAPP_PATH.'config.inc.php'; + $this->get('index.php?step=2'); $this->assertText('Create Your ThinkUp Account'); @@ -152,7 +164,7 @@ private function setUpApp($version, $MIGRATIONS) { $this->setField('timezone', 'America/Los_Angeles'); $this->setField('db_host', $THINKUP_CFG['db_host']); - $this->setField('db_name', $this->test_database_name); + $this->setField('db_name', $THINKUP_CFG['db_name']); $this->setField('db_user', $THINKUP_CFG['db_user']); $this->setField('db_passwd', $THINKUP_CFG['db_password']); $this->setField('db_socket', $THINKUP_CFG['db_socket']); diff --git a/tests/classes/class.ThinkUpBasicWebTestCase.php b/tests/classes/class.ThinkUpBasicWebTestCase.php index d72b4f0027..65853e10c3 100644 --- a/tests/classes/class.ThinkUpBasicWebTestCase.php +++ b/tests/classes/class.ThinkUpBasicWebTestCase.php @@ -23,7 +23,7 @@ * * @author Gina Trapani * @license http://www.gnu.org/licenses/gpl.html - * @copyright 2009-2010 Gina Trapani + * @copyright 2009-2011 Gina Trapani */ class ThinkUpBasicWebTestCase extends WebTestCase { /** @@ -42,6 +42,9 @@ public function setUp() { $this->url = $TEST_SERVER_DOMAIN; $this->DEBUG = (getenv('TEST_DEBUG')!==false) ? true : false; + putenv("MODE=TESTS"); + $this->get($this->url.'/install/setmode.php?m=tests'); + self::isWebTestEnvironmentReady(); require THINKUP_ROOT_PATH.'tests/config.tests.inc.php'; @@ -49,6 +52,8 @@ public function setUp() { } public function tearDown() { + putenv("MODE=PROD"); + $this->get($this->url.'/install/setmode.php?m=prod'); } public function debug($message) { diff --git a/tests/init.tests.php b/tests/init.tests.php index 78ec37f83e..b4db23fb3e 100644 --- a/tests/init.tests.php +++ b/tests/init.tests.php @@ -24,6 +24,7 @@ * @license http://www.gnu.org/licenses/gpl.html * @copyright 2009-2010 Gina Trapani */ +putenv("MODE=TESTS"); require_once 'config.tests.inc.php'; //set up 3 required constants diff --git a/webapp/config.sample.inc.php b/webapp/config.sample.inc.php index 06682d62ed..6e80c21f98 100644 --- a/webapp/config.sample.inc.php +++ b/webapp/config.sample.inc.php @@ -56,3 +56,10 @@ // Set this to true if you want your PDO object's database connection's charset to be explicitly set to utf8. // If false (or unset), the database connection's charset will not be explicitly set. $THINKUP_CFG['set_pdo_charset'] = false; + +//Test database override: Set this to run tests against the tests database +if ((isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE")=="TESTS") { + $THINKUP_CFG['db_user'] = 'your_test_database_username'; + $THINKUP_CFG['db_password'] = 'your_test_database_password'; + $THINKUP_CFG['db_name'] = 'your_test_database_name'; //by default, thinkup_tests +} diff --git a/webapp/install/setmode.php b/webapp/install/setmode.php new file mode 100644 index 0000000000..601d4b1030 --- /dev/null +++ b/webapp/install/setmode.php @@ -0,0 +1,45 @@ +. + * + * + * @author Gina Trapani + * @license http://www.gnu.org/licenses/gpl.html + * @copyright 2011 Gina Trapani + */ +session_start(); +if (strtolower($_GET['m']) == "tests") { + putenv("MODE=TESTS"); + $_SESSION["MODE"] = "TESTS"; + echo "Set to tests mode"; +} elseif (strtolower($_GET['m']) == "prod") { + putenv("MODE=PROD"); + $_SESSION["MODE"] = "PROD"; + echo "Set to prod mode"; +} else { + echo "Currently in "; + if (isset($_SESSION["MODE"])) { + echo strtolower($_SESSION["MODE"]); + } else { + echo " prod "; + } + echo " mode"; +}