Mercurial > pub > Impl
annotate _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 |
rev | line source |
---|---|
183 | 1 package Test::Web::View; |
188 | 2 use IMPL::Profiler::Memory; |
183 | 3 use strict; |
4 use warnings; | |
185 | 5 use utf8; |
183 | 6 |
185 | 7 use File::Slurp; |
188 | 8 use Scalar::Util qw(weaken); |
288
3a9cfea098dd
*TTView refactoring: removed RequireControl method, etc.
sergey
parents:
287
diff
changeset
|
9 use Data::Dumper; |
280 | 10 use IMPL::lang; |
286 | 11 use IMPL::Test qw(assert assertarray test GetCallerSourceLine); |
183 | 12 |
367 | 13 use IMPL::declare { |
14 require => { | |
15 FormMeta => 'IMPL::Web::View::Metadata::FormMeta', | |
16 Schema => 'IMPL::DOM::Schema', | |
17 Builder => 'IMPL::DOM::Navigator::Builder', | |
18 Document => 'IMPL::DOM::Document', | |
368 | 19 XMLReader => 'IMPL::DOM::XMLReader', |
20 MProfiler => '-IMPL::Profiler::Memory' | |
367 | 21 }, |
22 base => [ | |
23 'IMPL::Test::Unit' => '@_' | |
24 ] | |
183 | 25 }; |
26 | |
367 | 27 |
188 | 28 sub AssertMemoryLeak { |
194 | 29 my $code = shift; |
30 my $dump = shift; | |
31 | |
32 my $data = MProfiler->Monitor($code); | |
33 | |
34 if ($data->isLeak and $dump) { | |
35 write_file("dump.out", { binmode => ':utf8' }, $data->Dump() ); | |
36 } | |
37 | |
38 assert( not($data->isLeak), "Memory leak detected", GetCallerSourceLine() , @{$data->{objects}} ); | |
188 | 39 } |
40 | |
185 | 41 sub templatesDir { |
367 | 42 shift->GetResourceDir('Resources','TTView'); |
188 | 43 } |
44 | |
367 | 45 test TestFormMetadata => sub { |
46 my ($this) = @_; | |
47 | |
368 | 48 # preload to avoid the false memory leak dection |
49 Schema->MetaSchema->Validate(Schema->MetaSchema); | |
50 Document->Empty(); | |
51 require IMPL::DOM::Schema::Validator::RegExp; | |
367 | 52 |
368 | 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); | |
367 | 70 |
368 | 71 my $props = $meta->GetProperties; |
72 | |
73 assertarray( | |
74 [map $_->name, @$props], | |
75 [qw(firstName lastName age address)] | |
76 ); | |
77 assertarray( | |
78 [map $_->modelType, @$props], | |
79 [undef,undef,'number','ARRAY'] | |
80 ); | |
81 | |
82 my $prop = $meta->GetProperty('address'); | |
83 | |
84 assert($prop); | |
85 assert($prop->schema->type eq 'address'); | |
86 assert($prop->isMultiple); | |
87 | |
88 assert(@{$prop->errors || []} == 1); | |
89 assertarray( | |
90 [map scalar(@{$_->errors || []}), @{$prop->GetItems}], | |
91 [0,0,1] | |
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 }); | |
185 | 106 }; |
107 | |
188 | 108 |
183 | 109 1; |