comparison _test/Test/DOM/Node.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents 029c9610528c
children 99ac2e19c0cc
comparison
equal deleted inserted replaced
193:8e8401c0aea4 194:4d0e1962161c
45 failed "document property is undef" unless $child->document; 45 failed "document property is undef" unless $child->document;
46 failed "document property returned incorrect value" unless $child->document == $this->Root; 46 failed "document property returned incorrect value" unless $child->document == $this->Root;
47 }; 47 };
48 48
49 test DocumentCreateNode => sub { 49 test DocumentCreateNode => sub {
50 my ($this) = @_; 50 my ($this) = @_;
51 51
52 my $child = $this->Root->firstChild->appendNode($this->Root->Create(Info => { uuid => '77f9-9a-6d58' } )) or failed "Failed to append a child node"; 52 my $child = $this->Root->firstChild->appendNode($this->Root->Create(Info => { uuid => '77f9-9a-6d58' } )) or failed "Failed to append a child node";
53 53
54 failed "document property is undef" unless $child->document; 54 failed "document property is undef" unless $child->document;
55 failed "document property returned incorrect value" unless $child->document == $this->Root; 55 failed "document property returned incorrect value" unless $child->document == $this->Root;
56 }; 56 };
57 57
103 "Actual: ".scalar(@result) 103 "Actual: ".scalar(@result)
104 unless @result == 2; 104 unless @result == 2;
105 }; 105 };
106 106
107 test SelectNodesPath => sub { 107 test SelectNodesPath => sub {
108 my ($this) = @_; 108 my ($this) = @_;
109 109
110 my @result = $this->Root->selectNodes('Child','Info'); 110 my @result = $this->Root->selectNodes('Child','Info');
111 111
112 failed "Failed to select a node by path 'Child/Info'" unless @result; 112 failed "Failed to select a node by path 'Child/Info'" unless @result;
113 }; 113 };
114 114
115 test SelectByAxisDescendant => sub { 115 test SelectByAxisDescendant => sub {
116 my ($this) = @_; 116 my ($this) = @_;
117 117
118 my @result = $this->Root->selectNodes( { descendant => ['GrandChild','Info']} ); 118 my @result = $this->Root->selectNodes( { descendant => ['GrandChild','Info']} );
119 119
120 failed "Failed to select a node by path '//(GrandChild|Info)/'" unless @result == 2; 120 failed "Failed to select a node by path '//(GrandChild|Info)/'" unless @result == 2;
121 }; 121 };
122 122
123 test SelectByAxisAncestor => sub { 123 test SelectByAxisAncestor => sub {
124 my ($this) = @_; 124 my ($this) = @_;
125 125
126 my @result = $this->Root->selectSingleNode( { descendant => 'Info'} )->selectNodes( { ancestor => undef } ) ; 126 my @result = $this->Root->selectSingleNode( { descendant => 'Info'} )->selectNodes( { ancestor => undef } ) ;
127 127
128 failed "Failed to select a node by path '//Info/ancestor:*'" unless @result == 2; 128 failed "Failed to select a node by path '//Info/ancestor:*'" unless @result == 2;
129 }; 129 };
130 130
131 test CheckNodesValues => sub { 131 test CheckNodesValues => sub {
132 my ($this) = @_; 132 my ($this) = @_;
133 133
154 failed "property isComplex returned false for the root node" unless $this->Root->isComplex; 154 failed "property isComplex returned false for the root node" unless $this->Root->isComplex;
155 failed "property isComplex returned true for a simple node", $this->Root->selectSingleNode('Item')->childNodes->Count if $this->Root->selectSingleNode('Item')->isComplex; 155 failed "property isComplex returned true for a simple node", $this->Root->selectSingleNode('Item')->childNodes->Count if $this->Root->selectSingleNode('Item')->isComplex;
156 }; 156 };
157 157
158 test setObjectProperty => sub { 158 test setObjectProperty => sub {
159 my ($this) = @_; 159 my ($this) = @_;
160 160
161 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode'); 161 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode');
162 162
163 my $name = 'Vergon 6'; 163 my $name = 'Vergon 6';
164 164
165 $node->nodeProperty(name => $name); 165 $node->nodeProperty(name => $name);
166 failed "Failed to set a property 'name'", "Expected: $name", "Got: ".$node->name unless $node->name eq $name; 166 failed "Failed to set a property 'name'", "Expected: $name", "Got: ".$node->name unless $node->name eq $name;
167 167
168 $name = 'entity_vergon_6'; 168 $name = 'entity_vergon_6';
169 $node->systemName($name); 169 $node->systemName($name);
170 failed "Failed to set a property 'systemName'", "Expected: $name", "Got: ".$node->nodeProperty('systemName') unless $node->nodeProperty('systemName') eq $name; 170 failed "Failed to set a property 'systemName'", "Expected: $name", "Got: ".$node->nodeProperty('systemName') unless $node->nodeProperty('systemName') eq $name;
171 }; 171 };
172 172
173 test setDynamicProperty => sub { 173 test setDynamicProperty => sub {
174 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode'); 174 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode');
175 175
176 my $uuid = 'entity_76fd98b9e7a'; 176 my $uuid = 'entity_76fd98b9e7a';
177 $node->nodeProperty(uuid => $uuid); 177 $node->nodeProperty(uuid => $uuid);
178 failed "Failed to set a dynamic property 'uuid'", "Expected: $uuid", "Got: ".$node->nodeProperty('uuid') unless $node->nodeProperty('uuid') eq $uuid; 178 failed "Failed to set a dynamic property 'uuid'", "Expected: $uuid", "Got: ".$node->nodeProperty('uuid') unless $node->nodeProperty('uuid') eq $uuid;
179 }; 179 };
180 180
181 test setPrivateProperty => sub { 181 test setPrivateProperty => sub {
182 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode'); 182 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode');
183 183
184 eval { 184 eval {
185 $node->nodeProperty(_private => 'failed'); 185 $node->nodeProperty(_private => 'failed');
186 1; 186 1;
187 } and failed "Setting a private property successfull"; 187 } and failed "Setting a private property successfull";
188 }; 188 };
189 189
190 test createNodeWithProps => sub { 190 test createNodeWithProps => sub {
191 my $uuid = 'entity_76fd98b9e7a'; 191 my $uuid = 'entity_76fd98b9e7a';
192 my $name = 'Vergon 6'; 192 my $name = 'Vergon 6';
193 my $systemName = 'entity_vergon_6'; 193 my $systemName = 'entity_vergon_6';
194 194
195 my $node = Test::DOM::TypedNode->new( 195 my $node = Test::DOM::TypedNode->new(
196 nodeName => 'TestNode', 196 nodeName => 'TestNode',
197 uuid => $uuid, 197 uuid => $uuid,
198 name => $name, 198 name => $name,
199 systemName => $systemName 199 systemName => $systemName
200 ); 200 );
201 201
202 failed "Failed to get dynamic property 'uuid'" unless $node->nodeProperty('uuid') eq $uuid; 202 failed "Failed to get dynamic property 'uuid'" unless $node->nodeProperty('uuid') eq $uuid;
203 failed "Failed to get property 'name' through nodeProperty method" unless $node->nodeProperty('name') eq $name; 203 failed "Failed to get property 'name' through nodeProperty method" unless $node->nodeProperty('name') eq $name;
204 failed "Failed to get property name directly" unless $node->name eq $name; 204 failed "Failed to get property name directly" unless $node->name eq $name;
205 }; 205 };
206 206
207 test listNodePredefinedProps => sub { 207 test listNodePredefinedProps => sub {
208 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode'); 208 my $node = Test::DOM::TypedNode->new(nodeName => 'TestNode');
209 209
210 my @props = $node->listProperties; 210 my @props = $node->listProperties;
211 my @expected = qw(name _private); 211 my @expected = qw(name _private);
212 212
213 failed "Got wrong list of props", @props unless cmparray(\@props,\@expected); 213 failed "Got wrong list of props", @props unless cmparray(\@props,\@expected);
214 }; 214 };
215 215
216 test listNodeAllProps => sub { 216 test listNodeAllProps => sub {
217 my $node = Test::DOM::TypedNode->new( 217 my $node = Test::DOM::TypedNode->new(
218 nodeName => 'TestNode', 218 nodeName => 'TestNode',
219 uuid => 'ade58f98b', # dynamic 219 uuid => 'ade58f98b', # dynamic
220 name => 'noname', # predefined 220 name => 'noname', # predefined
221 systemName => 'no sys' # not visible to DOM 221 systemName => 'no sys' # not visible to DOM
222 ); 222 );
223 223
224 my @props = $node->listProperties; 224 my @props = $node->listProperties;
225 my @expected = qw(name _private uuid); # systemName is not a DOM prop 225 my @expected = qw(name _private uuid); # systemName is not a DOM prop
226 226
227 failed "Got wrong list of props", @props unless cmparray(\@props,\@expected); 227 failed "Got wrong list of props", @props unless cmparray(\@props,\@expected);
228 }; 228 };
229 229
230 test MemoryLeaks => sub { 230 test MemoryLeaks => sub {
231 my $doc = new IMPL::DOM::Document(nodeName => 'Root'); 231 my $doc = new IMPL::DOM::Document(nodeName => 'Root');
232 weaken($doc); 232 weaken($doc);
233 233
234 assert(not defined $doc); 234 assert(not defined $doc);
235 }; 235 };
236 236
237 package Test::DOM::TypedNode; 237 package Test::DOM::TypedNode;
238 use parent qw(IMPL::DOM::Node); 238 use parent qw(IMPL::DOM::Node);
239 use IMPL::Class::Property; 239 use IMPL::Class::Property;
240 use IMPL::DOM::Property qw(_dom); 240 use IMPL::DOM::Property qw(_dom);
241 241
242 __PACKAGE__->PassThroughArgs; 242 __PACKAGE__->PassThroughArgs;
243 243
244 BEGIN { 244 BEGIN {
245 public _dom property name => prop_all; 245 public _dom property name => prop_all;
246 public property systemName => prop_all; 246 public property systemName => prop_all;
247 private _dom property _private => prop_all; 247 private _dom property _private => prop_all;
248 } 248 }
249 249
250 250
251 1; 251 1;