[Jifty-commit] r2565 - in Test-WWW-Declare: lib/Test/WWW t
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Fri Jan 26 00:24:08 EST 2007
Author: jesse
Date: Fri Jan 26 00:24:06 2007
New Revision: 2565
Modified:
Test-WWW-Declare/ (props changed)
Test-WWW-Declare/lib/Test/WWW/Declare.pm
Test-WWW-Declare/t/basic_live_forms.t
Test-WWW-Declare/t/skip.t
Log:
r21330 at hualien: jesse | 2007-01-26 13:20:16 +0800
* support for forms and for skips
Modified: Test-WWW-Declare/lib/Test/WWW/Declare.pm
==============================================================================
--- Test-WWW-Declare/lib/Test/WWW/Declare.pm (original)
+++ Test-WWW-Declare/lib/Test/WWW/Declare.pm Fri Jan 26 00:24:06 2007
@@ -9,16 +9,28 @@
use WWW::Mechanize;
use Test::Builder;
-our @EXPORT = qw(flow run get session check mech match follow link content should click href button );
+our @EXPORT = qw(flow run get session check mech match follow link content should click href button fill form SKIP);
our $BUILDER = Test::Builder->new();
$BUILDER->no_plan();
our $WWW_MECHANIZE;
+
+
+
+sub SKIP ($) {
+ my $reason = shift;
+ die "SKIP: $reason";
+}
+
+
sub flow ($$) {
my $definition = shift;
my $coderef = shift;
eval { $coderef->(); };
- if ($@) {
+ if ($@ =~/^SKIP: (.*)$/) {
+ my $reason = $1;
+ $BUILDER->skip($reason);
+ } elsif ($@) {
$BUILDER->ok(0, $definition. ": ". $@);
die $@;
} else {
@@ -49,7 +61,10 @@
my $coderef = shift;
local $WWW_MECHANIZE = WWW::Mechanize->new();
eval { $coderef->() };
- if ($@) {
+ if ($@ =~/^SKIP: (.*)$/) {
+ my $reason = $1;
+ $BUILDER->skip($reason);
+ } elsif ($@) {
$BUILDER->ok(0, $title );
} else {
$BUILDER->ok(1,$title);
@@ -71,15 +86,23 @@
}
-sub href ($) { return shift }
+sub href ($) { return (shift , 'href') }
+sub button ($) { return( shift , 'button') }
-sub click ($) {
+sub click {
my $link = shift;
+ my $type;
+ $type = shift if ($_[0]);
my $ret;
+ if ($type eq 'button') {
+ return mech()->click_button(value => $link);
+ }
+ else {
unless (ref $link eq 'Regexp') {
die "click doesn't know what to do with a link type of ".ref($link);
}
return follow_link(text_regex => $link);
+ }
}
sub content ($) {
@@ -94,5 +117,19 @@
my $item = shift;
return $item;
}
+
+sub form ($$) {
+ my $form_name = shift;
+ my $data = shift;
+ mech()->form_name($form_name);
+ return ($data);
+}
+
+sub fill {
+ my $data = shift; # as a hashref
+ mech()->set_fields(%{$data});
+}
+
+
1;
Modified: Test-WWW-Declare/t/basic_live_forms.t
==============================================================================
--- Test-WWW-Declare/t/basic_live_forms.t (original)
+++ Test-WWW-Declare/t/basic_live_forms.t Fri Jan 26 00:24:06 2007
@@ -8,13 +8,13 @@
flow "google searches work" => check {
get 'http://google.com/ncr';
# google.com/ would get us a country specific page
- fill form 'search' => {
+ fill form 'f' => {
q => 'Squeamish ossifrage'
};
# These two are the same thing:
#submit form 'search';
- click button 'Search!';
+ click button 'Google Search';
}
};
Modified: Test-WWW-Declare/t/skip.t
==============================================================================
--- Test-WWW-Declare/t/skip.t (original)
+++ Test-WWW-Declare/t/skip.t Fri Jan 26 00:24:06 2007
@@ -6,15 +6,9 @@
session "check logins" => run {
flow "google searches work" => check {
- get 'http://google.com/ncr';
- # google.com/ would get us a country specific page
- fill form 'search' => {
- q => 'Squeamish ossifrage'
- };
- # These two are the same thing:
- #submit form 'search';
- click button 'Search!';
+ SKIP "We're just testing skip";
+
}
};
More information about the Jifty-commit
mailing list