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 creation tests (attributes and final elements)
  */
 function itest_wrong_creation()
 {
     // Create instance with invalid name
     try {
         $instance = new mock_base_nested_element('');
         $this->fail("Expecting base_atom_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_atom_struct_exception);
     }
     // Create instance with incorrect (object) final element
     try {
         $obj = new stdClass();
         $obj->name = 'test_attr';
         $instance = new mock_base_nested_element('TEST', null, $obj);
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Create instance with array containing incorrect (object) final element
     try {
         $obj = new stdClass();
         $obj->name = 'test_attr';
         $instance = new mock_base_nested_element('TEST', null, array($obj));
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Create instance with array containing duplicate final elements
     try {
         $instance = new mock_base_nested_element('TEST', null, array('VAL1', 'VAL2', 'VAL1'));
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Try to get value of base_nested_element
     $instance = new mock_base_nested_element('TEST');
     try {
         $instance->get_value();
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Try to set value of base_nested_element
     $instance = new mock_base_nested_element('TEST');
     try {
         $instance->set_value('some_value');
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
     // Try to clean one value of base_nested_element
     $instance = new mock_base_nested_element('TEST');
     try {
         $instance->clean_value('some_value');
         $this->fail("Expecting base_element_struct_exception exception, none occurred");
     } catch (Exception $e) {
         $this->assertTrue($e instanceof base_element_struct_exception);
     }
 }
Esempio n. 3
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);
     }
 }