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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<?php
use PHPHtmlParser\Dom\MockNode as Node;
class NodeChildTest extends PHPUnit_Framework_TestCase {
public function testGetParent() { $parent = new Node; $child = new Node; $child->setParent($parent); $this->assertEquals($parent->id(), $child->getParent()->id()); }
public function testSetParentTwice() { $parent = new Node; $parent2 = new Node; $child = new Node; $child->setParent($parent); $child->setParent($parent2); $this->assertEquals($parent2->id(), $child->getParent()->id()); }
public function testNextSibling() { $parent = new Node; $child = new Node; $child2 = new Node; $child->setParent($parent); $child2->setParent($parent); $this->assertEquals($child2->id(), $child->nextSibling()->id()); }
/** * @expectedException PHPHtmlParser\Exceptions\ChildNotFoundException */ public function testNextSiblingNotFound() { $parent = new Node; $child = new Node; $child->setParent($parent); $child->nextSibling(); }
/** * @expectedException PHPHtmlParser\Exceptions\ParentNotFoundException */ public function testNextSiblingNoParent() { $child = new Node; $child->nextSibling(); }
public function testPreviousSibling() { $parent = new Node; $child = new Node; $child2 = new Node; $child->setParent($parent); $child2->setParent($parent); $this->assertEquals($child->id(), $child2->previousSibling()->id()); }
/** * @expectedException PHPHtmlParser\Exceptions\ChildNotFoundException */ public function testPreviousSiblingNotFound() { $parent = new Node; $node = new Node; $node->setParent($parent); $node->previousSibling(); }
/** * @expectedException PHPHtmlParser\Exceptions\ParentNotFoundException */ public function testPreviousSiblingNoParent() { $child = new Node; $child->previousSibling(); }
public function testGetChildren() { $parent = new Node; $child = new Node; $child2 = new Node; $child->setParent($parent); $child2->setParent($parent); $this->assertEquals($child->id(), $parent->getChildren()[0]->id()); }
public function testCountChildren() { $parent = new Node; $child = new Node; $child2 = new Node; $child->setParent($parent); $child2->setParent($parent); $this->assertEquals(2, $parent->countChildren()); }
public function testIsChild () { $parent = new Node; $child1 = new Node; $child2 = new Node;
$child1->setParent($parent); $child2->setParent($child1);
$this->assertTrue ($parent->isChild ($child1->id ())); $this->assertTrue ($parent->isDescendant ($child2->id ())); $this->assertFalse ($parent->isChild ($child2->id ())); } }
|