[Catalyst-commits] r7613 - in trunk/Catalyst-Plugin-FillInForm/t: . lib

marcus at dev.catalyst.perl.org marcus at dev.catalyst.perl.org
Fri Apr 11 20:48:52 BST 2008


Author: marcus
Date: 2008-04-11 20:48:52 +0100 (Fri, 11 Apr 2008)
New Revision: 7613

Added:
   trunk/Catalyst-Plugin-FillInForm/t/04fillform1.t
   trunk/Catalyst-Plugin-FillInForm/t/04fillform2.t
   trunk/Catalyst-Plugin-FillInForm/t/04fillform3.t
   trunk/Catalyst-Plugin-FillInForm/t/04fillform4.t
   trunk/Catalyst-Plugin-FillInForm/t/lib/
   trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp1.pm
   trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp2.pm
   trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp3.pm
   trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp4.pm
Log:
Updated tests and docs for fillinform

Added: trunk/Catalyst-Plugin-FillInForm/t/04fillform1.t
===================================================================
--- trunk/Catalyst-Plugin-FillInForm/t/04fillform1.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-FillInForm/t/04fillform1.t	2008-04-11 19:48:52 UTC (rev 7613)
@@ -0,0 +1,40 @@
+package main;
+
+#
+# Default behavior of Catalyst::Plugin::FillInForm
+# all params of both forms should auto-fill w/ query params
+#
+
+use Test::More tests => 3;
+use lib 't/lib';
+use Catalyst::Test 'TestApp1';
+
+use HTML::Parser ();
+my $p = HTML::Parser->new(
+   start_h => [\&html_parser_start, "self,tagname,attr"],
+);
+
+my $url = '/?aaa=one&bbb=two&ccc=three&ddd=four';
+
+my $parsed_html;
+{
+    ok( my $response = request($url), 'Normal Request'  );
+    is( $response->code, 200,         'OK status code'  );
+    $p->parse($response->content);
+    is( $parsed_html,
+        "form1:aaa|one|bbb|two|ccc|three|ddd|four|" .
+        "form2:aaa|one|bbb|two|ccc|three|ddd|four|",
+                                      'Re-Parsed HTML'  );
+}
+
+sub html_parser_start {
+    my($self, $tag, $attr) = @_;
+    if ($tag eq "form") {
+       $parsed_html .= $attr->{name} . ":";
+    } elsif ($tag eq "input") {
+       $parsed_html .= sprintf("%s|%s|", $attr->{name}, $attr->{value});
+    }
+}
+
+
+

Added: trunk/Catalyst-Plugin-FillInForm/t/04fillform2.t
===================================================================
--- trunk/Catalyst-Plugin-FillInForm/t/04fillform2.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-FillInForm/t/04fillform2.t	2008-04-11 19:48:52 UTC (rev 7613)
@@ -0,0 +1,40 @@
+package main;
+
+#
+# Default behavior, EXCEPT:
+#    ignore_fields => ['aaa']
+#
+
+use Test::More tests => 3;
+use lib 't/lib';
+use Catalyst::Test 'TestApp2';
+
+use HTML::Parser ();
+my $p = HTML::Parser->new(
+   start_h => [\&html_parser_start, "self,tagname,attr"],
+);
+
+my $url = '/?aaa=one&bbb=two&ccc=three&ddd=four';
+
+my $parsed_html;
+{
+    ok( my $response = request($url), 'Normal Request'  );
+    is( $response->code, 200,         'OK status code'  );
+    $p->parse($response->content);
+    is( $parsed_html,
+        "form1:aaa||bbb|two|ccc|three|ddd|four|" .
+        "form2:aaa||bbb|two|ccc|three|ddd|four|",
+                                      'Re-Parsed HTML'  );
+}
+
+sub html_parser_start {
+    my($self, $tag, $attr) = @_;
+    if ($tag eq "form") {
+       $parsed_html .= $attr->{name} . ":";
+    } elsif ($tag eq "input") {
+       $parsed_html .= sprintf("%s|%s|", $attr->{name}, $attr->{value});
+    }
+}
+
+
+

