From 3d97797bdb098a1c2a7fc5b5bd60a812685a5bae Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Mon, 26 Oct 2009 06:08:47 +0000 Subject: [PATCH] navigation MDL-20543 Fixed remove_child and simpletests --- lib/navigationlib.php | 9 ++++++--- lib/simpletest/testnavigationlib.php | 9 +++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 2938df4b9b..ede1fef348 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -749,11 +749,14 @@ class navigation_node { * @param string|int $key The key that identifies a child node * @return bool */ - public function remove_child($key) { - if (array_key_exists($key, $this->children)) { - unset($this->children[$key]); + public function remove_child($key, $type=null) { + $child = $this->get($key, $type); + + if ($child) { + unset($this->children[$child->key]); return true; } + return false; } diff --git a/lib/simpletest/testnavigationlib.php b/lib/simpletest/testnavigationlib.php index 979a43204f..b29e1946ec 100644 --- a/lib/simpletest/testnavigationlib.php +++ b/lib/simpletest/testnavigationlib.php @@ -84,7 +84,7 @@ class navigation_node_test extends UnitTestCase { // Add a node with the minimum args required $key2 = $this->node->add('test_add_2',null, navigation_node::TYPE_CUSTOM,'testadd2'); $key3 = $this->node->add(str_repeat('moodle ', 15),str_repeat('moodle', 15)); - $this->assertEqual('key',$key1); + $this->assertEqual('key:'.navigation_node::TYPE_COURSE,$key1); $this->assertEqual($key2, $this->node->get($key2)->key); $this->assertEqual($key3, $this->node->get($key3)->key); $this->assertIsA($this->node->get('key'), 'navigation_node'); @@ -106,7 +106,7 @@ class navigation_node_test extends UnitTestCase { global $CFG; $path = array('demo3','demo5'); $key1 = $this->node->add_to_path($path,'testatp1', 'Test add to path 1', 'testatp1', navigation_node::TYPE_COURSE, 'http://www.moodle.org/', $CFG->httpswwwroot . '/pix/i/course.gif'); - $this->assertEqual($key1, 'testatp1'); + $this->assertEqual($key1, 'testatp1:'.navigation_node::TYPE_COURSE); // This should generate an exception as we have not provided any text for // the node @@ -157,7 +157,8 @@ class navigation_node_test extends UnitTestCase { $content5 = $this->node->get('hiddendemo1')->get('hiddendemo3')->content(); $this->assert(new ContainsTagWithAttribute('a','href',$this->node->get('demo1')->action->out()), $content1); $this->assert(new ContainsTagWithAttribute('a','href',$this->node->get('demo3')->action->out()), $content2); - $this->assertEqual($content3, 'A fake help buttondemo5'); + $this->assert(new ContainsTagWithAttribute('span','class','dimmed_text'), $content3); + #$this->assertEqual($content3, 'A fake help buttondemo5'); $this->assert(new ContainsTagWithAttribute('a','href',$this->node->get('hiddendemo1')->get('hiddendemo2')->action->out()), $content4); $this->assertTrue(empty($content5)); } @@ -221,7 +222,7 @@ class navigation_node_test extends UnitTestCase { $name .= $expandable[2]['branchid']; $name .= $expandable[3]['branchid']; $name .= $expandable[4]['branchid']; - $this->assertEqual($name, 'demo1demo2demo4hiddendemo2hiddendemo3'); + $this->assertEqual($name, 'demo1:20demo2:20demo4:20hiddendemo2:20hiddendemo3:20'); } } -- 2.39.5