annotate _test/Test/DOM/Builder.pm @ 34:a8086f85a571

Dom Builder
author Sergey
date Mon, 16 Nov 2009 18:39:25 +0300
parents
children f25d021780b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
34
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
1 package Test::DOM::Builder;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
2 use strict;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
3 use warnings;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
4
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
5 use base qw(IMPL::Test::Unit);
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
6 __PACKAGE__->PassThroughArgs;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
7
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
8 use IMPL::Class::Property;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
9 use IMPL::Test qw(test failed shared);
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
10
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
11 require IMPL::DOM::Schema;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
12 require IMPL::DOM::Navigator::Builder;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
13 require IMPL::DOM::Document;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
14
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
15 BEGIN {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
16 public property schemaDoc => prop_all;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
17 }
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
18
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
19 sub CTOR {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
20 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
21
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
22 my $schema = new IMPL::DOM::Schema;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
23 $schema->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
24 IMPL::DOM::Schema::ComplexNode->new( name => 'personInfo' )->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
25 IMPL::DOM::Schema::NodeSet->new()->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
26 new IMPL::DOM::Schema::SimpleNode( name => 'firstName' ),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
27 new IMPL::DOM::Schema::SimpleNode( name => 'lastName' ),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
28 new IMPL::DOM::Schema::ComplexNode( name => 'address' )->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
29 IMPL::DOM::Schema::NodeSet->new()->appendRange(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
30 new IMPL::DOM::Schema::SimpleNode( name => 'street' ),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
31 new IMPL::DOM::Schema::SimpleNode( name => 'line', minOccur => 0 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
32 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
33 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
34 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
35 )
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
36 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
37
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
38 $this->schemaDoc( $schema );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
39 }
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
40
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
41 test CreateBuilder => sub {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
42 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
43
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
44 my $builder = IMPL::DOM::Navigator::Builder->new(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
45 new IMPL::DOM::Document(nodeName => 'personInfo'),
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
46 $this->schemaDoc
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
47 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
48 };
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
49
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
50 test BuildDocument => sub {
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
51 my ($this) = @_;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
52
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
53 my $builder = IMPL::DOM::Navigator::Builder->new(
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
54 'IMPL::DOM::Document',
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
55 $this->schemaDoc
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
56 );
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
57
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
58 $builder->NavigateCreate('personInfo', version => '1');
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
59 $builder->NavigateCreate('firstName')->nodeValue('Nemo');
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
60 $builder->Back();
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
61 $builder->NavigateCreate('address', local => 1);
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
62 $builder->NavigateCreate('street')->nodeValue('Hellroad');
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
63 $builder->Back();
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
64 $builder->Back();
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
65 $builder->Back();
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
66
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
67 return 1;
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
68 };
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
69
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
70
a8086f85a571 Dom Builder
Sergey
parents:
diff changeset
71 1;