]> git.mjollnir.org Git - moodle.git/commitdiff
unittests: NOBUG fix pagelib unit tests
authortjhunt <tjhunt>
Wed, 30 Sep 2009 16:24:05 +0000 (16:24 +0000)
committertjhunt <tjhunt>
Wed, 30 Sep 2009 16:24:05 +0000 (16:24 +0000)
lib/blocklib.php
lib/outputlib.php
lib/simpletest/testpagelib_moodlepage.php

index 3d203ec49e3ede30372615d8c06405c8c1bd9d1b..9c3a0f64650850e220bda865b2499367b79be684 100644 (file)
@@ -167,7 +167,9 @@ class block_manager {
      * @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);
     }
 
@@ -399,6 +401,7 @@ class block_manager {
      */
     public function load_blocks($includeinvisible = null) {
         global $DB, $CFG;
+
         if (!is_null($this->birecordsbyregion)) {
             // Already done.
             return;
@@ -411,7 +414,7 @@ class block_manager {
         }
 
         // 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)) {
index 6a8e05fb892f71413f3c650a99ae3b1c9a2af3d4..6a928530520055ab8637e3db57256eab71f26ae4 100644 (file)
@@ -611,6 +611,8 @@ class theme_config {
         if (!empty($layoutinfo['regions'])) {
             $blockmanager->add_regions($layoutinfo['regions']);
             $blockmanager->set_default_region($layoutinfo['defaultregion']);
+        } else {
+               $blockmanager->set_default_region('');
         }
     }
 
index 4620fa22cac4a55766ddaf41560009b28f834da1..affa5ff6c560f487a3fd94c60ceb85ce33fa0e58 100644 (file)
@@ -56,20 +56,21 @@ class testable_moodle_page extends moodle_page {
 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. */
@@ -110,20 +111,33 @@ class moodle_page_test extends UnitTestCase {
         $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();
@@ -131,9 +145,9 @@ class moodle_page_test extends UnitTestCase {
         $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
@@ -162,7 +176,10 @@ class moodle_page_test extends UnitTestCase {
     }
 
     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);
@@ -187,6 +204,9 @@ class moodle_page_test extends UnitTestCase {
     }
 
     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);