MDL-52656 unittest: Reset original session while setting user

This commit is contained in:
Rajesh Taneja 2016-01-07 13:27:35 +10:00
parent 4aaa38e8fa
commit faea241337
3 changed files with 11 additions and 11 deletions

View File

@ -492,6 +492,9 @@ abstract class advanced_testcase extends base_testcase {
unset($user->access);
unset($user->preference);
// Enusre session is empty, as it may contain caches and user specific info.
\core\session\manager::init_empty_session();
\core\session\manager::set_user($user);
}

View File

@ -72,7 +72,9 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
}
public function test_set_user() {
global $USER, $DB;
global $USER, $DB, $SESSION;
$this->resetAfterTest();
$this->assertEquals(0, $USER->id);
$this->assertSame($_SESSION['USER'], $USER);
@ -109,6 +111,11 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
$this->assertEquals(0, $USER->id);
$this->assertSame($_SESSION['USER'], $USER);
$this->assertSame($GLOBALS['USER'], $USER);
// Ensure session is reset after setUser, as it may contain extra info.
$SESSION->sometestvalue = true;
$this->setUser($user);
$this->assertObjectNotHasAttribute('sometestvalue', $SESSION);
}
public function test_set_admin_user() {

View File

@ -2170,7 +2170,6 @@ class mod_forum_lib_testcase extends advanced_testcase {
}
public function test_print_overview_groups() {
global $SESSION;
$this->resetAfterTest();
$course1 = self::getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
@ -2220,10 +2219,6 @@ class mod_forum_lib_testcase extends advanced_testcase {
$this->assertCount(1, $results[$course1->id]);
$this->assertArrayHasKey('forum', $results[$course1->id]);
// As viewer2 (different group to post).
// Temporary hack to workaround for MDL-52656.
$SESSION->currentgroup = null;
$this->setUser($viewer2->id);
$results = array();
forum_print_overview($courses, $results);
@ -2290,7 +2285,6 @@ class mod_forum_lib_testcase extends advanced_testcase {
* @dataProvider print_overview_timed_provider
*/
public function test_print_overview_timed_groups($config, $hasresult) {
global $SESSION;
$this->resetAfterTest();
$course1 = self::getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course1->id));
@ -2351,10 +2345,6 @@ class mod_forum_lib_testcase extends advanced_testcase {
$this->assertCount(0, $results);
}
// As viewer2 (different group to post).
// Temporary hack to workaround for MDL-52656.
$SESSION->currentgroup = null;
$this->setUser($viewer2->id);
$results = array();
forum_print_overview($courses, $results);