diff --git a/core/control/Director.php b/core/control/Director.php index 992420dd9..e06206149 100755 --- a/core/control/Director.php +++ b/core/control/Director.php @@ -649,7 +649,7 @@ class Director { $destURL = str_replace('http:', 'https:', Director::absoluteURL($_SERVER['REQUEST_URI'])); // This coupling to SapphireTest is necessary to test the destination URL and to not interfere with tests - if(SapphireTest::is_running_test()) { + if(class_exists('SapphireTest', false) && SapphireTest::is_running_test()) { return $destURL; } else { if(!headers_sent()) header("Location: $destURL"); diff --git a/core/model/DatabaseAdmin.php b/core/model/DatabaseAdmin.php index 11ae278a9..fc62b3810 100644 --- a/core/model/DatabaseAdmin.php +++ b/core/model/DatabaseAdmin.php @@ -29,12 +29,13 @@ class DatabaseAdmin extends Controller { // if on CLI or with the database not ready. The latter makes it less errorprone to do an // initial schema build without requiring a default-admin login. // Access to this controller is always allowed in "dev-mode", or of the user is ADMIN. + $isRunningTests = (class_exists('SapphireTest', false) && SapphireTest::is_running_test()); $canAccess = ( Director::isDev() || !Security::database_is_ready() // We need to ensure that DevelopmentAdminTest can simulate permission failures when running // "dev/tests" from CLI. - || (Director::is_cli() && !SapphireTest::is_running_test()) + || (Director::is_cli() && !$isRunningTests) || Permission::check("ADMIN") ); if(!$canAccess) { diff --git a/dev/TaskRunner.php b/dev/TaskRunner.php index f4d9a118b..367e5c125 100644 --- a/dev/TaskRunner.php +++ b/dev/TaskRunner.php @@ -12,12 +12,13 @@ class TaskRunner extends Controller { function init() { parent::init(); - + + $isRunningTests = (class_exists('SapphireTest', false) && SapphireTest::is_running_test()); $canAccess = ( Director::isDev() // We need to ensure that DevelopmentAdminTest can simulate permission failures when running // "dev/tasks" from CLI. - || (Director::is_cli() && !SapphireTest::is_running_test()) + || (Director::is_cli() && !$isRunningTests) || Permission::check("ADMIN") ); if(!$canAccess) return Security::permissionFailure($this); diff --git a/filesystem/Upload.php b/filesystem/Upload.php index 9d4983359..1e833c3eb 100644 --- a/filesystem/Upload.php +++ b/filesystem/Upload.php @@ -476,7 +476,8 @@ class Upload_Validator { // we don't validate for empty upload fields yet if(!isset($this->tmpFile['name']) || empty($this->tmpFile['name'])) return true; - if(isset($this->tmpFile['tmp_name']) && !is_uploaded_file($this->tmpFile['tmp_name']) && !SapphireTest::is_running_test()) { + $isRunningTests = (class_exists('SapphireTest', false) && SapphireTest::is_running_test()); + if(isset($this->tmpFile['tmp_name']) && !is_uploaded_file($this->tmpFile['tmp_name']) && !$isRunningTests) { $this->errors[] = _t('File.NOVALIDUPLOAD', 'File is not a valid upload'); return false; } diff --git a/security/BasicAuth.php b/security/BasicAuth.php index 7c13606b2..8393aaba0 100755 --- a/security/BasicAuth.php +++ b/security/BasicAuth.php @@ -44,7 +44,8 @@ class BasicAuth { * @return Member $member */ static function requireLogin($realm, $permissionCode = null, $tryUsingSessionLogin = true) { - if(!Security::database_is_ready() || (Director::is_cli() && !SapphireTest::is_running_test())) return true; + $isRunningTests = (class_exists('SapphireTest', false) && SapphireTest::is_running_test()); + if(!Security::database_is_ready() || (Director::is_cli() && !$isRunningTests)) return true; $member = null; if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { diff --git a/tasks/EncryptAllPasswordsTask.php b/tasks/EncryptAllPasswordsTask.php index 42047bd95..14b3bc622 100644 --- a/tasks/EncryptAllPasswordsTask.php +++ b/tasks/EncryptAllPasswordsTask.php @@ -66,7 +66,7 @@ class EncryptAllPasswordsTask extends BuildTask { * @todo This should really be taken care of by TestRunner */ protected function debugMessage($msg) { - if(!SapphireTest::is_running_test()) { + if(class_exists('SapphireTest', false) && !SapphireTest::is_running_test()) { Debug::message($msg); } }