mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-53383 navigation: Do not require $type in remove()
navigation_node_collection -> remove function broken when $type is null
This commit is contained in:
parent
fed66ad9e2
commit
eb9a3e9379
@ -923,7 +923,7 @@ class navigation_node_collection implements IteratorAggregate {
|
||||
$child = $this->get($key, $type);
|
||||
if ($child !== false) {
|
||||
foreach ($this->collection as $colkey => $node) {
|
||||
if ($node->key === $key && $node->type == $type) {
|
||||
if ($node->key === $key && (is_null($type) || $node->type == $type)) {
|
||||
unset($this->collection[$colkey]);
|
||||
$this->collection = array_values($this->collection);
|
||||
break;
|
||||
|
@ -499,6 +499,49 @@ class core_navigationlib_testcase extends advanced_testcase {
|
||||
|
||||
$this->assertFalse($node->exposed_in_alternative_role());
|
||||
}
|
||||
|
||||
|
||||
public function test_navigation_node_collection_remove_with_no_type() {
|
||||
$navigationnodecollection = new navigation_node_collection();
|
||||
$this->setup_node();
|
||||
$this->node->key = 100;
|
||||
|
||||
// Test it's empty
|
||||
$this->assertEquals(0, count($navigationnodecollection->get_key_list()));
|
||||
|
||||
// Add a node
|
||||
$navigationnodecollection->add($this->node);
|
||||
|
||||
// Test it's not empty
|
||||
$this->assertEquals(1, count($navigationnodecollection->get_key_list()));
|
||||
|
||||
// Remove a node - passing key only!
|
||||
$this->assertTrue($navigationnodecollection->remove(100));
|
||||
|
||||
// Test it's empty again!
|
||||
$this->assertEquals(0, count($navigationnodecollection->get_key_list()));
|
||||
}
|
||||
|
||||
public function test_navigation_node_collection_remove_with_type() {
|
||||
$navigationnodecollection = new navigation_node_collection();
|
||||
$this->setup_node();
|
||||
$this->node->key = 100;
|
||||
|
||||
// Test it's empty
|
||||
$this->assertEquals(0, count($navigationnodecollection->get_key_list()));
|
||||
|
||||
// Add a node
|
||||
$navigationnodecollection->add($this->node);
|
||||
|
||||
// Test it's not empty
|
||||
$this->assertEquals(1, count($navigationnodecollection->get_key_list()));
|
||||
|
||||
// Remove a node - passing type
|
||||
$this->assertTrue($navigationnodecollection->remove(100, 1));
|
||||
|
||||
// Test it's empty again!
|
||||
$this->assertEquals(0, count($navigationnodecollection->get_key_list()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user