aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/TestMech.pm
diff options
context:
space:
mode:
authorEdmund von der Burg <evdb@mysociety.org>2011-03-25 15:09:53 +0000
committerEdmund von der Burg <evdb@mysociety.org>2011-03-25 15:09:53 +0000
commit47bf5d345fca67912d5f061813f22e599b2bb1d5 (patch)
tree8e9e2075bcae68d8b3eb558de5379b374c4a2130 /perllib/FixMyStreet/TestMech.pm
parent20ae747d9a49473e5664b27156d7fefd38eb6333 (diff)
More tests (and fixes to issues thrown up)
Diffstat (limited to 'perllib/FixMyStreet/TestMech.pm')
-rw-r--r--perllib/FixMyStreet/TestMech.pm36
1 files changed, 36 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 03ece6c47..94e87f50b 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -8,6 +8,7 @@ use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App';
use Test::More;
use Web::Scraper;
+use Carp;
=head1 NAME
@@ -84,4 +85,39 @@ sub extract_location {
};
}
+=head2 visible_form_values
+
+ $hashref = $mech->visible_form_values( );
+
+Return all the visible form values on the page - ie not the hidden ones.
+
+=cut
+
+sub visible_form_values {
+ my $mech = shift;
+
+ my @forms = $mech->forms;
+
+ # insert form filtering here (eg ignore login form)
+
+ croak "Found no forms - can't continue..."
+ unless @forms;
+ croak "Found several forms - don't know which to use..."
+ if @forms > 1;
+
+ my $form = $forms[0];
+
+ my @visible_fields =
+ grep { ref($_) ne 'HTML::Form::SubmitInput' }
+ grep { ref($_) ne 'HTML::Form::ImageInput' }
+ grep { ref($_) ne 'HTML::Form::TextInput' || $_->type ne 'hidden' }
+ $form->inputs;
+
+ my @visible_field_names = map { $_->name } @visible_fields;
+
+ my %params = map { $_ => $form->value($_) } @visible_field_names;
+
+ return \%params;
+}
+
1;