require_once($CFG->dirroot.'/course/lib.php');
- $modinfo = get_fast_modinfo($course);
- $sections = array_slice(get_all_sections($course->id), 0, $course->numsections+1, true);
+ if (!$this->cache->cached('modinfo'.$course->id)) {
+ $this->cache->set('modinfo'.$course->id, get_fast_modinfo($course));
+ }
+ $modinfo = $this->cache->{'modinfo'.$course->id};
+
+ if (!$this->cache->cached('coursesections'.$course->id)) {
+ $this->cache->set('coursesections'.$course->id, array_slice(get_all_sections($course->id), 0, $course->numsections+1, true));
+ }
+ $sections = $this->cache->{'coursesections'.$course->id};
+
$viewhiddensections = has_capability('moodle/course:viewhiddensections', $this->page->context);
if (isloggedin() && !isguestuser()) {
public function test_find_expandable() {
$expandable = array();
$this->node->find_expandable($expandable);
- $this->assertEqual(count($expandable), 5);
- if (count($expandable) === 5) {
+ $this->assertEqual(count($expandable), 4);
+ if (count($expandable) === 4) {
$name = $expandable[0]['branchid'];
$name .= $expandable[1]['branchid'];
$name .= $expandable[2]['branchid'];
$name .= $expandable[3]['branchid'];
- $name .= $expandable[4]['branchid'];
- $this->assertEqual($name, 'demo1demo2demo4hiddendemo2hiddendemo3');
+ $this->assertEqual($name, 'demo1demo2demo4hiddendemo2');
}
}
*/
class exposed_global_navigation extends global_navigation {
protected $exposedkey = 'exposed_';
- function __construct() {
+ public function __construct(moodle_page $page=null) {
global $PAGE;
- parent::__construct($PAGE);
+ if ($page === null) {
+ $page = $PAGE;
+ }
+ parent::__construct($page);
$this->cache = new navigation_cache('simpletest_nav');
}
- function __call($method, $arguments) {
+ public function __call($method, $arguments) {
if (strpos($method,$this->exposedkey) !== false) {
$method = substr($method, strlen($this->exposedkey));
}
}
throw new coding_exception('You have attempted to access a method that does not exist for the given object '.$method, DEBUG_DEVELOPER);
}
+ public function set_initialised() {
+ $this->initialised = true;
+ }
}
class mock_initialise_global_navigation extends global_navigation {
$course->numsections = 10;
$course->modinfo = $this->modinfo5;
$this->node->load_generic_course_sections($course, $coursenode, 'topic', 'topic');
- $this->assertEqual($coursenode->children->count(),4);
+ $this->assertEqual($coursenode->children->count(),1);
}
public function test_format_display_course_content() {
$this->assertTrue($this->node->exposed_format_display_course_content('topic'));
*/
class exposed_navbar extends navbar {
protected $exposedkey = 'exposed_';
- function __construct() {
- global $PAGE;
- parent::__construct($PAGE);
+ public function __construct(moodle_page $page) {
+ parent::__construct($page);
$this->cache = new navigation_cache('simpletest_nav');
}
function __call($method, $arguments) {
}
}
+class navigation_exposed_moodle_page extends moodle_page {
+ public function set_navigation(navigation_node $node) {
+ $this->_navigation = $node;
+ }
+}
+
class navbar_test extends UnitTestCase {
protected $node;
protected $oldnav;
public function setUp() {
global $PAGE;
- $this->oldnav = $PAGE->navigation;
- $this->cache = new navigation_cache('simpletest_nav');
- $this->node = new exposed_navbar();
+
$temptree = new global_navigation_test();
$temptree->setUp();
$temptree->node->find('course2', navigation_node::TYPE_COURSE)->make_active();
- $PAGE->navigation = $temptree->node;
- }
- public function tearDown() {
- global $PAGE;
- $PAGE->navigation = $this->oldnav;
+
+ $page = new navigation_exposed_moodle_page();
+ $page->set_url($PAGE->url);
+ $page->set_context($PAGE->context);
+
+ $navigation = new exposed_global_navigation($page);
+ $navigation->children = $temptree->node->children;
+ $navigation->set_initialised();
+ $page->set_navigation($navigation);
+
+ $this->cache = new navigation_cache('simpletest_nav');
+ $this->node = new exposed_navbar($page);
}
public function test_add() {
- global $CFG;
// Add a node with all args set
$this->node->add('test_add_1','http://www.moodle.org/',navigation_node::TYPE_COURSE,'testadd1','testadd1',new pix_icon('i/course', ''));
// Add a node with the minimum args required
$this->assertIsA($this->node->get('testadd2'), 'navigation_node');
}
public function test_has_items() {
- global $PAGE;
$this->assertTrue($this->node->has_items());
}
}