From 4f8af9cbdf19aefe95f93fe879efca07dc3be4e6 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 31 May 2013 11:48:32 +1000 Subject: [PATCH] MDL-39801 navigation_node::remove does not allow to insert nodes afterwards --- lib/navigationlib.php | 1 + lib/tests/navigationlib_test.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/navigationlib.php b/lib/navigationlib.php index 9266975b143..b364a5534da 100644 --- a/lib/navigationlib.php +++ b/lib/navigationlib.php @@ -891,6 +891,7 @@ class navigation_node_collection implements IteratorAggregate { foreach ($this->collection as $colkey => $node) { if ($node->key === $key && $node->type == $type) { unset($this->collection[$colkey]); + $this->collection = array_values($this->collection); break; } } diff --git a/lib/tests/navigationlib_test.php b/lib/tests/navigationlib_test.php index 1c046ceb40a..473b6599ea2 100644 --- a/lib/tests/navigationlib_test.php +++ b/lib/tests/navigationlib_test.php @@ -258,9 +258,19 @@ class navigation_node_testcase extends basic_testcase { $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'));