View::TT, added tests from dwc
Andy Grundman [Fri, 18 Nov 2005 03:37:59 +0000 (03:37 +0000)]
Changes
lib/Catalyst/View/TT.pm
t/04pkgconfig.t [new file with mode: 0644]
t/05appconfig.t [new file with mode: 0644]
t/lib/TestApp.pm [new file with mode: 0755]
t/lib/TestApp/View/TT/Appconfig.pm [new file with mode: 0755]
t/lib/TestApp/View/TT/Pkgconfig.pm [new file with mode: 0755]
t/lib/TestApp/root/test.tt [new file with mode: 0644]

diff --git a/Changes b/Changes
index 8161070..b0fb54b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension Catalyst::View::TT.
 
+0.20
+        - Added tests. (Daniel Westermann-Clark)
+
 0.19  - Tue Nov 15 09:52:00 2005
         - unbreak config.
 
index 1463bc6..6b7a828 100644 (file)
@@ -6,7 +6,7 @@ use Template;
 use Template::Timer;
 use NEXT;
 
-our $VERSION = '0.19';
+our $VERSION = '0.20';
 
 __PACKAGE__->mk_accessors('template');
 
@@ -30,9 +30,9 @@ Catalyst::View::TT - Template View Class
               MyApp->path_to( 'root', 'src' ), 
               MyApp->path_to( 'root', 'lib' ), 
             ],
-            PRE_PROCESS => 'config/main',
-            WRAPPER     => 'site/wrapper',
-           TEMPLATE_EXTENSION => '.tt',
+            PRE_PROCESS        => 'config/main',
+            WRAPPER            => 'site/wrapper',
+            TEMPLATE_EXTENSION => '.tt',
 
             # two optional config items
             CATALYST_VAR => 'Catalyst',
diff --git a/t/04pkgconfig.t b/t/04pkgconfig.t
new file mode 100644 (file)
index 0000000..9d64e02
--- /dev/null
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use Test::More tests => 5;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use_ok('Catalyst::Test', 'TestApp');
+
+my $view = 'Pkgconfig';
+
+my $response;
+ok(($response = request("/test?view=$view"))->is_success, 'request ok');
+is($response->content, TestApp->config->{default_message}, 'message ok');
+
+my $message = scalar localtime;
+ok(($response = request("/test?view=$view&message=$message"))->is_success, 'request with message ok');
+is($response->content,  $message, 'message ok')
diff --git a/t/05appconfig.t b/t/05appconfig.t
new file mode 100644 (file)
index 0000000..ff6e5fd
--- /dev/null
@@ -0,0 +1,18 @@
+use strict;
+use warnings;
+use Test::More tests => 5;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use_ok('Catalyst::Test', 'TestApp');
+
+my $view = 'Appconfig';
+
+my $response;
+ok(($response = request("/test?view=$view"))->is_success, 'request ok');
+is($response->content, TestApp->config->{default_message}, 'message ok');
+
+my $message = scalar localtime;
+ok(($response = request("/test?view=$view&message=$message"))->is_success, 'request with message ok');
+is($response->content, $message, 'message ok')
diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm
new file mode 100755 (executable)
index 0000000..12d9bc0
--- /dev/null
@@ -0,0 +1,45 @@
+package TestApp;
+
+use strict;
+use warnings;
+
+use Catalyst; # qw/-Debug/;
+
+our $VERSION = '0.01';
+
+__PACKAGE__->config(
+    name                  => 'TestApp',
+    default_message       => 'hi',
+    default_view          => 'Pkgconfig',
+    'View::TT::Appconfig' => {
+        PRE_CHOMP          => 1,
+        POST_CHOMP         => 1,
+        TEMPLATE_EXTENSION => '.tt',
+    },
+);
+
+__PACKAGE__->setup;
+
+sub default : Private {
+    my ($self, $c) = @_;
+
+    $c->response->redirect($c->uri_for('test'));
+}
+
+sub test : Local {
+    my ($self, $c) = @_;
+
+    $c->stash->{message} = ($c->request->param('message') || $c->config->{default_message});
+}
+
+sub end : Private {
+    my ($self, $c) = @_;
+
+    return 1 if $c->response->status =~ /^3\d\d$/;
+    return 1 if $c->response->body;
+
+    my $view = 'View::TT::' . ($c->request->param('view') || $c->config->{default_view});
+    $c->forward($view);
+}
+
+1;
diff --git a/t/lib/TestApp/View/TT/Appconfig.pm b/t/lib/TestApp/View/TT/Appconfig.pm
new file mode 100755 (executable)
index 0000000..562ed03
--- /dev/null
@@ -0,0 +1,6 @@
+package TestApp::View::TT::Appconfig;
+
+use strict;
+use base 'Catalyst::View::TT';
+
+1;
diff --git a/t/lib/TestApp/View/TT/Pkgconfig.pm b/t/lib/TestApp/View/TT/Pkgconfig.pm
new file mode 100755 (executable)
index 0000000..011fab4
--- /dev/null
@@ -0,0 +1,12 @@
+package TestApp::View::TT::Pkgconfig;
+
+use strict;
+use base 'Catalyst::View::TT';
+
+__PACKAGE__->config(
+    PRE_CHOMP          => 1,
+    POST_CHOMP         => 1,
+    TEMPLATE_EXTENSION => '.tt',
+);
+
+1;
diff --git a/t/lib/TestApp/root/test.tt b/t/lib/TestApp/root/test.tt
new file mode 100644 (file)
index 0000000..4a0a2d8
--- /dev/null
@@ -0,0 +1 @@
+[% message %]