Permalink
Browse files

MDL-26229 restore - prevent tag-conflicting structures to be created

  • Loading branch information...
1 parent 5539e69 commit 945962a45d1b4202b30fef1f6b8aa38b952c4cc3 @stronk7 stronk7 committed Feb 12, 2011
@@ -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));
@@ -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.