comparison _test/Test/Web/View.pm @ 185:ae8072f2f2a3

IMPL::Web::View::TTDocument tests, fixes
author cin
date Thu, 29 Mar 2012 18:22:15 +0400
parents 7525ea9a071a
children 6c0fee769b0c
comparison
equal deleted inserted replaced
184:7525ea9a071a 185:ae8072f2f2a3
1 package Test::Web::View; 1 package Test::Web::View;
2 use strict; 2 use strict;
3 use warnings; 3 use warnings;
4 use utf8;
4 5
5 use parent qw(IMPL::Test::Unit); 6 use parent qw(IMPL::Test::Unit);
6 __PACKAGE__->PassThroughArgs; 7 __PACKAGE__->PassThroughArgs;
8
9 use File::Slurp;
7 10
8 use IMPL::Test qw(assert test); 11 use IMPL::Test qw(assert test);
9 use IMPL::Web::View::TTLoader(); 12 use IMPL::Web::View::TTLoader();
10 13
11 use constant { 14 use constant {
12 TTLoader => typeof IMPL::Web::View::TTLoader 15 TTLoader => typeof IMPL::Web::View::TTLoader
13 }; 16 };
14 17
15 test TemplateLoaderTests => sub { 18 sub templatesDir {
19 $_[0]->GetResourceDir('Resources','TTView');
20 }
21
22 test TTLoaderTests => sub {
16 my ($this) = @_; 23 my ($this) = @_;
17 24
18 my $loader = TTLoader->new( 25 my $loader = TTLoader->new(
19 { 26 {
20 INCLUDE_PATH => [ 27 INCLUDE_PATH => [
21 $this->GetResourceDir('Resources','TTView') 28 $this->templatesDir
22 ] 29 ]
23 }, 30 },
24 ext => '.tt', 31 ext => '.tt',
25 initializer => 'global.tt' 32 initializer => 'global.tt'
26 ); 33 );
40 47
41 # document should inherit loader's context 48 # document should inherit loader's context
42 assert( $doc->context->stash->get('user') eq 'test_user'); 49 assert( $doc->context->stash->get('user') eq 'test_user');
43 }; 50 };
44 51
52 test TTDocumentTests => sub {
53 my ($this) = @_;
54 my $loader = TTLoader->new(
55 {
56 INCLUDE_PATH => [
57 $this->templatesDir
58 ],
59 INTERPOLATE => 1,
60 POST_CHOMP => 1,
61 ENCODING => 'utf-8'
62 },
63 ext => '.tt',
64 initializer => 'global.tt'
65 );
66
67 my $doc = $loader->document('simple');
68
69 assert(defined $doc);
70
71 assert($doc->nodeName eq 'document');
72 assert(not $doc->can('notexists')); # autoloaded property should be ignored
73 assert($doc->notexists eq ''); # nonexisting property
74 assert($doc->version == 10); # static metadata
75 assert($doc->user eq 'test_user'); # global data
76 assert($doc->templateVar eq 'initialized by the constructor'); # defined in CTOR block
77
78 my $text = $doc->Render();
79 my $expected = read_file($this->GetResourceFile('Resources','TTView.Output','simple.txt'), binmode => ':utf8');
80
81 assert($text eq $expected, "Bad Render() output","Got: $text", "Expected: $expected");
82
83 };
84
45 1; 85 1;