Added: trunk/Catalyst-Plugin-FillInForm/t/04fillform3.t
===================================================================
--- trunk/Catalyst-Plugin-FillInForm/t/04fillform3.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-FillInForm/t/04fillform3.t	2008-04-11 19:48:52 UTC (rev 7613)
@@ -0,0 +1,41 @@
+package main;
+
+#
+# Default behavior, EXCEPT:
+#    target => 'form2'
+#
+
+use Test::More tests => 3;
+use lib 't/lib';
+use Catalyst::Test 'TestApp3';
+
+use HTML::Parser ();
+my $p = HTML::Parser->new(
+   start_h => [\&html_parser_start, "self,tagname,attr"],
+);
+
+my $url = '/?aaa=one&bbb=two&ccc=three&ddd=four';
+
+my $parsed_html;
+{
+    ok( my $response = request($url), 'Normal Request'  );
+    is( $response->code, 200,         'OK status code'  );
+    $p->parse($response->content);
+    is( $parsed_html,
+        "form1:aaa||bbb||ccc||ddd||" .
+        "form2:aaa|one|bbb|two|ccc|three|ddd|four|",
+                                      'Re-Parsed HTML'  );
+}
+
+
+sub html_parser_start {
+    my($self, $tag, $attr) = @_;
+    if ($tag eq "form") {
+       $parsed_html .= $attr->{name} . ":";
+    } elsif ($tag eq "input") {
+       $parsed_html .= sprintf("%s|%s|", $attr->{name}, $attr->{value});
+    }
+}
+
+
+

Added: trunk/Catalyst-Plugin-FillInForm/t/04fillform4.t
===================================================================
--- trunk/Catalyst-Plugin-FillInForm/t/04fillform4.t	                        (rev 0)
+++ trunk/Catalyst-Plugin-FillInForm/t/04fillform4.t	2008-04-11 19:48:52 UTC (rev 7613)
@@ -0,0 +1,41 @@
+package main;
+
+#
+# Default behavior, EXCEPT:
+#    fill_password => 0
+#
+
+use Test::More tests => 3;
+use lib 't/lib';
+use Catalyst::Test 'TestApp4';
+
+use HTML::Parser ();
+my $p = HTML::Parser->new(
+   start_h => [\&html_parser_start, "self,tagname,attr"],
+);
+
+my $url = '/?aaa=one&bbb=two&ccc=three&ddd=four';
+
+my $parsed_html;
+{
+    ok( my $response = request($url), 'Normal Request'  );
+    is( $response->code, 200,         'OK status code'  );
+    $p->parse($response->content);
+    is( $parsed_html,
+        "form1:aaa|one|bbb|two|ccc|three|ddd||" .
+        "form2:aaa|one|bbb|two|ccc|three|ddd||",
+                                      'Re-Parsed HTML'  );
+}
+
+
+sub html_parser_start {
+    my($self, $tag, $attr) = @_;
+    if ($tag eq "form") {
+       $parsed_html .= $attr->{name} . ":";
+    } elsif ($tag eq "input") {
+       $parsed_html .= sprintf("%s|%s|", $attr->{name}, $attr->{value});
+    }
+}
+
+
+

Added: trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp1.pm
===================================================================
--- trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp1.pm	                        (rev 0)
+++ trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp1.pm	2008-04-11 19:48:52 UTC (rev 7613)
@@ -0,0 +1,50 @@
+package TestApp1;
+
+#
+# Default behavior of Catalyst::Plugin::FillInForm
+# all params of both forms should auto-fill w/ query params
+#
+
+use Catalyst qw( FillInForm );
+
+__PACKAGE__->config(
+    name=>"FillInForm test"
+);
+
+__PACKAGE__->setup();
+
+my $html = <<EOT;
+<html>
+<head></head>
+<body>
+<form name="form1" action="" method="POST">
+<input name="aaa">
+<input name="bbb">
+<input name="ccc" type="hidden">
+<input name="ddd" type="password">
+</form>
+
+<form name="form2" action="" method="POST">
+<input name="aaa">
+<input name="bbb">
+<input name="ccc" type="hidden">
+<input name="ddd" type="password">
+</form>
+</body>
+</html>
+EOT
+
+
+sub index : Global {
+   my ( $self, $c, $arg ) = @_;
+   $c->res->body($html);
+}
+
+sub end : Private {
+   my ($self, $c) = @_;
+   $c->forward('render');
+   $c->fillform();
+}
+sub render : ActionClass('RenderView') { }
+
+1;

