49
|
1 package Test::DOM::Node;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use base qw(IMPL::Test::Unit);
|
|
6 use IMPL::Test qw(test shared failed cmparray);
|
|
7 use IMPL::Class::Property;
|
|
8
|
|
9 require IMPL::DOM::Node;
|
|
10
|
|
11 __PACKAGE__->PassThroughArgs;
|
|
12
|
|
13 BEGIN {
|
|
14 shared public property Root => prop_all;
|
|
15 }
|
|
16
|
|
17 test Create => sub {
|
|
18 my ($this) = @_;
|
|
19
|
|
20 $this->Root(new IMPL::DOM::Document(nodeName => 'Root')) or failed "Failed to create a document";
|
|
21 };
|
|
22
|
|
23 test InsertNode => sub {
|
|
24 my ($this) = @_;
|
|
25 my $child = $this->Root->insertNode(new IMPL::DOM::Node(nodeName => 'Child')) or failed "Failed to insert a child node";
|
|
26 failed "fiestChild returned incorrect results" unless ($this->Root->firstChild || 0) == $child;
|
|
27 };
|
|
28
|
|
29 test AppendNode => sub {
|
|
30 my ($this) = @_;
|
|
31
|
|
32 my $child = $this->Root->appendNode(new IMPL::DOM::Node(nodeName => 'Child')) or failed "Failed to append a child node";
|
|
33
|
|
34 my $lastChild = $this->Root->removeLast;
|
|
35
|
|
36 failed "removeLast returned incorrect results" unless $lastChild == $child;
|
|
37 };
|
|
38
|
|
39 test GetDocumentNode => sub {
|
|
40 my ($this) = @_;
|
|
41
|
|
42 my $child = $this->Root->firstChild->appendNode(new IMPL::DOM::Node(nodeName => 'GrandChild')) or failed "Failed to append a child node";
|
|
43
|
|
44 failed "document property is undef" unless $child->document;
|
|
45 failed "document property returned incorrect value" unless $child->document == $this->Root;
|
|
46 };
|
|
47
|
|
48 test MoveNode => sub {
|
|
49 my ($this) = @_;
|
|
50
|
|
51 my $grandChild = $this->Root->firstChild->firstChild;
|
|
52 $this->Root->appendNode($grandChild);
|
|
53
|
|
54 failed "incorrect new parentNode value" unless ($grandChild->parentNode || 0) == $this->Root;
|
|
55 failed "incorrect new document value" unless ($grandChild->document || 0) == $this->Root;
|
|
56 };
|
|
57
|
|
58 test AppendRange => sub {
|
|
59 my ($this) = @_;
|
|
60
|
|
61 my $count = $this->Root->childNodes->Count;
|
|
62
|
|
63 $this->Root->appendRange(
|
|
64 map IMPL::DOM::Node->new(nodeName => "Item", nodeValue => $_),1..10
|
|
65 );
|
|
66
|
|
67 failed
|
|
68 "Wrong number of a child nodes",
|
|
69 "Expected: ".($count+10),
|
|
70 "Actual: ".$this->Root->childNodes->Count
|
|
71 unless $count + 10 == $this->Root->childNodes->Count;
|
|
72 };
|
|
73
|
|
74 test SelectNodes => sub {
|
|
75 my ($this) = @_;
|
|
76
|
|
77 my @result = $this->Root->selectNodes("Item");
|
|
78
|
|
79 failed
|
|
80 "Wrong number of a selected nodes",
|
|
81 "Expected: 10",
|
|
82 "Actual: ".scalar(@result)
|
|
83 unless @result == 10;
|
|
84 };
|
|
85
|
|
86 test SelectNodesByQuery => sub {
|
|
87 my ($this) = @_;
|
|
88
|
|
89 my @result = $this->Root->selectNodes(sub { $_->nodeName =~ /child/i } );
|
|
90 failed
|
|
91 "Wrong number of a selected nodes",
|
|
92 "Expected: 2",
|
|
93 "Actual: ".scalar(@result)
|
|
94 unless @result == 2;
|
|
95 };
|
|
96
|
|
97 test CheckNodesValues => sub {
|
|
98 my ($this) = @_;
|
|
99
|
|
100 my @expected = (1..10);
|
|
101
|
|
102 my @result = map $_->nodeValue, grep $_->nodeValue, $this->Root->selectNodes("Item");
|
|
103
|
|
104 failed
|
|
105 "Some nodes returned wrong node values or in a wrong order",
|
|
106 "Expected: ".join(', ',@expected),
|
|
107 "Recieved: ".join(', ',@result)
|
|
108 unless cmparray(\@expected,\@result);
|
|
109
|
|
110 failed
|
|
111 "a text property of a root node returned a wrong value",
|
|
112 "Expected: @expected",
|
|
113 "Recieved: ". $this->Root->text
|
|
114 unless $this->Root->text eq join '',@expected;
|
|
115 };
|
|
116
|
|
117 test isComplex => sub {
|
|
118 my ($this) = @_;
|
|
119
|
|
120 failed "property isComplex returned false for the root node" unless $this->Root->isComplex;
|
|
121 failed "property isComplex returned true for a simple node", $this->Root->firstChild->nodeName if $this->Root->firstChild->isComplex;
|
|
122 };
|
|
123
|
123
|
124 test setObjectProperty => sub {
|
|
125 my ($this) = @_;
|
|
126
|
|
127 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode');
|
|
128
|
|
129 my $name = 'Vergon 6';
|
|
130
|
|
131 $node->nodeProperty(name => $name);
|
|
132 failed "Failed to set a property 'name'", "Expected: $name", "Got: ".$node->name unless $node->name eq $name;
|
|
133
|
|
134 $name = 'entity_vergon_6';
|
|
135 $node->systemName($name);
|
|
136 failed "Failed to set a property 'systemName'", "Expected: $name", "Got: ".$node->nodeProperty('systemName') unless $node->nodeProperty('systemName') eq $name;
|
|
137 };
|
|
138
|
|
139 test setDynamicProperty => sub {
|
|
140 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode');
|
|
141
|
|
142 my $uuid = 'entity_76fd98b9e7a';
|
|
143 $node->nodeProperty(uuid => $uuid);
|
|
144 failed "Failed to set a dynamic property 'uuid'", "Expected: $uuid", "Got: ".$node->nodeProperty('uuid') unless $node->nodeProperty('uuid') eq $uuid;
|
|
145 };
|
|
146
|
|
147 test setPrivateProperty => sub {
|
|
148 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode');
|
|
149
|
|
150 eval {
|
|
151 $node->nodeProperty(_private => 'failed');
|
|
152 1;
|
|
153 } and failed "Setting a private property successfull";
|
|
154 };
|
|
155
|
124
|
156 test createNodeWithProps => sub {
|
|
157 my $uuid = 'entity_76fd98b9e7a';
|
|
158 my $name = 'Vergon 6';
|
|
159 my $systemName = 'entity_vergon_6';
|
|
160
|
|
161 my $node = Test::DOM::TypedNode->new(
|
|
162 nodeName => 'TestNode',
|
|
163 uuid => $uuid,
|
|
164 name => $name,
|
|
165 systemName => $systemName
|
|
166 );
|
|
167
|
|
168 failed "Failed to get dynamic property 'uuid'" unless $node->nodeProperty('uuid') eq $uuid;
|
|
169 failed "Failed to get property 'name' through nodeProperty method" unless $node->nodeProperty('name') eq $name;
|
|
170 failed "Failed to get property name directly" unless $node->name eq $name;
|
|
171 };
|
|
172
|
|
173 test listNodePredefinedProps => sub {
|
|
174 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode');
|
|
175
|
|
176 my @props = $node->listProperties;
|
|
177 my @expected = qw(name _private);
|
|
178
|
|
179 failed "Got wrong list of props", @props unless cmparray(\@props,\@expected);
|
|
180 };
|
|
181
|
|
182 test listNodeAllProps => sub {
|
|
183 my $node = Test::DOM::TypedNode->new(
|
|
184 nodeName => 'TestNode',
|
|
185 uuid => 'ade58f98b', # dynamic
|
|
186 name => 'noname', # predefined
|
|
187 systemName => 'no sys' # not visible to DOM
|
|
188 );
|
|
189
|
|
190 my @props = $node->listProperties;
|
|
191 my @expected = qw(name _private uuid); # systemName is not a DOM prop
|
|
192
|
|
193 failed "Got wrong list of props", @props unless cmparray(\@props,\@expected);
|
|
194 };
|
|
195
|
122
|
196 package Test::DOM::TypedNode;
|
|
197 use base qw(IMPL::DOM::Node);
|
|
198 use IMPL::Class::Property;
|
123
|
199 use IMPL::DOM::Property qw(_dom);
|
|
200
|
|
201 __PACKAGE__->PassThroughArgs;
|
122
|
202
|
123
|
203 BEGIN {
|
|
204 public _dom property name => prop_all;
|
|
205 public property systemName => prop_all;
|
|
206 private _dom property _private => prop_all;
|
|
207 }
|
122
|
208
|
|
209
|
49
|
210 1;
|