Skip to content
Permalink
Browse files

MDL-52656 unittest: Reset original session while setting user

  • Loading branch information...
rajeshtaneja committed Jan 7, 2016
1 parent 4aaa38e commit faea241337ff2f81f5ef69864744e4eb7749977c
Showing with 11 additions and 11 deletions.
  1. +3 −0 lib/phpunit/classes/advanced_testcase.php
  2. +8 −1 lib/phpunit/tests/advanced_test.php
  3. +0 −10 mod/forum/tests/lib_test.php
@@ -492,6 +492,9 @@ public static function setUser($user = null) {
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);
}
@@ -72,7 +72,9 @@ public function test_debugging() {
}
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 @@ public function test_set_user() {
$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() {
@@ -2170,7 +2170,6 @@ public function test_print_overview() {
}
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 @@ public function test_print_overview_groups() {
$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 @@ public function test_print_overview_timed($config, $hasresult) {
* @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 @@ public function test_print_overview_timed_groups($config, $hasresult) {
$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);

0 comments on commit faea241

Please sign in to comment.
You can’t perform that action at this time.