Mercurial > pub > Impl
diff _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 |
line wrap: on
line diff
--- a/_test/Test/Web/View.pm Thu Mar 29 01:54:20 2012 +0400 +++ b/_test/Test/Web/View.pm Thu Mar 29 18:22:15 2012 +0400 @@ -1,10 +1,13 @@ package Test::Web::View; use strict; use warnings; +use utf8; use parent qw(IMPL::Test::Unit); __PACKAGE__->PassThroughArgs; +use File::Slurp; + use IMPL::Test qw(assert test); use IMPL::Web::View::TTLoader(); @@ -12,13 +15,17 @@ TTLoader => typeof IMPL::Web::View::TTLoader }; -test TemplateLoaderTests => sub { +sub templatesDir { + $_[0]->GetResourceDir('Resources','TTView'); +} + +test TTLoaderTests => sub { my ($this) = @_; my $loader = TTLoader->new( { INCLUDE_PATH => [ - $this->GetResourceDir('Resources','TTView') + $this->templatesDir ] }, ext => '.tt', @@ -42,4 +49,37 @@ assert( $doc->context->stash->get('user') eq 'test_user'); }; +test TTDocumentTests => sub { + my ($this) = @_; + my $loader = TTLoader->new( + { + INCLUDE_PATH => [ + $this->templatesDir + ], + INTERPOLATE => 1, + POST_CHOMP => 1, + ENCODING => 'utf-8' + }, + ext => '.tt', + initializer => 'global.tt' + ); + + my $doc = $loader->document('simple'); + + assert(defined $doc); + + assert($doc->nodeName eq 'document'); + assert(not $doc->can('notexists')); # autoloaded property should be ignored + assert($doc->notexists eq ''); # nonexisting property + assert($doc->version == 10); # static metadata + assert($doc->user eq 'test_user'); # global data + assert($doc->templateVar eq 'initialized by the constructor'); # defined in CTOR block + + my $text = $doc->Render(); + my $expected = read_file($this->GetResourceFile('Resources','TTView.Output','simple.txt'), binmode => ':utf8'); + + assert($text eq $expected, "Bad Render() output","Got: $text", "Expected: $expected"); + +}; + 1; \ No newline at end of file