Mercurial > pub > Impl
diff _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 |
line wrap: on
line diff
--- a/_test/Test/Web/View.pm Tue Dec 03 17:55:36 2013 +0400 +++ b/_test/Test/Web/View.pm Wed Dec 04 17:31:53 2013 +0400 @@ -16,7 +16,8 @@ Schema => 'IMPL::DOM::Schema', Builder => 'IMPL::DOM::Navigator::Builder', Document => 'IMPL::DOM::Document', - XMLReader => 'IMPL::DOM::XMLReader' + XMLReader => 'IMPL::DOM::XMLReader', + MProfiler => '-IMPL::Profiler::Memory' }, base => [ 'IMPL::Test::Unit' => '@_' @@ -44,33 +45,64 @@ test TestFormMetadata => sub { my ($this) = @_; - my $schema = Schema->LoadSchema($this->GetResourceFile('Resources','person.schema.xml')); - my $builder = Builder->new(Document, $schema); - - my $reader = XMLReader->new( Navigator => $builder ); + # preload to avoid the false memory leak dection + Schema->MetaSchema->Validate(Schema->MetaSchema); + Document->Empty(); + require IMPL::DOM::Schema::Validator::RegExp; - $reader->ParseFile("Resources/person_info.xml"); - - my $doc = $builder->document; - my @errors = $builder->buildErrors; - - push @errors, $schema->Validate($doc); + AssertMemoryLeak(sub{ + my ($doc,$errors) = XMLReader->LoadDocument( + $this->GetResourceFile('Resources','person_info2.xml'), + $this->GetResourceFile('Resources','person.schema.xml') + ); + + my $meta = FormMeta->new( + $doc, + $doc->schemaSource->type, + { + decl => $doc->schemaSource, + schema => $doc->schema, + errors => $errors + } + ); + + assert(@{$errors||[]} == 2); - my $meta = FormMeta->new( - $doc, - $doc->schemaSource->type, - { - decl => $doc->schemaSource, - schema => $doc->schema, - errors => \@errors - } - ); - - my $props = $meta->GetProperties; - - my $prop = $meta->GetProperty('address'); - - join ',', map $_->GetProperty('line')->name, @{$prop->GetItems}; + my $props = $meta->GetProperties; + + assertarray( + [map $_->name, @$props], + [qw(firstName lastName age address)] + ); + assertarray( + [map $_->modelType, @$props], + [undef,undef,'number','ARRAY'] + ); + + my $prop = $meta->GetProperty('address'); + + assert($prop); + assert($prop->schema->type eq 'address'); + assert($prop->isMultiple); + + assert(@{$prop->errors || []} == 1); + assertarray( + [map scalar(@{$_->errors || []}), @{$prop->GetItems}], + [0,0,1] + ); + + my $item = $prop->GetItem(2); + + assert(@{$item->errors} == 1); + assert(@{$item->GetOwnErrors()} == 0); + + assert($item->GetProperty('street')); + + assert(@{$item->GetProperty('street')->errors} == 1); + assert(@{$item->GetProperty('street')->GetOwnErrors()} == 1); + + #join ',', map $_->GetProperty('line')->name, @{$prop->GetItems}; + }); };