Beispiel #1
0
 /**
  * Correct base_attribute tests
  */
 function test_base_attribute()
 {
     $name_with_all_chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_';
     $value_to_test = 'Some <value> to test';
     // Create instance with correct names
     $instance = new mock_base_attribute($name_with_all_chars);
     $this->assertIsA($instance, 'base_attribute');
     $this->assertEqual($instance->get_name(), $name_with_all_chars);
     $this->assertNull($instance->get_value());
     // Set value
     $instance->set_value($value_to_test);
     $this->assertEqual($instance->get_value(), $value_to_test);
     // Get to_string() results (with values)
     $instance = new mock_base_attribute($name_with_all_chars);
     $instance->set_value($value_to_test);
     $tostring = $instance->to_string(true);
     $this->assertTrue(strpos($tostring, '@' . $name_with_all_chars) !== false);
     $this->assertTrue(strpos($tostring, ' => ') !== false);
     $this->assertTrue(strpos($tostring, $value_to_test) !== false);
 }
 /**
  * Correct base_final_element tests
  */
 function test_base_final_element()
 {
     // Create instance with name
     $instance = new mock_base_final_element('TEST');
     $this->assertIsA($instance, 'base_final_element');
     $this->assertEqual($instance->get_name(), 'TEST');
     $this->assertNull($instance->get_value());
     $this->assertEqual($instance->get_attributes(), array());
     $this->assertNull($instance->get_parent());
     $this->assertEqual($instance->get_level(), 1);
     // Set value
     $instance->set_value('value');
     $this->assertEqual($instance->get_value(), 'value');
     // Create instance with name and one object attribute
     $instance = new mock_base_final_element('TEST', new mock_base_attribute('ATTR1'));
     $attrs = $instance->get_attributes();
     $this->assertTrue(is_array($attrs));
     $this->assertEqual(count($attrs), 1);
     $this->assertTrue($attrs['ATTR1'] instanceof base_attribute);
     $this->assertEqual($attrs['ATTR1']->get_name(), 'ATTR1');
     $this->assertNull($attrs['ATTR1']->get_value());
     // Create instance with name and various object attributes
     $attr1 = new mock_base_attribute('ATTR1');
     $attr1->set_value('attr1_value');
     $attr2 = new mock_base_attribute('ATTR2');
     $instance = new mock_base_final_element('TEST', array($attr1, $attr2));
     $attrs = $instance->get_attributes();
     $this->assertTrue(is_array($attrs));
     $this->assertEqual(count($attrs), 2);
     $this->assertTrue($attrs['ATTR1'] instanceof base_attribute);
     $this->assertEqual($attrs['ATTR1']->get_name(), 'ATTR1');
     $this->assertEqual($attrs['ATTR1']->get_value(), 'attr1_value');
     $this->assertTrue($attrs['ATTR2'] instanceof base_attribute);
     $this->assertEqual($attrs['ATTR2']->get_name(), 'ATTR2');
     $this->assertNull($attrs['ATTR2']->get_value());
     // Create instance with name and one string attribute
     $instance = new mock_base_final_element('TEST', 'ATTR1');
     $attrs = $instance->get_attributes();
     $this->assertTrue(is_array($attrs));
     $this->assertEqual(count($attrs), 1);
     $this->assertTrue($attrs['ATTR1'] instanceof base_attribute);
     $this->assertEqual($attrs['ATTR1']->get_name(), 'ATTR1');
     $this->assertNull($attrs['ATTR1']->get_value());
     // Create instance with name and various object attributes
     $instance = new mock_base_final_element('TEST', array('ATTR1', 'ATTR2'));
     $attrs = $instance->get_attributes();
     $attrs['ATTR1']->set_value('attr1_value');
     $this->assertTrue(is_array($attrs));
     $this->assertEqual(count($attrs), 2);
     $this->assertTrue($attrs['ATTR1'] instanceof base_attribute);
     $this->assertEqual($attrs['ATTR1']->get_name(), 'ATTR1');
     $this->assertEqual($attrs['ATTR1']->get_value(), 'attr1_value');
     $this->assertTrue($attrs['ATTR2'] instanceof base_attribute);
     $this->assertEqual($attrs['ATTR2']->get_name(), 'ATTR2');
     $this->assertNull($attrs['ATTR2']->get_value());
     // Clean values
     $instance = new mock_base_final_element('TEST', array('ATTR1', 'ATTR2'));
     $instance->set_value('instance_value');
     $attrs = $instance->get_attributes();
     $attrs['ATTR1']->set_value('attr1_value');
     $this->assertEqual($instance->get_value(), 'instance_value');
     $this->assertEqual($attrs['ATTR1']->get_value(), 'attr1_value');
     $instance->clean_values();
     $this->assertNull($instance->get_value());
     $this->assertNull($attrs['ATTR1']->get_value());
     // Get to_string() results (with values)
     $instance = new mock_base_final_element('TEST', array('ATTR1', 'ATTR2'));
     $instance->set_value('final element value');
     $attrs = $instance->get_attributes();
     $attrs['ATTR1']->set_value('attr1 value');
     $tostring = $instance->to_string(true);
     $this->assertTrue(strpos($tostring, '#TEST (level: 1)') !== false);
     $this->assertTrue(strpos($tostring, ' => ') !== false);
     $this->assertTrue(strpos($tostring, 'final element value') !== false);
     $this->assertTrue(strpos($tostring, 'attr1 value') !== false);
 }