Permalink
Browse files

Added basic test

  • Loading branch information...
1 parent 9794cee commit eeebe687cf1eb9a71680cdc686dce8b9c208097d typester committed Jul 25, 2006
Showing with 91 additions and 0 deletions.
  1. +91 −0 t/02_basic.t
View
@@ -0,0 +1,91 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+{
+ package TestApp;
+
+ use Catalyst qw/
+ FormValidator::Simple
+ FormValidator::Simple::Auto
+ /;
+
+ __PACKAGE__->config(
+ name => 'TestApp',
+ validator => {
+ profiles => {
+ action1 => {
+ param1 => ['NOT_BLANK', 'ASCII'],
+ },
+ action2_submit => {
+ param1 => ['NOT_BLANK', 'ASCII'],
+ },
+ },
+ },
+ );
+ __PACKAGE__->setup;
+
+ sub action1 : Global {
+ my ( $self, $c ) = @_;
+
+ if ($c->form->has_error) {
+ $c->res->body( $c->form->error('param1') );
+ }
+ else {
+ $c->res->body('no errors');
+ }
+ }
+
+ sub action2 : Global {
+ my ( $self, $c ) = @_;
+
+ if ($c->req->method eq 'POST') {
+ $c->forward('action2_submit');
+ }
+ else {
+ $c->res->body('no $c->form executed');
+ }
+ }
+
+ sub action2_submit : Private {
+ my ( $self, $c ) = @_;
+
+ if ($c->form->has_error) {
+ $c->res->body( $c->form->error('param1') );
+ }
+ else {
+ $c->res->body('no errors');
+ }
+ }
+}
+
+use Catalyst::Test 'TestApp';
+use Test::More tests => 14;
+
+use HTTP::Request::Common;
+
+# action driven validation
+ok( my $res = request('/action1'), 'request ok' );
+is( $res->content, 'NOT_BLANK', 'is NOT_BLANK error');
+
+ok( $res = request('/action1?param1=aaa bbb'), 'request ok' );
+is( $res->content, 'ASCII', 'is ASCII error');
+
+ok( $res = request('/action1?param1=aaa'), 'request ok' );
+is( $res->content, 'no errors', 'is no errors');
+
+
+# forward driven validation
+ok( $res = request(POST '/action2', [ param1 => '' ]), 'request ok' );
+is( $res->content, 'NOT_BLANK', 'is NOT_BLANK error');
+
+ok( $res = request(POST '/action2', [ param1 => 'aaa bbb' ]), 'request ok' );
+is( $res->content, 'ASCII', 'is ASCII error');
+
+ok( $res = request(POST '/action2', [ param1 => 'ab' ]), 'request ok' );
+is( $res->content, 'no errors', 'is no errors');
+
+ok( $res = request('/action2'), 'request ok' );
+is( $res->content, 'no $c->form executed', 'is no $c->form executed');
+

0 comments on commit eeebe68

Please sign in to comment.