Esempio n. 1
0
 /**
  * Incorrect tree tests (children stuff)
  */
 function test_wrong_tree()
 {
     // Add null object child
     $parent = new mock_base_nested_element('PARENT');
     $child = null;
     try {
         $parent->add_child($child);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add non base_element object child
     $parent = new mock_base_nested_element('PARENT');
     $child = new stdClass();
     try {
         $parent->add_child($child);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add existing element (being parent)
     $parent = new mock_base_nested_element('PARENT');
     $child = new mock_base_nested_element('PARENT');
     try {
         $parent->add_child($child);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add existing element (being grandparent)
     $grandparent = new mock_base_nested_element('GRANDPARENT');
     $parent = new mock_base_nested_element('PARENT');
     $child = new mock_base_nested_element('GRANDPARENT');
     $grandparent->add_child($parent);
     try {
         $parent->add_child($child);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add existing element (being grandchild)
     $grandparent = new mock_base_nested_element('GRANDPARENT');
     $parent = new mock_base_nested_element('PARENT');
     $child = new mock_base_nested_element('GRANDPARENT');
     $parent->add_child($child);
     try {
         $grandparent->add_child($parent);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add existing element (being cousin)
     $grandparent = new mock_base_nested_element('GRANDPARENT');
     $parent1 = new mock_base_nested_element('PARENT1');
     $parent2 = new mock_base_nested_element('PARENT2');
     $child1 = new mock_base_nested_element('CHILD1');
     $child2 = new mock_base_nested_element('CHILD1');
     $grandparent->add_child($parent1);
     $parent1->add_child($child1);
     $parent2->add_child($child2);
     try {
         $grandparent->add_child($parent2);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add element to two parents
     $parent1 = new mock_base_nested_element('PARENT1');
     $parent2 = new mock_base_nested_element('PARENT2');
     $child = new mock_base_nested_element('CHILD');
     $parent1->add_child($child);
     try {
         $parent2->add_child($child);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $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->assertEquals($e->errorcode, 'baseelementchildnameconflict');
         $this->assertEquals($e->a, 'FINAL2');
     }
 }
Esempio n. 2
0
 /**
  * Incorrect tree tests (children stuff)
  */
 function test_wrong_tree()
 {
     // Add null object child
     $parent = new mock_base_nested_element('PARENT');
     $child = null;
     try {
         $parent->add_child($child);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add non base_element object child
     $parent = new mock_base_nested_element('PARENT');
     $child = new stdClass();
     try {
         $parent->add_child($child);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add existing element (being parent)
     $parent = new mock_base_nested_element('PARENT');
     $child = new mock_base_nested_element('PARENT');
     try {
         $parent->add_child($child);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add existing element (being grandparent)
     $grandparent = new mock_base_nested_element('GRANDPARENT');
     $parent = new mock_base_nested_element('PARENT');
     $child = new mock_base_nested_element('GRANDPARENT');
     $grandparent->add_child($parent);
     try {
         $parent->add_child($child);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add existing element (being grandchild)
     $grandparent = new mock_base_nested_element('GRANDPARENT');
     $parent = new mock_base_nested_element('PARENT');
     $child = new mock_base_nested_element('GRANDPARENT');
     $parent->add_child($child);
     try {
         $grandparent->add_child($parent);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add existing element (being cousin)
     $grandparent = new mock_base_nested_element('GRANDPARENT');
     $parent1 = new mock_base_nested_element('PARENT1');
     $parent2 = new mock_base_nested_element('PARENT2');
     $child1 = new mock_base_nested_element('CHILD1');
     $child2 = new mock_base_nested_element('CHILD1');
     $grandparent->add_child($parent1);
     $parent1->add_child($child1);
     $parent2->add_child($child2);
     try {
         $grandparent->add_child($parent2);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Add element to two parents
     $parent1 = new mock_base_nested_element('PARENT1');
     $parent2 = new mock_base_nested_element('PARENT2');
     $child = new mock_base_nested_element('CHILD');
     $parent1->add_child($child);
     try {
         $parent2->add_child($child);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_parent_exception);
     }
 }