Permalink
Browse files

MDL-39801 navigation_node::remove does not allow to insert nodes afte…

…rwards
  • Loading branch information...
1 parent bd205fa commit a74edf03ad933d8ab3696a6369752546fad9893c @marinaglancy marinaglancy committed May 31, 2013
Showing with 11 additions and 0 deletions.
  1. +1 −0 lib/navigationlib.php
  2. +10 −0 lib/tests/navigationlib_test.php
View
1 lib/navigationlib.php
@@ -901,6 +901,7 @@ public function remove($key, $type=null) {
foreach ($this->collection as $colkey => $node) {
if ($node->key === $key && $node->type == $type) {
unset($this->collection[$colkey]);
+ $this->collection = array_values($this->collection);
break;
}
}
View
10 lib/tests/navigationlib_test.php
@@ -258,9 +258,19 @@ public function test_remove() {
$this->assertFalse($this->node->get('remove1'));
$this->assertFalse(in_array('remove1', $this->node->get_children_key_list(), true));
+ // Make sure that we can insert element after removal
+ $insertelement = navigation_node::create('extra element 4', null, navigation_node::TYPE_CUSTOM, null, 'element4');
+ $this->node->add_node($insertelement, 'remove2');
+ $this->assertNotEmpty($this->node->get('element4'));
+
// Remove more elements
$this->assertTrue($this->node->get('remove2')->remove());
$this->assertFalse($this->node->get('remove2'));
+
+ // Make sure that we can add element after removal
+ $this->node->add('extra element 5', null, navigation_node::TYPE_CUSTOM, null, 'element5');
+ $this->assertNotEmpty($this->node->get('element5'));
+
$this->assertTrue($remove2->get('remove3')->remove());
$this->assertFalse($this->node->get('remove1'));

0 comments on commit a74edf0

Please sign in to comment.