annotate _test/Test/Web/View.pm @ 187:927653d01f4f

TTControl::AUTOLOAD now accesses nodeProperties Added TTControl::renderBlock property to access RENDER block of the template
author sergey
date Tue, 03 Apr 2012 07:54:25 +0400
parents 6c0fee769b0c
children 029c9610528c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
1 package Test::Web::View;
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
2 use strict;
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
3 use warnings;
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
4 use utf8;
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
5
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
6 use parent qw(IMPL::Test::Unit);
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
7 __PACKAGE__->PassThroughArgs;
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
8
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
9 use File::Slurp;
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
10
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
11 use IMPL::Test qw(assert test);
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
12 use IMPL::Web::View::TTLoader();
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
13
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
14 use constant {
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
15 TTLoader => typeof IMPL::Web::View::TTLoader
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
16 };
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
17
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
18 sub templatesDir {
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
19 $_[0]->GetResourceDir('Resources','TTView');
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
20 }
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
21
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
22 test TTLoaderTests => sub {
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
23 my ($this) = @_;
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
24
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
25 my $loader = TTLoader->new(
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
26 {
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
27 INCLUDE_PATH => [
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
28 $this->templatesDir
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
29 ]
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
30 },
184
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
31 ext => '.tt',
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
32 initializer => 'global.tt'
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
33 );
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
34
184
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
35 # test the loader to be able to find a desired resource
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
36 assert( defined($loader->template('simple') ) );
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
37
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
38 # loader should be initialized on demand
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
39 assert( not $loader->isInitialized );
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
40
184
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
41 # loader should be able to load a document
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
42 my $doc = $loader->document('simple');
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
43 assert(defined $doc);
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
44
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
45 assert( $loader->isInitialized );
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
46 assert( $loader->context->stash->get('user') eq 'test_user');
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
47
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
48 # document should inherit loader's context
7525ea9a071a IMPL::Web::View::TTLoader tests
sergey
parents: 183
diff changeset
49 assert( $doc->context->stash->get('user') eq 'test_user');
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
50 };
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
51
185
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
52 test TTDocumentTests => sub {
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
53 my ($this) = @_;
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
54 my $loader = TTLoader->new(
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
55 {
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
56 INCLUDE_PATH => [
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
57 $this->templatesDir
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
58 ],
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
59 INTERPOLATE => 1,
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
60 POST_CHOMP => 1,
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
61 ENCODING => 'utf-8'
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
62 },
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
63 ext => '.tt',
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
64 initializer => 'global.tt'
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
65 );
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
66
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
67 my $doc = $loader->document('simple');
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
68
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
69 assert(defined $doc);
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
70
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
71 assert($doc->nodeName eq 'document');
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
72 assert(not $doc->can('notexists')); # autoloaded property should be ignored
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
73 assert($doc->notexists eq ''); # nonexisting property
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
74 assert($doc->version == 10); # static metadata
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
75 assert($doc->user eq 'test_user'); # global data
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
76 assert($doc->templateVar eq 'initialized by the constructor'); # defined in CTOR block
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
77
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
78 my $text = $doc->Render();
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
79 my $expected = read_file($this->GetResourceFile('Resources','TTView.Output','simple.txt'), binmode => ':utf8');
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
80
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
81 assert($text eq $expected, "Bad Render() output","Got: $text", "Expected: $expected");
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
82
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
83 };
ae8072f2f2a3 IMPL::Web::View::TTDocument tests, fixes
cin
parents: 184
diff changeset
84
186
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
85 test TTControlTests => sub {
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
86 my ($this) = @_;
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
87
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
88 my $loader = TTLoader->new(
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
89 {
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
90 INCLUDE_PATH => [
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
91 $this->templatesDir
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
92 ],
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
93 INTERPOLATE => 1,
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
94 POST_CHOMP => 1,
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
95 ENCODING => 'utf8'
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
96 },
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
97 ext => '.tt',
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
98 initializer => 'global.tt'
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
99 );
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
100
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
101 my $doc = $loader->document('simple');
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
102
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
103 assert(defined $doc);
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
104
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
105 my $factory = $doc->require('My/Org/Panel');
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
106
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
107 assert(defined $factory);
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
108
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
109 assert($factory == $doc->require('My/Org/Panel'), "Control should be loaded only once");
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
110
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
111 my $ctl = $factory->new('information', { visualClass => 'simple' } );
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
112
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
113 assert(defined $ctl);
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
114
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
115
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
116 assert($ctl->nodeName eq 'information', "Created control should have a name", "Got: ".$ctl->nodeName, "Expected: information");
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
117
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
118 assert($ctl->nodeProperty('visualClass') eq 'simple');
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
119
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
120 assert($ctl->controlObject == $ctl);
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
121
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
122 assert($factory->instances == 1);
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
123
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
124 assert($doc->context->stash->get('My.Org.Panel') == $factory);
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
125
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
126 my $text = $ctl->Render();
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
127 my $expected = read_file($this->GetResourceFile('Resources', 'TTView.Output', 'Panel.txt'), binmode => ':utf8');
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
128
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
129 assert($text eq $expected, '$ctl->Render(): Bad output', "Got: $text", "Expected: $expected");
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
130
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
131 };
6c0fee769b0c IMPL::Web::View::TTControl tests, fixes
cin
parents: 185
diff changeset
132
183
2184fa28b49e IMPL::Web::View::TTLoader tests
cin
parents:
diff changeset
133 1;