Added: trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp2.pm
===================================================================
--- trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp2.pm	                        (rev 0)
+++ trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp2.pm	2008-04-11 19:48:52 UTC (rev 7613)
@@ -0,0 +1,52 @@
+package TestApp2;
+
+#
+# Default behavior, EXCEPT:
+#    ignore_fields => ['aaa']
+#
+
+use Catalyst qw( FillInForm );
+
+__PACKAGE__->config(
+    name=>"FillInForm test"
+);
+
+__PACKAGE__->setup();
+
+my $html = <<EOT;
+<html>
+<head></head>
+<body>
+<form name="form1" action="" method="POST">
+<input name="aaa">
+<input name="bbb">
+<input name="ccc" type="hidden">
+<input name="ddd" type="password">
+</form>
+
+<form name="form2" action="" method="POST">
+<input name="aaa">
+<input name="bbb">
+<input name="ccc" type="hidden">
+<input name="ddd" type="password">
+</form>
+</body>
+</html>
+EOT
+
+
+sub index : Global {
+   my ( $self, $c, $arg ) = @_;
+   $c->res->body($html);
+}
+
+sub end : Private {
+   my ($self, $c) = @_;
+   $c->forward('render');
+   $c->fillform($c->req->params, {
+      ignore_fields => [ 'aaa' ],
+   });
+}
+sub render : ActionClass('RenderView') { }
+
+1;

Added: trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp3.pm
===================================================================
--- trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp3.pm	                        (rev 0)
+++ trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp3.pm	2008-04-11 19:48:52 UTC (rev 7613)
@@ -0,0 +1,52 @@
+package TestApp3;
+
+#
+# Default behavior, EXCEPT:
+#    target => 'form2'
+#
+
+use Catalyst qw( FillInForm );
+
+__PACKAGE__->config(
+    name=>"FillInForm test"
+);
+
+__PACKAGE__->setup();
+
+my $html = <<EOT;
+<html>
+<head></head>
+<body>
+<form name="form1" action="" method="POST">
+<input name="aaa">
+<input name="bbb">
+<input name="ccc" type="hidden">
+<input name="ddd" type="password">
+</form>
+
+<form name="form2" action="" method="POST">
+<input name="aaa">
+<input name="bbb">
+<input name="ccc" type="hidden">
+<input name="ddd" type="password">
+</form>
+</body>
+</html>
+EOT
+
+
+sub index : Global {
+   my ( $self, $c, $arg ) = @_;
+   $c->res->body($html);
+}
+
+sub end : Private {
+   my ($self, $c) = @_;
+   $c->forward('render');
+   $c->fillform($c->req->params, {
+      target => 'form2',
+   });
+}
+sub render : ActionClass('RenderView') { }
+
+1;

Added: trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp4.pm
===================================================================
--- trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp4.pm	                        (rev 0)
+++ trunk/Catalyst-Plugin-FillInForm/t/lib/TestApp4.pm	2008-04-11 19:48:52 UTC (rev 7613)
@@ -0,0 +1,52 @@
+package TestApp4;
+
+#
+# Default behavior, EXCEPT:
+#    fill_password => 0
+#
+
+use Catalyst qw( FillInForm );
+
+__PACKAGE__->config(
+    name=>"FillInForm test"
+);
+
+__PACKAGE__->setup();
+
+my $html = <<EOT;
+<html>
+<head></head>
+<body>
+<form name="form1" action="" method="POST">
+<input name="aaa">
+<input name="bbb">
+<input name="ccc" type="hidden">
+<input name="ddd" type="password">
+</form>
+
+<form name="form2" action="" method="POST">
+<input name="aaa">
+<input name="bbb">
+<input name="ccc" type="hidden">
+<input name="ddd" type="password">
+</form>
+</body>
+</html>
+EOT
+
+
+sub index : Global {
+   my ( $self, $c, $arg ) = @_;
+   $c->res->body($html);
+}
+
+sub end : Private {
+   my ($self, $c) = @_;
+   $c->forward('render');
+   $c->fillform($c->req->params, {
+      fill_password => 0,
+   });
+}
+sub render : ActionClass('RenderView') { }
+
+1;




More information about the Catalyst-commits mailing list