comparison _test/Test/Web/View.pm @ 368:010ceafd0c5a

form metadata + tests
author cin
date Wed, 04 Dec 2013 17:31:53 +0400
parents 608e74bc309f
children 7c784144d2f1
comparison
equal deleted inserted replaced
367:608e74bc309f 368:010ceafd0c5a
14 require => { 14 require => {
15 FormMeta => 'IMPL::Web::View::Metadata::FormMeta', 15 FormMeta => 'IMPL::Web::View::Metadata::FormMeta',
16 Schema => 'IMPL::DOM::Schema', 16 Schema => 'IMPL::DOM::Schema',
17 Builder => 'IMPL::DOM::Navigator::Builder', 17 Builder => 'IMPL::DOM::Navigator::Builder',
18 Document => 'IMPL::DOM::Document', 18 Document => 'IMPL::DOM::Document',
19 XMLReader => 'IMPL::DOM::XMLReader' 19 XMLReader => 'IMPL::DOM::XMLReader',
20 MProfiler => '-IMPL::Profiler::Memory'
20 }, 21 },
21 base => [ 22 base => [
22 'IMPL::Test::Unit' => '@_' 23 'IMPL::Test::Unit' => '@_'
23 ] 24 ]
24 }; 25 };
42 } 43 }
43 44
44 test TestFormMetadata => sub { 45 test TestFormMetadata => sub {
45 my ($this) = @_; 46 my ($this) = @_;
46 47
47 my $schema = Schema->LoadSchema($this->GetResourceFile('Resources','person.schema.xml')); 48 # preload to avoid the false memory leak dection
48 my $builder = Builder->new(Document, $schema); 49 Schema->MetaSchema->Validate(Schema->MetaSchema);
50 Document->Empty();
51 require IMPL::DOM::Schema::Validator::RegExp;
49 52
50 my $reader = XMLReader->new( Navigator => $builder ); 53 AssertMemoryLeak(sub{
54 my ($doc,$errors) = XMLReader->LoadDocument(
55 $this->GetResourceFile('Resources','person_info2.xml'),
56 $this->GetResourceFile('Resources','person.schema.xml')
57 );
58
59 my $meta = FormMeta->new(
60 $doc,
61 $doc->schemaSource->type,
62 {
63 decl => $doc->schemaSource,
64 schema => $doc->schema,
65 errors => $errors
66 }
67 );
68
69 assert(@{$errors||[]} == 2);
51 70
52 $reader->ParseFile("Resources/person_info.xml"); 71 my $props = $meta->GetProperties;
53 72
54 my $doc = $builder->document; 73 assertarray(
55 my @errors = $builder->buildErrors; 74 [map $_->name, @$props],
56 75 [qw(firstName lastName age address)]
57 push @errors, $schema->Validate($doc); 76 );
58 77 assertarray(
59 my $meta = FormMeta->new( 78 [map $_->modelType, @$props],
60 $doc, 79 [undef,undef,'number','ARRAY']
61 $doc->schemaSource->type, 80 );
62 { 81
63 decl => $doc->schemaSource, 82 my $prop = $meta->GetProperty('address');
64 schema => $doc->schema, 83
65 errors => \@errors 84 assert($prop);
66 } 85 assert($prop->schema->type eq 'address');
67 ); 86 assert($prop->isMultiple);
68 87
69 my $props = $meta->GetProperties; 88 assert(@{$prop->errors || []} == 1);
70 89 assertarray(
71 my $prop = $meta->GetProperty('address'); 90 [map scalar(@{$_->errors || []}), @{$prop->GetItems}],
72 91 [0,0,1]
73 join ',', map $_->GetProperty('line')->name, @{$prop->GetItems}; 92 );
93
94 my $item = $prop->GetItem(2);
95
96 assert(@{$item->errors} == 1);
97 assert(@{$item->GetOwnErrors()} == 0);
98
99 assert($item->GetProperty('street'));
100
101 assert(@{$item->GetProperty('street')->errors} == 1);
102 assert(@{$item->GetProperty('street')->GetOwnErrors()} == 1);
103
104 #join ',', map $_->GetProperty('line')->name, @{$prop->GetItems};
105 });
74 }; 106 };
75 107
76 108
77 1; 109 1;