14
|
1 package Test::DOM::Node;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
|
5 use base qw(IMPL::Test::Unit);
|
18
|
6 use IMPL::Test qw(test shared failed cmparray);
|
14
|
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
|
37
|
20 $this->Root(new IMPL::DOM::Document(nodeName => 'Root')) or failed "Failed to create a document";
|
14
|
21 };
|
|
22
|
18
|
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
|
14
|
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
|
18
|
34 my $lastChild = $this->Root->removeLast;
|
|
35
|
|
36 failed "removeLast returned incorrect results" unless $lastChild == $child;
|
|
37 };
|
|
38
|
37
|
39 test GetDocumentNode => sub {
|
18
|
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
|
37
|
44 failed "document property is undef" unless $child->document;
|
|
45 failed "document property returned incorrect value" unless $child->document == $this->Root;
|
18
|
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;
|
37
|
55 failed "incorrect new document value" unless ($grandChild->document || 0) == $this->Root;
|
18
|
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) = @_;
|
14
|
76
|
18
|
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
|
24
|
89 my @result = $this->Root->selectNodes(sub { $_->nodeName =~ /child/i } );
|
18
|
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;
|
14
|
122 };
|
|
123
|
|
124 1;
|