Permalink
Browse files

Standardize test mode check

Use a cookie rather than SESSION for web-based test flag
Use single Utils function to check test mode everywhere
Stop using global TESTS_RUNNING variable
  • Loading branch information...
1 parent 9e59f87 commit 7404a1f39e394d4bac3e4f8ab38982ce9a1e9dcf @ginatrapani ginatrapani committed Feb 27, 2014
@@ -73,8 +73,8 @@
$THINKUP_CFG['set_pdo_charset'] = false;
//TESTS OVERRIDE: Run against the tests database and use unpackaged developer /thinkup/webapp/ folder structure
-if ((isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") && ! isset($_SESSION["RD_MODE"])
-|| (getenv("MODE")=="TESTS" && ! getenv("RD_MODE")=="1")) {
+if ((isset($_COOKIE['TU_MODE']) && $_COOKIE['TU_MODE']=='TESTS') && !isset($_SESSION["RD_MODE"])
+|| (getenv("MODE")=="TESTS" && !getenv("RD_MODE")=="1")) {
// Full server path to /thinkup/ source code folder.
// $THINKUP_CFG['source_root_path'] = '/your-server-path-to/thinkup/';
// $THINKUP_CFG['db_user'] = 'your_test_database_username';
@@ -89,4 +89,4 @@
$THINKUP_CFG['db_user'] = 'your_ram_disk_test_database_username';
$THINKUP_CFG['db_password'] = 'your_ram_disk_test_database_password';
$THINKUP_CFG['db_name'] = $THINKUP_CFG['db_name'] . '_rd';
-}
+}
@@ -65,6 +65,9 @@ public function setUp() {
$crawler_plugin_registrar = PluginRegistrarCrawler::getInstance();
$this->DEBUG = (getenv('TEST_DEBUG')!==false) ? true : false;
+ ini_set('session.use_cookies', 0);
+ session_cache_limiter('');
+
self::isTestEnvironmentReady();
}
@@ -36,10 +36,6 @@
define('THINKUP_WEBAPP_PATH', THINKUP_ROOT_PATH . 'webapp/');
}
-if ( !defined('TESTS_RUNNING') ) {
- define('TESTS_RUNNING', true);
-}
-
//Register our lazy class loader
require_once THINKUP_WEBAPP_PATH.'_lib/class.Loader.php';
@@ -84,7 +84,7 @@ public function generate() {
*/
public function doesTextMatchImage() {
//if in test mode, assume check is good if user_code is set to 123456
- if ((isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE")=="TESTS") {
+ if (Utils::isTest()) {
if (isset($_POST['user_code']) && $_POST['user_code'] == '123456') {
return true;
} else {
@@ -142,7 +142,7 @@ public static function getInstance() {
*/
public function checkVersion($ver = '') {
// when testing
- if ( defined('TESTS_RUNNING') && TESTS_RUNNING && !empty($ver) ) {
+ if ( Utils::isTest() && !empty($ver) ) {
$version = $ver;
} else {
$version = PHP_VERSION;
@@ -207,7 +207,7 @@ public function checkDependency($libs = array()) {
$ret['ZipArchive'] = true;
}
// when testing
- if ( defined('TESTS_RUNNING') && TESTS_RUNNING && !empty($libs) ) {
+ if ( Utils::isTest() && !empty($libs) ) {
$ret = $libs;
}
return $ret;
@@ -248,7 +248,7 @@ public function checkPermission($perms = array()) {
}
// when testing
- if ( defined('TESTS_RUNNING') && TESTS_RUNNING && !empty($perms) ) {
+ if ( Utils::isTest() && !empty($perms) ) {
$ret = $perms;
}
return $ret;
@@ -304,7 +304,7 @@ public function checkStep1($pass = true) {
$writable_session_permission = $this->isSessionDirectoryWritable();
// when testing
- if ( defined('TESTS_RUNNING') && TESTS_RUNNING && !empty($pass) ) {
+ if ( Utils::isTest() && !empty($pass) ) {
$ret = $pass;
} else {
$ret = ($version_compat && $lib_depends_ret && $writable_permission_ret && $writable_session_permission);
@@ -457,7 +457,7 @@ public function isThinkUpInstalled($config) {
// check version is met
$version_met = self::checkStep1();
// when testing
- if ( defined('TESTS_RUNNING') && TESTS_RUNNING && !empty($pass) ) {
+ if ( Utils::isTest() && !empty($pass) ) {
$version_met = $pass;
}
if ( !$version_met ) {
@@ -47,8 +47,7 @@ public static function reportVersion(Instance $instance) {
$referer_url .= "?u=".urlencode($instance->network_username)."&n=". urlencode($instance->network);
}
- $in_test_mode = ((isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE")=="TESTS");
- if (!$in_test_mode) { //only make live request if we're not running the test suite
+ if (!Utils::isTest()) { //only make live request if we're not running the test suite
//Make the cURL request
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $report_back_url);
@@ -75,7 +75,7 @@ public static function completeLogin($owner) {
SessionCache::put('user_is_admin', $owner->is_admin);
// set a CSRF token
SessionCache::put('csrf_token', uniqid(mt_rand(), true));
- if (isset($_SESSION["MODE"]) && $_SESSION["MODE"] == 'TESTS') {
+ if (Utils::isTest()) {
SessionCache::put('csrf_token', 'TEST_CSRF_TOKEN');
}
}
@@ -473,6 +473,6 @@ public static function getLastSaturday($from_date = null ) {
* @return bool Whether in test mode
*/
public static function isTest() {
- return (isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE")=="TESTS";
+ return (getenv("MODE")=="TESTS" || (isset($_COOKIE['TU_MODE']) && $_COOKIE['TU_MODE']=='TESTS'));
}
}
@@ -422,7 +422,7 @@ private function repairInstallation($to_repair) {
// check $THINKUP_CFG['repair'] is set to true
// bypass this security check when running tests
- if ( defined('TESTS_RUNNING') && TESTS_RUNNING ) {
+ if ( Utils::isTest() ) {
$THINKUP_CFG['repair'] = true;
}
$this->installer->repairerIsDefined($THINKUP_CFG);
@@ -78,7 +78,7 @@
$THINKUP_CFG['set_pdo_charset'] = false;
//TESTS OVERRIDE: Assign variables below to use different settings during test builds
-if ((isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") && ! isset($_SESSION["RD_MODE"])
+if ((isset($_COOKIE['TU_MODE']) && $_COOKIE['TU_MODE']=='TESTS') && ! isset($_SESSION["RD_MODE"])
|| (getenv("MODE")=="TESTS" && ! getenv("RD_MODE")=="1")) {
// $THINKUP_CFG['source_root_path'] = '/your-server-path-to/thinkup/';
// $THINKUP_CFG['db_user'] = 'your_test_database_username';
@@ -23,16 +23,16 @@
*
* @author Gina Trapani <ginatrapani[at]gmail[dot]com>
* @license http://www.gnu.org/licenses/gpl.html
- * @copyright 2011-2013 Gina Trapani
+ * @copyright 2011-2014 Gina Trapani
*/
-session_start();
+
if (strtolower($_GET['m']) == "tests") {
putenv("MODE=TESTS");
- $_SESSION["MODE"] = "TESTS";
+ setcookie('TU_MODE', 'TESTS', 0, '/');
echo "Set to tests mode";
} elseif (strtolower($_GET['m']) == "prod") {
putenv("MODE=PROD");
- $_SESSION["MODE"] = "PROD";
+ setcookie('TU_MODE', 'PROD', 0, '/');
echo "Set to prod mode";
} else {
echo "Currently in ";
@@ -94,8 +94,7 @@ public function generateInsight(Instance $instance, $last_week_of_posts, $number
public function shouldGenerateInsight($slug, Instance $instance, $insight_date=null,
$regenerate_existing_insight=false, $day_of_week=null, $count_last_week_of_posts=null,
$excluded_networks=null, $alternate_day=true) {
- $in_test_mode = ((isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE") == "TESTS");
- if ($in_test_mode) {
+ if (Utils::isTest()) {
return true;
} else {
return $alternate_day && parent::shouldGenerateInsight($slug, $instance, $insight_date,
@@ -79,9 +79,8 @@ public function shouldGenerateInsight($slug, Instance $instance, $insight_date=n
}
// Check whether testing
- $in_test_mode = ((isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE") == "TESTS");
- if ($in_test_mode) {
- return ($run && $in_test_mode);
+ if (Utils::isTest()) {
+ return ($run && Utils::isTest());
}
// Check the day of the week (0 for Sunday through 6 for Saturday) on which the insight should run
@@ -69,8 +69,7 @@ public function authControl() {
/* Request tokens from twitter */
$token_array = $twitter_oauth->getRequestToken(Utils::getApplicationURL(true)."account/?p=twitter");
- if (isset($token_array['oauth_token'])
- || (isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS") || getenv("MODE")=="TESTS") { //testing
+ if (isset($token_array['oauth_token']) || Utils::isTest()) {
$token = $token_array['oauth_token'];
SessionCache::put('oauth_request_token_secret', $token_array['oauth_token_secret']);

0 comments on commit 7404a1f

Please sign in to comment.