Newer
Older
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
require_once 'node.php';
use \BasicWeb\Node;
class NodeTest extends PHPUnit_Framework_TestCase {
var $autoloader;
function setUp() {
$this->root = new Node('test node');
}
function test_get_id() {
$this->assertEquals($this->root->get_id(), 1);
$this->assertEquals(Node::create('')->get_id(), 2);
}
function test_get_name() {
$this->assertEquals($this->root->get_name(), 'test node');
$this->assertEquals(Node::create('second node')->get_name(), 'second node');
}
function test_get_parent() {
$this->assertNull($this->root->get_parent());
$this->assertSame(Node::create('', $this->root)->get_parent(), $this->root);
}
function test_is() {
$mirror = $this->root;
$this->assertTrue($mirror->is($this->root));
$this->assertFalse(Node::create('')->is($this->root));
}
function test_is_root() {
$this->assertTrue($this->root->is_root());
$this->assertFalse(Node::create('', $this->root)->is_root());
}
function test_add_child() {
$node = new Node('');
$this->root->add_child($node);
$this->assertAttributeEquals(array($node), 'children', $this->root);
$this->assertSame($node->get_parent(), $this->root);
}
/**
* @depends test_add_child
*/
function test_get_children() {
$this->assertEquals($this->root->get_children(), array());
$node = new Node('');
$this->root->add_child($node);
$this->assertSame($this->root->get_children(), array($node));
}
function test_add_child_no_set_parent() {
$node = new Node('');
$this->root->add_child($node, false);
$this->assertAttributeEquals(array($node), 'children', $this->root);
$this->assertNull($node->get_parent());
}
/**
* @depends test_add_child
*/
function test_is_leaf() {
$node = new Node('');
$this->root->add_child($node);
$this->assertTrue($node->is_leaf());
$this->assertFalse($this->root->is_leaf());
}
/**
* @depends test_add_child
*/
function test_add() {
$node = $this->root->add('name', array('foo' => 'bar'));
$this->assertEquals($node->get_name(), 'name');
$this->assertEquals($node->get('foo'), 'bar');
$this->assertSame($node->get_parent(), $this->root);
}
/**
* @depends test_add
*/
function test_remove_child() {
$node1 = $this->root->add('name', array('foo' => 'bar'));
$node2 = $this->root->add('name', array('foo' => 'bar'));
$this->root->remove_child($node2);
$this->assertAttributeSame(array($node1), 'children', $this->root);
}
/**
* @depends test_remove_child
*/
function test_remove_leaf() {
$node1 = $this->root->add('name', array('foo' => 'bar'));
$node2 = $this->root->add('name', array('foo' => 'bar'));
$node1->remove();
$this->assertAttributeSame(array($node2), 'children', $this->root);
}
/**
* @depends test_remove_leaf
*/
function test_remove_node() {
$node = $this->root->add('node');
$leaf = $node->add('leaf');
$node->remove();
$this->assertAttributeEquals(array(), 'children', $this->root);
$this->assertNull($leaf->get_parent());
}
/**
* @depends test_remove_child
* @expectedException \RuntimeException
*/
function test_remove_root() {
$node1 = $this->root->add('name', array('foo' => 'bar'));
$node2 = $this->root->add('name', array('foo' => 'bar'));
$this->root->remove();
$this->assertAttributeSame(array($node2), 'children', $this->root);
}
function test_set_single() {
$this->root->set('foo', 'bar');
$this->assertAttributeEquals(array('foo' => 'bar'), 'variables', $this->root);
$this->root->set('bar', 'baz');
$this->assertAttributeEquals(array('foo' => 'bar', 'bar' => 'baz'), 'variables', $this->root);
}
function test_set_return() {
$this->assertSame($this->root->set('foo', 'bar'), $this->root);
}
function test_set_multiple() {
$this->root->set(array('foo' => 'bar'));
$this->assertAttributeEquals(array('foo' => 'bar'), 'variables', $this->root);
$this->root->set(array('bar' => 'baz'));
$this->assertAttributeEquals(array('foo' => 'bar', 'bar' => 'baz'), 'variables', $this->root);
}
/**
* @depends test_set_single
*/
function test___set() {
$this->root->foo = 'bar';
$this->assertAttributeEquals(array('foo' => 'bar'), 'variables', $this->root);
$this->root->bar = 'baz';
$this->assertAttributeEquals(array('foo' => 'bar', 'bar' => 'baz'), 'variables', $this->root);
}
/**
* @depends test_set_multiple
*/
function test_get_direct() {
$this->root->set(array('foo' => 'bar', 'bar' => 'baz'));
$this->assertEquals($this->root->get('foo'), 'bar');
$this->assertEquals($this->root->get('bar'), 'baz');
}
/**
* @depends test_get_direct
*/
function test___get() {
$this->root->set(array('foo' => 'bar', 'bar' => 'baz'));
$this->assertEquals($this->root->foo, 'bar');
$this->assertEquals($this->root->bar, 'baz');
}
/**
* @depends test_set_single
*/
function test_get_ancestor() {
$this->root->set('foo', 'bar');
$node = $this->root->add('');
$this->assertEquals($node->get('foo'), 'bar');
}
function test_get_failure() {
$this->assertNull($this->root->get('foo'));
}
/**
* @depends test_get_name
*/
function test_find() {
$node1 = $this->root->add('foo');
$node2 = $this->root->add('bar');
$node3 = $this->root->add('foo');
$this->assertSame($this->root->find('foo'), array($node1, $node3));
}
/**
* @depends test_set_multiple
*/
function test_copy_simple() {
$copy = $this->root->copy();
$this->assertEquals($this->root, $copy);
$this->assertNotSame($this->root, $copy);
}
/**
* @depends test_copy_simple
*/
function test_copy_shallow() {
$child = $this->root->add('');
$copy = $this->root->copy();
$this->assertAttributeSame(array($child), 'children', $copy);
}
/**
* @depends test_get_children
* @depends test_copy_simple
*/
function test_copy_deep() {
$child = $this->root->add('foo');
$copy = $this->root->copy(true);
$copy_children = $copy->get_children();
$child_copy = reset($copy_children);
$this->assertNotSame($copy_children, $this->root->get_children());
$this->assertSame($child_copy->get_parent(), $copy);
}
}
?>