From 615eb561dfc43bd11ba620c9465e18ac15e22131 Mon Sep 17 00:00:00 2001
From: knut <>
Date: Fri, 1 Jun 2007 05:09:32 +0000
Subject: resolved #634 and added unit tests for TXmlElement
---
tests/unit/Xml/TXmlElementTest.php | 92 +++++++++++++++++++++++++++-----------
1 file changed, 65 insertions(+), 27 deletions(-)
(limited to 'tests/unit/Xml/TXmlElementTest.php')
diff --git a/tests/unit/Xml/TXmlElementTest.php b/tests/unit/Xml/TXmlElementTest.php
index eec22b1f..89baed03 100644
--- a/tests/unit/Xml/TXmlElementTest.php
+++ b/tests/unit/Xml/TXmlElementTest.php
@@ -8,39 +8,77 @@ Prado::using('System.Xml.TXmlDocument');
*/
class TXmlElementTest extends PHPUnit_Framework_TestCase {
- public function setUp() {
- }
+ public function setUp() {
+ }
- public function testConstruct() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
+ public function testConstruct() {
+ $element = new TXmlElement('tag');
+ self::assertEquals('tag', $element->getTagName());
+ }
- public function testSetParent() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
+ public function testSetParent() {
+ $parent = new TXmlElement('parent');
+ $child = new TXmlElement('child');
+ $child->setParent($parent);
+ self::assertEquals($parent, $child->getParent());
+ }
- public function testSetTagName() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
+ public function testSetTagName() {
+ $element = new TXmlElement('tag');
+ $element->setTagName('newtag');
+ self::assertEquals('newtag', $element->getTagName());
+ }
- public function testSetValue() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
+ public function testSetValue() {
+ $element = new TXmlElement('tag');
+ $element->setValue('value');
+ self::assertEquals('value', $element->getValue());
+ }
- public function testSetAttribute() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
+ public function testHasElement() {
+ $element = new TXmlElement('first');
+ self::assertEquals(false, $element->getHasElement());
+ $element->Elements[] = new TXmlElement('second');
+ self::assertEquals(true, $element->getHasElement());
+ }
- public function testGetElementByTagName() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
+ public function testHasAttribute() {
+ $element = new TXmlElement('tag');
+ self::assertEquals(false, $element->getHasAttribute());
+ $element->Attributes[] = new TMap(array('key' => 'value'));
+ self::assertEquals(true, $element->getHasAttribute());
+ }
- public function testGetElementsByTagName() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
+ public function testSetAttribute() {
+ $element = new TXmlElement('tag');
+ self::assertEquals(null, $element->getAttribute('key'));
+ $element->setAttribute('key', 'value');
+ self::assertEquals('value', $element->getAttribute('key'));
+ }
- public function testToString() {
- throw new PHPUnit_Framework_IncompleteTestError();
- }
+ public function testGetElementByTagName() {
+ $element = new TXmlElement('tag');
+ self::assertEquals(null, $element->getElementByTagName('first'));
+ $element->Elements[] = new TXmlElement('first');
+ $first = $element->getElementByTagName('first');
+ self::assertType('TXmlElement', $first);
+ self::assertEquals('first', $first->getTagName());
+ }
+
+ public function testGetElementsByTagName() {
+ $element = new TXmlElement('tag');
+ $element->Elements[] = new TXmlElement('tag');
+ $element->Elements[] = new TXmlElement('tag');
+ self::assertEquals(2, count($element->getElementsByTagName('tag')));
+ }
+
+ public function testToString() {
+ $element = new TXmlElement('tag');
+ self::assertEquals('', (string)$element);
+ $element->setAttribute('key', 'value');
+ self::assertEquals('', (string)$element);
+ $element->setValue('value');
+ self::assertEquals('value', (string)$element);
+ }
}
-?>
\ No newline at end of file
+?>
--
cgit v1.2.3