diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-03-08 17:26:04 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-03-09 15:31:40 +0000 |
commit | a5636fc2acd3e03b853f3644fedc054e3eb8b905 (patch) | |
tree | d4e60f0e25c27574045fd069df9904f55dc3a1fb /t/cobrand/form_extras.t | |
parent | b3c925c1b76b93e7c952f1925a959346fae72bef (diff) |
Add cobrand-specific custom reporting fields.
This adds a new cobrand variable, report_form_extras, which contains a
list of extra fields that will be saved in the 'extra' metadata of the
report. Fields may optionally be marked as required.
Diffstat (limited to 't/cobrand/form_extras.t')
-rw-r--r-- | t/cobrand/form_extras.t | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/t/cobrand/form_extras.t b/t/cobrand/form_extras.t new file mode 100644 index 000000000..9c20b7ad4 --- /dev/null +++ b/t/cobrand/form_extras.t @@ -0,0 +1,73 @@ +use strict; +use warnings; + +package FixMyStreet::Cobrand::Tester; +use parent 'FixMyStreet::Cobrand::FixMyStreet'; + +sub report_form_extras { + ( { name => 'address', required => 1 }, { name => 'passport', required => 0 } ) +} + +# To allow a testing template override +sub path_to_web_templates { + my $self = shift; + return [ + FixMyStreet->path_to( 't/cobrand/form_extras/templates' )->stringify, + FixMyStreet->path_to( 'templates/web/fixmystreet' )->stringify + ]; +} + +package main; + +use Test::More; +use FixMyStreet::TestMech; + +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + +my $mech = FixMyStreet::TestMech->new; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { tester => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $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 => { + title => 'Test Report', + detail => 'Test report details.', + name => 'Joe Bloggs', + may_show_name => '1', + email => 'test-1@example.com', + passport => '123456', + password_register => '', + } + }, + "submit details without address, with 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_contains('value="123456" name="passport"', 'Passport number reshown'); + + $mech->submit_form_ok( { + button => 'submit_register', + with_fields => { + address => 'My address', + } + }, + "submit details, now with address", + ); + $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'; +}; + +END { + $mech->delete_problems_for_body(undef); + done_testing(); +} |