Skip to content

Commit

Permalink
MDL-26229 restore - prevent tag-conflicting structures to be created
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Feb 12, 2011
1 parent 5539e69 commit 945962a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions backup/util/structure/base_nested_element.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ protected function add_used($element) {
}

protected function check_and_set_used($element) {
// First of all, check the element being added doesn't conflict with own final elements
if (array_key_exists($element->get_name(), $this->final_elements)) {
throw new base_element_struct_exception('baseelementchildnameconflict', $element->get_name());
}
$grandparent = $this->get_grandoptigroupelement_or_grandparent();
if ($existing = array_intersect($grandparent->get_used(), $element->get_used())) { // Check the element isn't being used already
throw new base_element_struct_exception('baseelementexisting', implode($existing));
Expand Down
11 changes: 11 additions & 0 deletions backup/util/structure/simpletest/testbasenestedelement.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,16 @@ function test_wrong_tree() {
$this->assertTrue($e instanceof base_element_parent_exception);
}

// Add child element already used by own final elements
$nested = new mock_base_nested_element('PARENT1', null, array('FINAL1', 'FINAL2'));
$child = new mock_base_nested_element('FINAL2', null, array('FINAL3', 'FINAL4'));
try {
$nested->add_child($child);
$this->fail("Expecting base_element_struct_exception exception, none occurred");
} catch (Exception $e) {
$this->assertTrue($e instanceof base_element_struct_exception);
$this->assertEqual($e->errorcode, 'baseelementchildnameconflict');
$this->assertEqual($e->a, 'FINAL2');
}
}
}

0 comments on commit 945962a

Please sign in to comment.