]> git.mjollnir.org Git - moodle.git/commitdiff
navigation MDL-20543 Fixed remove_child and simpletests
authorSam Hemelryk <sam@moodle.com>
Mon, 26 Oct 2009 06:08:47 +0000 (06:08 +0000)
committerSam Hemelryk <sam@moodle.com>
Mon, 26 Oct 2009 06:08:47 +0000 (06:08 +0000)
lib/navigationlib.php
lib/simpletest/testnavigationlib.php

index 2938df4b9b752a66e7f9fb057711a33ac040e848..ede1fef348a500f807e0a4b57bcf1c409d6150bd 100644 (file)
@@ -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;
     }
 
index 979a43204f89f048e9fc81da9627514ee10b7ee6..b29e1946ec2ef2fb38e835d777ddce14f39f1b5c 100644 (file)
@@ -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 button<span class="clearhelpbutton"><span class="dimmed_text" title="This is a title">demo5</span></span>');
+        $this->assert(new ContainsTagWithAttribute('span','class','dimmed_text'), $content3);
+        #$this->assertEqual($content3, 'A fake help button<span class="clearhelpbutton"><span class="dimmed_text" title="This is a title">demo5</span></span>');
         $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');
         }
     }