[Catalyst] [Patch] Tests for Catalyst::View::TT

Daniel Westermann-Clark daniel at acceleration.net
Thu Nov 17 16:44:00 CET 2005


Since I broke Catalyst::View::TT the other day, I thought it would be
a good idea to contribute some tests for it.

Attached is a patch which checks basic functionality of the TT view
using a simple test application and Catalyst::Test.  Both package- and
application-level configuration of view classes are tested, as is the
TEMPLATE_EXTENSION feature.

Ideas for improvement gladly accepted.

-- 
Daniel Westermann-Clark
-------------- next part --------------
==== Patch <tt-tests> level 1
Source: 462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/Catalyst:2340 [local]
Target: 4ad37cd2-5fec-0310-835f-b3785c72a374:/:2026 [mirrored]
        (http://dev.catalyst.perl.org/repos/Catalyst)
Log:
 r2007 at fortuna:  dwc | 2005-11-16 17:23:24 -0500
 Copying Catalyst tree for local changes
 r2008 at fortuna:  dwc | 2005-11-16 17:30:20 -0500
 Add basic tests, using both package config and application-level config

=== trunk/Catalyst-View-TT/t/lib/TestApp/root/test.tt
==================================================================
--- trunk/Catalyst-View-TT/t/lib/TestApp/root/test.tt	(revision 2026)
+++ trunk/Catalyst-View-TT/t/lib/TestApp/root/test.tt	(patch tt-tests level 1)
@@ -0,0 +1 @@
+[% message %]
=== trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Appconfig.pm
==================================================================
--- trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Appconfig.pm	(revision 2026)
+++ trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Appconfig.pm	(patch tt-tests level 1)
@@ -0,0 +1,6 @@
+package TestApp::View::TT::Appconfig;
+
+use strict;
+use base 'Catalyst::View::TT';
+
+1;
=== trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Pkgconfig.pm
==================================================================
--- trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Pkgconfig.pm	(revision 2026)
+++ trunk/Catalyst-View-TT/t/lib/TestApp/View/TT/Pkgconfig.pm	(patch tt-tests level 1)
@@ -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;
=== trunk/Catalyst-View-TT/t/lib/TestApp.pm
==================================================================
--- trunk/Catalyst-View-TT/t/lib/TestApp.pm	(revision 2026)
+++ trunk/Catalyst-View-TT/t/lib/TestApp.pm	(patch tt-tests level 1)
@@ -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;
=== trunk/Catalyst-View-TT/t/04pkgconfig.t
==================================================================
--- trunk/Catalyst-View-TT/t/04pkgconfig.t	(revision 2026)
+++ trunk/Catalyst-View-TT/t/04pkgconfig.t	(patch tt-tests level 1)
@@ -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');
+ok($response->content eq TestApp->config->{default_message}, 'message ok');
+
+my $message = scalar localtime;
+ok(($response = request("/test?view=$view&message=$message"))->is_success, 'request with message ok');
+ok($response->content eq $message, 'message ok')
=== trunk/Catalyst-View-TT/t/05appconfig.t
==================================================================
--- trunk/Catalyst-View-TT/t/05appconfig.t	(revision 2026)
+++ trunk/Catalyst-View-TT/t/05appconfig.t	(patch tt-tests level 1)
@@ -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');
+ok($response->content eq TestApp->config->{default_message}, 'message ok');
+
+my $message = scalar localtime;
+ok(($response = request("/test?view=$view&message=$message"))->is_success, 'request with message ok');
+ok($response->content eq $message, 'message ok')


More information about the Catalyst mailing list