From f50243edefe86df344f16814bf671b42cb3a5eae Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Wed, 13 Jul 2011 13:44:45 +0800 Subject: [PATCH] MDL-28137 unit tests: Fixed up problem with block manager tests when running unit tests after turning editing on --- lib/simpletest/testblocklib_blockmanager.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/simpletest/testblocklib_blockmanager.php b/lib/simpletest/testblocklib_blockmanager.php index be448619c2a..3d4b292f2dd 100644 --- a/lib/simpletest/testblocklib_blockmanager.php +++ b/lib/simpletest/testblocklib_blockmanager.php @@ -159,13 +159,28 @@ class moodle_block_manager_test extends UnitTestCase { */ class moodle_block_manager_test_saving_loading extends UnitTestCaseUsingDatabase { + protected $isediting = null; + public function setUp() { + global $USER; + if (!empty($USER->editing)) { + // We want to avoid the capability checks associated with + // checking the user is editing. + $this->isediting = $USER->editing; + unset($USER->editing); + } parent::setUp(); $this->create_test_tables(array('block', 'block_instances', 'block_positions', 'context'), 'lib'); $this->switch_to_test_db(); } public function tearDown() { + global $USER; + if (!empty($this->isediting)) { + // Replace $USER->editing as it was there at setup. + $USER->editing = $this->isediting; + $this->isediting = null; + } parent::tearDown(); } -- 2.43.0