aboutsummaryrefslogtreecommitdiffstats
path: root/t/cobrand
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-04-19 18:24:32 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-04-23 15:39:51 +0100
commit41a5f14388e92fa9dbbb5dc3a72d9ad83291eeb4 (patch)
tree8c374383eb4adc94fa4066291d4563f8444bcb5e /t/cobrand
parent76c8fe259443c88d644b738d6b88e054d03c3078 (diff)
Add way of validating data in report_form_extras.
Diffstat (limited to 't/cobrand')
-rw-r--r--t/cobrand/form_extras.t35
1 files changed, 31 insertions, 4 deletions
diff --git a/t/cobrand/form_extras.t b/t/cobrand/form_extras.t
index 84ded5bc1..df76ccbe1 100644
--- a/t/cobrand/form_extras.t
+++ b/t/cobrand/form_extras.t
@@ -2,7 +2,10 @@ package FixMyStreet::Cobrand::Tester;
use parent 'FixMyStreet::Cobrand::FixMyStreet';
sub report_form_extras {
- ( { name => 'address', required => 1 }, { name => 'passport', required => 0 } )
+ (
+ { name => 'address', required => 1 },
+ { name => 'passport', required => 0, validator => sub { die "Invalid number\n" if $_[0] && $_[0] !~ /^P/; return $_[0] } },
+ )
}
# To allow a testing template override
@@ -30,6 +33,7 @@ FixMyStreet::override_config {
$mech->get_ok('/around');
$mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" );
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
+
$mech->submit_form_ok( {
button => 'submit_register',
with_fields => {
@@ -38,13 +42,24 @@ FixMyStreet::override_config {
name => 'Joe Bloggs',
may_show_name => '1',
username => 'test-1@example.com',
- passport => '123456',
password_register => '',
}
},
- "submit details without address, with passport",
+ "submit details without address or passport",
);
$mech->content_like(qr{<label for="form_address">Address</label>\s*<p class='form-error'>This information is required</p>}, 'Address is required');
+ $mech->content_lacks("<p class='form-error'>Invalid number", 'Passport is optional');
+
+ $mech->submit_form_ok( {
+ button => 'submit_register',
+ with_fields => {
+ passport => '123456',
+ }
+ },
+ "submit details with bad passport",
+ );
+ $mech->content_like(qr{<label for="form_address">Address</label>\s*<p class='form-error'>This information is required</p>}, 'Address is required');
+ $mech->content_like(qr{<p class='form-error'>Invalid number}, 'Passport format wrong');
$mech->content_contains('value="123456" name="passport"', 'Passport number reshown');
$mech->submit_form_ok( {
@@ -55,11 +70,23 @@ FixMyStreet::override_config {
},
"submit details, now with address",
);
+ $mech->content_lacks('This information is required', 'Address is present');
+ $mech->content_like(qr{<p class='form-error'>Invalid number}, 'Passport format wrong');
+ $mech->content_contains('value="123456" name="passport"', 'Passport number reshown');
+
+ $mech->submit_form_ok( {
+ button => 'submit_register',
+ with_fields => {
+ passport => 'P123456',
+ }
+ },
+ "submit details with correct passport",
+ );
$mech->content_contains('Now check your email');
my $problem = FixMyStreet::DB->resultset('Problem')->search({}, { order_by => '-id' })->first;
is $problem->get_extra_metadata('address'), 'My address', 'Address is stored';
- is $problem->get_extra_metadata('passport'), '123456', 'Passport number is stored';
+ is $problem->get_extra_metadata('passport'), 'P123456', 'Passport number is stored';
};
END {