Skip to content

Commit

Permalink
MDL-37324 fix phpunit and behat SESSION and USER setup
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 24, 2013
1 parent c925e4f commit de230fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lib/classes/session/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ protected static function init_empty_session() {
$_SESSION['USER']->mnethostid = 1;
}

if (PHPUNIT_TEST) {
// Phpunit tests use reversed reference.
if (PHPUNIT_TEST or defined('BEHAT_TEST')) {
// Phpunit tests and behat init use reversed reference,
// the reason is we can not point global to $_SESSION outside of global scope.
global $USER, $SESSION;
$USER = $_SESSION['USER'];
$SESSION = $_SESSION['SESSION'];
Expand Down Expand Up @@ -597,8 +598,9 @@ public static function set_user(\stdClass $user) {
}
sesskey(); // Init session key.

if (PHPUNIT_TEST) {
// Phpunit tests use reversed reference.
if (PHPUNIT_TEST or defined('BEHAT_TEST')) {
// Phpunit tests and behat init use reversed reference,
// the reason is we can not point global to $_SESSION outside of global scope.
global $USER;
$USER = $_SESSION['USER'];
$_SESSION['USER'] =& $USER;
Expand Down
6 changes: 4 additions & 2 deletions lib/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,10 @@ function stripslashes_deep($value) {
$CFG->sessiontimeout = 7200;
}
\core\session\manager::start();
$SESSION = &$_SESSION['SESSION'];
$USER = &$_SESSION['USER'];
if (!PHPUNIT_TEST and !defined('BEHAT_TEST')) {
$SESSION =& $_SESSION['SESSION'];
$USER =& $_SESSION['USER'];
}

// Late profiling, only happening if early one wasn't started
if (!empty($CFG->profilingenabled)) {
Expand Down
6 changes: 4 additions & 2 deletions lib/tests/behat/behat_hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ public function before_scenario($event) {
behat_selectors::register_moodle_selectors($session);
}

// Avoid some notices / warnings.
// Reset $SESSION.
$_SESSION = array();
$SESSION = new stdClass();
$_SESSION['SESSION'] =& $SESSION;

behat_util::reset_database();
behat_util::reset_dataroot();
Expand All @@ -174,7 +176,7 @@ public function before_scenario($event) {
// Reset the nasty strings list used during the last test.
nasty_strings::reset_used_strings();

// Assing valid data to admin user (some generator-related code needs a valid user).
// Assign valid data to admin user (some generator-related code needs a valid user).
$user = $DB->get_record('user', array('username' => 'admin'));
\core\session\manager::set_user($user);

Expand Down

0 comments on commit de230fd

Please sign in to comment.