1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
<?php
use Prado\Collections\TMap;
use Prado\Xml\TXmlElement;
/**
* @package System.Xml
*/
class TXmlElementTest extends PHPUnit_Framework_TestCase {
public function setUp() {
}
public function testConstruct() {
$element = new TXmlElement('tag');
self::assertEquals('tag', $element->getTagName());
}
public function testSetParent() {
$parent = new TXmlElement('parent');
$child = new TXmlElement('child');
$child->setParent($parent);
self::assertEquals($parent, $child->getParent());
}
public function testSetTagName() {
$element = new TXmlElement('tag');
$element->setTagName('newtag');
self::assertEquals('newtag', $element->getTagName());
}
public function testSetValue() {
$element = new TXmlElement('tag');
$element->setValue('value');
self::assertEquals('value', $element->getValue());
}
public function testHasElement() {
$element = new TXmlElement('first');
self::assertEquals(false, $element->getHasElement());
$element->Elements[] = new TXmlElement('second');
self::assertEquals(true, $element->getHasElement());
}
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 testSetAttribute() {
$element = new TXmlElement('tag');
self::assertEquals(null, $element->getAttribute('key'));
$element->setAttribute('key', 'value');
self::assertEquals('value', $element->getAttribute('key'));
}
public function testGetElementByTagName() {
$element = new TXmlElement('tag');
self::assertEquals(null, $element->getElementByTagName('first'));
$element->Elements[] = new TXmlElement('first');
$first = $element->getElementByTagName('first');
self::assertInstanceOf('Prado\\Xml\\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('<tag />', (string)$element);
$element->setAttribute('key', 'value');
self::assertEquals('<tag key="value" />', (string)$element);
$element->setValue('value');
self::assertEquals('<tag key="value">value</tag>', (string)$element);
}
}
|