* @return array the internal names of the regions on this page where block may appear.
*/
public function get_regions() {
- $this->page->initialise_theme_and_output();
+ if (is_null($this->defaultregion)) {
+ $this->page->initialise_theme_and_output();
+ }
return array_keys($this->regions);
}
*/
public function load_blocks($includeinvisible = null) {
global $DB, $CFG;
+
if (!is_null($this->birecordsbyregion)) {
// Already done.
return;
}
// Ensure we have been initialised.
- if (!isset($this->defaultregion)) {
+ if (is_null($this->defaultregion)) {
$this->page->initialise_theme_and_output();
// If there are still no block regions, then there are no blocks on this page.
if (empty($this->regions)) {
class moodle_page_test extends UnitTestCase {
protected $testpage;
protected $originalcourse;
+ protected $originalpage;
public static $includecoverage = array('lib/pagelib.php', 'lib/blocklib.php');
public function setUp() {
- global $COURSE;
+ global $COURSE, $PAGE;
$this->originalcourse = $COURSE;
+ $this->originalpage = $PAGE;
$this->testpage = new testable_moodle_page();
- $this->testpage->blocks->add_regions(array('side-pre', 'side-post'));
- $this->testpage->blocks->set_default_region('side-post');
}
public function tearDown() {
global $COURSE;
$this->testpage = NULL;
$COURSE = $this->originalcourse;
+ $PAGE = $this->originalpage;
}
/** Creates an object with all the fields you would expect a $course object to have. */
$this->assert(new CheckSpecifiedFieldsExpectation($course), $this->testpage->course);
}
- public function test_global_course_and_page_course_are_same() {
- global $COURSE;
+ public function test_global_course_and_page_course_are_same_with_global_page() {
+ global $COURSE, $PAGE;
// Setup fixture
$course = $this->create_a_course();
$this->testpage->set_context(new stdClass); // Avoid trying to set the context.
+ $PAGE = $this->testpage;
// Exercise SUT
$this->testpage->set_course($course);
// Validate
$this->assertIdentical($this->testpage->course, $COURSE);
}
- public function test_cannot_set_course_once_output_started() {
+ public function test_global_course_not_changed_with_non_global_page() {
+ global $COURSE;
+ $originalcourse = $COURSE;
// Setup fixture
- $this->testpage->set_state(moodle_page::STATE_PRINTING_HEADER);
+ $course = $this->create_a_course();
+ $this->testpage->set_context(new stdClass); // Avoid trying to set the context.
+ // Exercise SUT
+ $this->testpage->set_course($course);
+ // Validate
+ $this->assertIdentical($originalcourse, $COURSE);
+ }
+
+ public function test_cannot_set_course_once_theme_set() {
+ // Setup fixture
+ $this->testpage->force_theme('standard');
$course = $this->create_a_course();
// Set expectation.
$this->expectException();
$this->testpage->set_course($course);
}
- public function test_cannot_set_category_once_output_started() {
+ public function test_cannot_set_category_once_theme_set() {
// Setup fixture
- $this->testpage->set_state(moodle_page::STATE_PRINTING_HEADER);
+ $this->testpage->force_theme('standard');
// Set expectation.
$this->expectException();
// Exercise SUT
}
public function test_set_state_normal_path() {
- $this->assertEqual(moodle_page::STATE_BEFORE_HEADER, $this->testpage->state);
+ $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM));
+ $this->testpage->set_course($this->create_a_course());
+
+ $this->assertEqual(moodle_page::STATE_BEFORE_HEADER, $this->testpage->state);
$this->testpage->set_state(moodle_page::STATE_PRINTING_HEADER);
$this->assertEqual(moodle_page::STATE_PRINTING_HEADER, $this->testpage->state);
}
public function test_header_printed_becomes_true() {
+ $this->testpage->set_context(get_context_instance(CONTEXT_SYSTEM));
+ $this->testpage->set_course($this->create_a_course());
+
// Exercise SUT
$this->testpage->set_state(moodle_page::STATE_PRINTING_HEADER);
$this->testpage->set_state(moodle_page::STATE_IN_BODY);