weekly release 2.1dev
[moodle.git] / lib / simpletest / testnavigationlib.php
CommitLineData
7d2a0492 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Unit tests for lib/navigationlib.php
20 *
21 * @package moodlecore
22 * @copyright 2009 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later (5)
24 */
25
26if (!defined('MOODLE_INTERNAL')) {
27 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
28}
29require_once($CFG->libdir . '/navigationlib.php');
30
31class navigation_node_test extends UnitTestCase {
32 protected $tree;
33 public static $includecoverage = array('./lib/navigationlib.php');
34 public static $excludecoverage = array();
95b97515 35 protected $fakeproperties = array(
36 'text' => 'text',
37 'shorttext' => 'A very silly extra long short text string, more than 25 characters',
38 'key' => 'key',
39 'type' => 'navigation_node::TYPE_COURSE',
40 'action' => 'http://www.moodle.org/');
c705a24e 41 protected $activeurl = null;
42 protected $inactivenode = null;
7d2a0492 43
3406acde
SH
44 /**
45 * @var navigation_node
46 */
47 public $node;
48
7d2a0492 49 public function setUp() {
c705a24e 50 global $CFG, $PAGE;
7d2a0492 51 parent::setUp();
c705a24e 52
53 $this->activeurl = $PAGE->url;
460232f3
SH
54 navigation_node::override_active_url($this->activeurl);
55
c705a24e 56 $this->inactiveurl = new moodle_url('http://www.moodle.com/');
57 $this->fakeproperties['action'] = $this->inactiveurl;
58
7d2a0492 59 $this->node = new navigation_node('Test Node');
60 $this->node->type = navigation_node::TYPE_SYSTEM;
3406acde
SH
61 $demo1 = $this->node->add('demo1', $this->inactiveurl, navigation_node::TYPE_COURSE, null, 'demo1', new pix_icon('i/course', ''));
62 $demo2 = $this->node->add('demo2', $this->inactiveurl, navigation_node::TYPE_COURSE, null, 'demo2', new pix_icon('i/course', ''));
63 $demo3 = $this->node->add('demo3', $this->inactiveurl, navigation_node::TYPE_CATEGORY, null, 'demo3',new pix_icon('i/course', ''));
64 $demo4 = $demo3->add('demo4', $this->inactiveurl,navigation_node::TYPE_COURSE, null, 'demo4', new pix_icon('i/course', ''));
65 $demo5 = $demo3->add('demo5', $this->activeurl, navigation_node::TYPE_COURSE, null, 'demo5',new pix_icon('i/course', ''));
66 $demo5->add('activity1', null, navigation_node::TYPE_ACTIVITY, null, 'activity1')->make_active();
67 $hiddendemo1 = $this->node->add('hiddendemo1', $this->inactiveurl, navigation_node::TYPE_CATEGORY, null, 'hiddendemo1', new pix_icon('i/course', ''));
68 $hiddendemo1->hidden = true;
69 $hiddendemo1->add('hiddendemo2', $this->inactiveurl, navigation_node::TYPE_COURSE, null, 'hiddendemo2', new pix_icon('i/course', ''))->helpbutton = 'Here is a help button';;
70 $hiddendemo1->add('hiddendemo3', $this->inactiveurl, navigation_node::TYPE_COURSE,null, 'hiddendemo3', new pix_icon('i/course', ''))->display = false;
7d2a0492 71 }
8926f844 72
7d2a0492 73 public function test___construct() {
74 global $CFG;
95b97515 75 $node = new navigation_node($this->fakeproperties);
76 $this->assertEqual($node->text, $this->fakeproperties['text']);
77 $this->assertEqual($node->title, $this->fakeproperties['text']);
78 $this->assertTrue(strpos($this->fakeproperties['shorttext'], substr($node->shorttext,0, -3))===0);
79 $this->assertEqual($node->key, $this->fakeproperties['key']);
80 $this->assertEqual($node->type, $this->fakeproperties['type']);
81 $this->assertEqual($node->action, $this->fakeproperties['action']);
82 }
7d2a0492 83 public function test_add() {
84 global $CFG;
85 // Add a node with all args set
3406acde 86 $node1 = $this->node->add('test_add_1','http://www.moodle.org/',navigation_node::TYPE_COURSE,'testadd1','key',new pix_icon('i/course', ''));
7d2a0492 87 // Add a node with the minimum args required
3406acde
SH
88 $node2 = $this->node->add('test_add_2',null, navigation_node::TYPE_CUSTOM,'testadd2');
89 $node3 = $this->node->add(str_repeat('moodle ', 15),str_repeat('moodle', 15));
90
91 $this->assertIsA($node1, 'navigation_node');
92 $this->assertIsA($node2, 'navigation_node');
93 $this->assertIsA($node3, 'navigation_node');
94
95 $this->assertReference($node1, $this->node->get('key'));
96 $this->assertReference($node2, $this->node->get($node2->key));
97 $this->assertReference($node2, $this->node->get($node2->key, $node2->type));
98 $this->assertReference($node3, $this->node->get($node3->key, $node3->type));
7d2a0492 99 }
100
101 public function test_add_class() {
102 $node = $this->node->get('demo1');
103 $this->assertIsA($node, 'navigation_node');
104 if ($node !== false) {
105 $node->add_class('myclass');
106 $classes = $node->classes;
107 $this->assertTrue(in_array('myclass', $classes));
108 }
109 }
110
7d2a0492 111
112 public function test_check_if_active() {
7d2a0492 113 // First test the string urls
7d2a0492 114 // demo1 -> action is http://www.moodle.org/, thus should be true
3406acde
SH
115 $demo5 = $this->node->find('demo5', navigation_node::TYPE_COURSE);
116 if ($this->assertIsA($demo5, 'navigation_node')) {
117 $this->assertTrue($demo5->check_if_active());
118 }
119
7d2a0492 120 // demo2 -> action is http://www.moodle.com/, thus should be false
3406acde
SH
121 $demo2 = $this->node->get('demo2');
122 if ($this->assertIsA($demo2, 'navigation_node')) {
123 $this->assertFalse($demo2->check_if_active());
124 }
7d2a0492 125 }
126
127 public function test_contains_active_node() {
128 // demo5, and activity1 were set to active during setup
129 // Should be true as it contains all nodes
130 $this->assertTrue($this->node->contains_active_node());
131 // Should be true as demo5 is a child of demo3
132 $this->assertTrue($this->node->get('demo3')->contains_active_node());
133 // Obviously duff
134 $this->assertFalse($this->node->get('demo1')->contains_active_node());
135 // Should be true as demo5 contains activity1
136 $this->assertTrue($this->node->get('demo3')->get('demo5')->contains_active_node());
3406acde
SH
137 // Should be true activity1 is the active node
138 $this->assertTrue($this->node->get('demo3')->get('demo5')->get('activity1')->contains_active_node());
7d2a0492 139 // Obviously duff
140 $this->assertFalse($this->node->get('demo3')->get('demo4')->contains_active_node());
141 }
142
7d2a0492 143 public function test_find_active_node() {
144 $activenode1 = $this->node->find_active_node();
3406acde
SH
145 $activenode2 = $this->node->get('demo1')->find_active_node();
146
147 if ($this->assertIsA($activenode1, 'navigation_node')) {
148 $this->assertReference($activenode1, $this->node->get('demo3')->get('demo5')->get('activity1'));
7d2a0492 149 }
3406acde
SH
150
151 $this->assertNotA($activenode2, 'navigation_node');
7d2a0492 152 }
153
3406acde
SH
154 public function test_find() {
155 $node1 = $this->node->find('demo1', navigation_node::TYPE_COURSE);
156 $node2 = $this->node->find('demo5', navigation_node::TYPE_COURSE);
157 $node3 = $this->node->find('demo5', navigation_node::TYPE_CATEGORY);
158 $node4 = $this->node->find('demo0', navigation_node::TYPE_COURSE);
7d2a0492 159 $this->assertIsA($node1, 'navigation_node');
160 $this->assertIsA($node2, 'navigation_node');
161 $this->assertNotA($node3, 'navigation_node');
162 $this->assertNotA($node4, 'navigation_node');
163 }
164
7d2a0492 165 public function test_find_expandable() {
166 $expandable = array();
167 $this->node->find_expandable($expandable);
abaece1e
SH
168 $this->assertEqual(count($expandable), 4);
169 if (count($expandable) === 4) {
c755c874
SH
170 $name = $expandable[0]['key'];
171 $name .= $expandable[1]['key'];
172 $name .= $expandable[2]['key'];
173 $name .= $expandable[3]['key'];
abaece1e 174 $this->assertEqual($name, 'demo1demo2demo4hiddendemo2');
7d2a0492 175 }
176 }
177
178 public function test_get() {
179 $node1 = $this->node->get('demo1'); // Exists
180 $node2 = $this->node->get('demo4'); // Doesn't exist for this node
181 $node3 = $this->node->get('demo0'); // Doesn't exist at all
182 $node4 = $this->node->get(false); // Sometimes occurs in nature code
183 $this->assertIsA($node1, 'navigation_node');
184 $this->assertFalse($node2);
185 $this->assertFalse($node3);
186 $this->assertFalse($node4);
187 }
188
7d2a0492 189 public function test_get_css_type() {
190 $csstype1 = $this->node->get('demo3')->get_css_type();
191 $csstype2 = $this->node->get('demo3')->get('demo5')->get_css_type();
192 $this->node->get('demo3')->get('demo5')->type = 1000;
193 $csstype3 = $this->node->get('demo3')->get('demo5')->get_css_type();
194 $this->assertEqual($csstype1, 'type_category');
195 $this->assertEqual($csstype2, 'type_course');
196 $this->assertEqual($csstype3, 'type_unknown');
197 }
198
199 public function test_make_active() {
200 global $CFG;
3406acde
SH
201 $node1 = $this->node->add('active node 1', null, navigation_node::TYPE_CUSTOM, null, 'anode1');
202 $node2 = $this->node->add('active node 2', new moodle_url($CFG->wwwroot), navigation_node::TYPE_COURSE, null, 'anode2');
203 $node1->make_active();
204 $this->node->get('anode2')->make_active();
205 $this->assertTrue($node1->isactive);
206 $this->assertTrue($this->node->get('anode2')->isactive);
207 }
208 public function test_remove() {
209 $remove1 = $this->node->add('child to remove 1', null, navigation_node::TYPE_CUSTOM, null, 'remove1');
210 $remove2 = $this->node->add('child to remove 2', null, navigation_node::TYPE_CUSTOM, null, 'remove2');
211 $remove3 = $remove2->add('child to remove 3', null, navigation_node::TYPE_CUSTOM, null, 'remove3');
212
213 $this->assertIsA($remove1, 'navigation_node');
214 $this->assertIsA($remove2, 'navigation_node');
215 $this->assertIsA($remove3, 'navigation_node');
216
7d2a0492 217 $this->assertIsA($this->node->get('remove1'), 'navigation_node');
3406acde
SH
218 $this->assertIsA($this->node->get('remove2'), 'navigation_node');
219 $this->assertIsA($remove2->get('remove3'), 'navigation_node');
220
221 $this->assertTrue($remove1->remove());
222 $this->assertTrue($this->node->get('remove2')->remove());
223 $this->assertTrue($remove2->get('remove3')->remove());
224
225 $this->assertFalse($this->node->get('remove1'));
226 $this->assertFalse($this->node->get('remove2'));
7d2a0492 227 }
228 public function test_remove_class() {
229 $this->node->add_class('testclass');
230 $this->assertTrue($this->node->remove_class('testclass'));
231 $this->assertFalse(in_array('testclass', $this->node->classes));
232 }
7d2a0492 233}
234
235/**
236 * This is a dummy object that allows us to call protected methods within the
237 * global navigation class by prefixing the methods with `exposed_`
238 */
239class exposed_global_navigation extends global_navigation {
240 protected $exposedkey = 'exposed_';
abaece1e 241 public function __construct(moodle_page $page=null) {
3406acde 242 global $PAGE;
abaece1e
SH
243 if ($page === null) {
244 $page = $PAGE;
245 }
246 parent::__construct($page);
7d2a0492 247 $this->cache = new navigation_cache('simpletest_nav');
248 }
abaece1e 249 public function __call($method, $arguments) {
7d2a0492 250 if (strpos($method,$this->exposedkey) !== false) {
251 $method = substr($method, strlen($this->exposedkey));
252 }
253 if (method_exists($this, $method)) {
254 return call_user_func_array(array($this, $method), $arguments);
255 }
256 throw new coding_exception('You have attempted to access a method that does not exist for the given object '.$method, DEBUG_DEVELOPER);
257 }
abaece1e
SH
258 public function set_initialised() {
259 $this->initialised = true;
260 }
7d2a0492 261}
262
95b97515 263class mock_initialise_global_navigation extends global_navigation {
264
265 static $count = 1;
266
267 public function load_for_category() {
268 $this->add('load_for_category', null, null, null, 'initcall'.self::$count);
269 self::$count++;
270 return 0;
271 }
272
273 public function load_for_course() {
274 $this->add('load_for_course', null, null, null, 'initcall'.self::$count);
275 self::$count++;
276 return 0;
277 }
278
279 public function load_for_activity() {
280 $this->add('load_for_activity', null, null, null, 'initcall'.self::$count);
281 self::$count++;
282 return 0;
283 }
284
285 public function load_for_user() {
286 $this->add('load_for_user', null, null, null, 'initcall'.self::$count);
287 self::$count++;
288 return 0;
289 }
290}
291
7d2a0492 292class global_navigation_test extends UnitTestCase {
293 /**
294 * @var global_navigation
295 */
296 public $node;
297 protected $cache;
3b7a763c 298 protected $modinfo5 = 'O:6:"object":6:{s:8:"courseid";s:1:"5";s:6:"userid";s:1:"2";s:8:"sections";a:1:{i:0;a:1:{i:0;s:3:"288";}}s:3:"cms";a:1:{i:288;O:6:"object":17:{s:2:"id";s:3:"288";s:8:"instance";s:2:"19";s:6:"course";s:1:"5";s:7:"modname";s:5:"forum";s:4:"name";s:10:"News forum";s:7:"visible";s:1:"1";s:10:"sectionnum";s:1:"0";s:9:"groupmode";s:1:"0";s:10:"groupingid";s:1:"0";s:16:"groupmembersonly";s:1:"0";s:6:"indent";s:1:"0";s:10:"completion";s:1:"0";s:5:"extra";s:0:"";s:4:"icon";s:0:"";s:11:"uservisible";b:1;s:9:"modplural";s:6:"Forums";s:9:"available";b:1;}}s:9:"instances";a:1:{s:5:"forum";a:1:{i:19;R:8;}}s:6:"groups";N;}';
299 protected $coursesections5 = 'a:5:{i:0;O:8:"stdClass":6:{s:7:"section";s:1:"0";s:2:"id";s:2:"14";s:6:"course";s:1:"5";s:7:"summary";N;s:8:"sequence";s:3:"288";s:7:"visible";s:1:"1";}i:1;O:8:"stdClass":6:{s:7:"section";s:1:"1";s:2:"id";s:2:"97";s:6:"course";s:1:"5";s:7:"summary";s:0:"";s:8:"sequence";N;s:7:"visible";s:1:"1";}i:2;O:8:"stdClass":6:{s:7:"section";s:1:"2";s:2:"id";s:2:"98";s:6:"course";s:1:"5";s:7:"summary";s:0:"";s:8:"sequence";N;s:7:"visible";s:1:"1";}i:3;O:8:"stdClass":6:{s:7:"section";s:1:"3";s:2:"id";s:2:"99";s:6:"course";s:1:"5";s:7:"summary";s:0:"";s:8:"sequence";N;s:7:"visible";s:1:"1";}i:4;O:8:"stdClass":6:{s:7:"section";s:1:"4";s:2:"id";s:3:"100";s:6:"course";s:1:"5";s:7:"summary";s:0:"";s:8:"sequence";N;s:7:"visible";s:1:"1";}}';
7d2a0492 300 public static $includecoverage = array('./lib/navigationlib.php');
301 public static $excludecoverage = array();
8926f844 302
7d2a0492 303 public function setUp() {
304 $this->cache = new navigation_cache('simpletest_nav');
305 $this->node = new exposed_global_navigation();
306 // Create an initial tree structure to work with
3406acde
SH
307 $cat1 = $this->node->add('category 1', null, navigation_node::TYPE_CATEGORY, null, 'cat1');
308 $cat2 = $this->node->add('category 2', null, navigation_node::TYPE_CATEGORY, null, 'cat2');
309 $cat3 = $this->node->add('category 3', null, navigation_node::TYPE_CATEGORY, null, 'cat3');
310 $sub1 = $cat2->add('sub category 1', null, navigation_node::TYPE_CATEGORY, null, 'sub1');
311 $sub2 = $cat2->add('sub category 2', null, navigation_node::TYPE_CATEGORY, null, 'sub2');
312 $sub3 = $cat2->add('sub category 3', null, navigation_node::TYPE_CATEGORY, null, 'sub3');
313 $course1 = $sub2->add('course 1', null, navigation_node::TYPE_COURSE, null, 'course1');
314 $course2 = $sub2->add('course 2', null, navigation_node::TYPE_COURSE, null, 'course2');
315 $course3 = $sub2->add('course 3', null, navigation_node::TYPE_COURSE, null, 'course3');
316 $section1 = $course2->add('section 1', null, navigation_node::TYPE_COURSE, null, 'sec1');
317 $section2 = $course2->add('section 2', null, navigation_node::TYPE_COURSE, null, 'sec2');
318 $section3 = $course2->add('section 3', null, navigation_node::TYPE_COURSE, null, 'sec3');
319 $act1 = $section2->add('activity 1', null, navigation_node::TYPE_ACTIVITY, null, 'act1');
320 $act2 = $section2->add('activity 2', null, navigation_node::TYPE_ACTIVITY, null, 'act2');
321 $act3 = $section2->add('activity 3', null, navigation_node::TYPE_ACTIVITY, null, 'act3');
322 $res1 = $section2->add('resource 1', null, navigation_node::TYPE_RESOURCE, null, 'res1');
323 $res2 = $section2->add('resource 2', null, navigation_node::TYPE_RESOURCE, null, 'res2');
324 $res3 = $section2->add('resource 3', null, navigation_node::TYPE_RESOURCE, null, 'res3');
7d2a0492 325
326 $this->cache->clear();
3b7a763c 327 $this->cache->modinfo5 = unserialize($this->modinfo5);
328 $this->cache->coursesections5 = unserialize($this->coursesections5);
7d2a0492 329 $this->cache->canviewhiddenactivities = true;
330 $this->cache->canviewhiddensections = true;
331 $this->cache->canviewhiddencourses = true;
3406acde 332 $sub2->add('Test Course 5', new moodle_url('http://moodle.org'),navigation_node::TYPE_COURSE,null,'5');
7d2a0492 333 }
3406acde
SH
334 public function test_load_generic_course_sections() {
335 $coursenode = $this->node->find('5', navigation_node::TYPE_COURSE);
7d2a0492 336 $course = new stdClass;
337 $course->id = '5';
3b7a763c 338 $course->numsections = 10;
339 $course->modinfo = $this->modinfo5;
3406acde 340 $this->node->load_generic_course_sections($course, $coursenode, 'topic', 'topic');
abaece1e 341 $this->assertEqual($coursenode->children->count(),1);
7d2a0492 342 }
343 public function test_format_display_course_content() {
344 $this->assertTrue($this->node->exposed_format_display_course_content('topic'));
345 $this->assertFalse($this->node->exposed_format_display_course_content('scorm'));
346 $this->assertTrue($this->node->exposed_format_display_course_content('dummy'));
347 }
7d2a0492 348 public function test_module_extends_navigation() {
349 $this->cache->test1_extends_navigation = true;
350 $this->cache->test2_extends_navigation = false;
47379255 351 $this->assertTrue($this->node->exposed_module_extends_navigation('data'));
7d2a0492 352 $this->assertTrue($this->node->exposed_module_extends_navigation('test1'));
353 $this->assertFalse($this->node->exposed_module_extends_navigation('test2'));
354 $this->assertFalse($this->node->exposed_module_extends_navigation('test3'));
355 }
356}
357
358/**
359 * This is a dummy object that allows us to call protected methods within the
360 * global navigation class by prefixing the methods with `exposed_`
361 */
362class exposed_navbar extends navbar {
363 protected $exposedkey = 'exposed_';
abaece1e
SH
364 public function __construct(moodle_page $page) {
365 parent::__construct($page);
7d2a0492 366 $this->cache = new navigation_cache('simpletest_nav');
367 }
368 function __call($method, $arguments) {
369 if (strpos($method,$this->exposedkey) !== false) {
370 $method = substr($method, strlen($this->exposedkey));
371 }
372 if (method_exists($this, $method)) {
373 return call_user_func_array(array($this, $method), $arguments);
374 }
375 throw new coding_exception('You have attempted to access a method that does not exist for the given object '.$method, DEBUG_DEVELOPER);
376 }
377}
378
abaece1e
SH
379class navigation_exposed_moodle_page extends moodle_page {
380 public function set_navigation(navigation_node $node) {
381 $this->_navigation = $node;
382 }
383}
384
7d2a0492 385class navbar_test extends UnitTestCase {
386 protected $node;
387 protected $oldnav;
388
389 public static $includecoverage = array('./lib/navigationlib.php');
390 public static $excludecoverage = array();
391
392 public function setUp() {
393 global $PAGE;
abaece1e 394
7d2a0492 395 $temptree = new global_navigation_test();
396 $temptree->setUp();
3406acde 397 $temptree->node->find('course2', navigation_node::TYPE_COURSE)->make_active();
abaece1e
SH
398
399 $page = new navigation_exposed_moodle_page();
400 $page->set_url($PAGE->url);
401 $page->set_context($PAGE->context);
402
403 $navigation = new exposed_global_navigation($page);
404 $navigation->children = $temptree->node->children;
405 $navigation->set_initialised();
406 $page->set_navigation($navigation);
407
408 $this->cache = new navigation_cache('simpletest_nav');
409 $this->node = new exposed_navbar($page);
7d2a0492 410 }
411 public function test_add() {
7d2a0492 412 // Add a node with all args set
a3bbac8b 413 $this->node->add('test_add_1','http://www.moodle.org/',navigation_node::TYPE_COURSE,'testadd1','testadd1',new pix_icon('i/course', ''));
7d2a0492 414 // Add a node with the minimum args required
3406acde 415 $this->node->add('test_add_2','http://www.moodle.org/',navigation_node::TYPE_COURSE,'testadd2','testadd2',new pix_icon('i/course', ''));
7d2a0492 416 $this->assertIsA($this->node->get('testadd1'), 'navigation_node');
3406acde 417 $this->assertIsA($this->node->get('testadd2'), 'navigation_node');
7d2a0492 418 }
419 public function test_has_items() {
7d2a0492 420 $this->assertTrue($this->node->has_items());
7d2a0492 421 }
7d2a0492 422}
423
424class navigation_cache_test extends UnitTestCase {
425 protected $cache;
426
427 public static $includecoverage = array('./lib/navigationlib.php');
428 public static $excludecoverage = array();
429
430 public function setUp() {
431 $this->cache = new navigation_cache('simpletest_nav');
432 $this->cache->anysetvariable = true;
433 }
434 public function test___get() {
435 $this->assertTrue($this->cache->anysetvariable);
436 $this->assertEqual($this->cache->notasetvariable, null);
437 }
438 public function test___set() {
439 $this->cache->myname = 'Sam Hemelryk';
440 $this->assertTrue($this->cache->cached('myname'));
441 $this->assertEqual($this->cache->myname, 'Sam Hemelryk');
442 }
443 public function test_cached() {
444 $this->assertTrue($this->cache->cached('anysetvariable'));
445 $this->assertFalse($this->cache->cached('notasetvariable'));
446 }
447 public function test_clear() {
448 $cache = clone($this->cache);
449 $this->assertTrue($cache->cached('anysetvariable'));
450 $cache->clear();
451 $this->assertFalse($cache->cached('anysetvariable'));
452 }
453 public function test_set() {
454 $this->cache->set('software', 'Moodle');
455 $this->assertTrue($this->cache->cached('software'));
456 $this->assertEqual($this->cache->software, 'Moodle');
457 }
458}
459
460/**
461 * This is a dummy object that allows us to call protected methods within the
462 * global navigation class by prefixing the methods with `exposed_`
463 */
464class exposed_settings_navigation extends settings_navigation {
465 protected $exposedkey = 'exposed_';
466 function __construct() {
467 global $PAGE;
468 parent::__construct($PAGE);
469 $this->cache = new navigation_cache('simpletest_nav');
470 }
471 function __call($method, $arguments) {
472 if (strpos($method,$this->exposedkey) !== false) {
473 $method = substr($method, strlen($this->exposedkey));
474 }
475 if (method_exists($this, $method)) {
476 return call_user_func_array(array($this, $method), $arguments);
477 }
478 throw new coding_exception('You have attempted to access a method that does not exist for the given object '.$method, DEBUG_DEVELOPER);
479 }
480}
481
482class settings_navigation_test extends UnitTestCase {
483 protected $node;
484 protected $cache;
485
486 public static $includecoverage = array('./lib/navigationlib.php');
487 public static $excludecoverage = array();
488
489 public function setUp() {
490 global $PAGE;
491 $this->cache = new navigation_cache('simpletest_nav');
492 $this->node = new exposed_settings_navigation();
493 }
494 public function test___construct() {
495 $this->node = new exposed_settings_navigation();
496 }
497 public function test___initialise() {
498 $this->node->initialise();
499 $this->assertEqual($this->node->id, 'settingsnav');
500 }
7d2a0492 501 public function test_in_alternative_role() {
502 $this->assertFalse($this->node->exposed_in_alternative_role());
503 }
95b97515 504}