aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-02-13 13:20:11 +0000
committerMatthew Somerville <matthew@mysociety.org>2020-02-13 13:25:03 +0000
commit90ba1eec155c8b785b52a842fb8157aacf53d555 (patch)
tree110f1aff075ceb39e508eb4b74559e7e80b6929a /t
parent06c0c23a9de9fb1c3d57daaa4d9358ffd143a5d5 (diff)
Allow anonymous reporting on per-category basis.
Diffstat (limited to 't')
-rw-r--r--t/app/controller/report_new_anon.t53
1 files changed, 53 insertions, 0 deletions
diff --git a/t/app/controller/report_new_anon.t b/t/app/controller/report_new_anon.t
index b14814f59..d86bc8134 100644
--- a/t/app/controller/report_new_anon.t
+++ b/t/app/controller/report_new_anon.t
@@ -8,6 +8,15 @@ use parent 'FixMyStreet::Cobrand::FixMyStreet';
sub allow_anonymous_reports { 'button' }
sub anonymous_account { { email => 'anonbutton@example.org', name => 'Anonymous Button' } }
+package FixMyStreet::Cobrand::AnonAllowedForCategory;
+use parent 'FixMyStreet::Cobrand::FixMyStreet';
+sub allow_anonymous_reports {
+ my ($self, $category) = @_;
+ $category ||= $self->{c}->stash->{category};
+ return 'button' if $category eq 'Trees';
+}
+sub anonymous_account { { email => 'anoncategory@example.org', name => 'Anonymous Category' } }
+
package main;
use FixMyStreet::TestMech;
@@ -216,4 +225,48 @@ subtest "test report creation anonymously by staff user" => sub {
};
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'anonallowedforcategory',
+ MAPIT_URL => 'http://mapit.uk/',
+}, sub {
+
+subtest "test report creation anonymously by button, per category" => 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_category_part_only',
+ with_fields => {
+ category => 'Street lighting',
+ }
+ }, "submit category with no anonymous reporting");
+ $mech->content_lacks('<button name="report_anonymously" value="yes" class="btn btn--block">'); # non-JS button, JS button always there
+ $mech->submit_form_ok({
+ button => 'submit_register',
+ with_fields => {
+ category => 'Trees',
+ }
+ }, "submit category with anonymous reporting");
+
+ $mech->submit_form_ok({
+ button => 'report_anonymously',
+ with_fields => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ }
+ }, "submit good details");
+ $mech->content_contains('Thank you');
+
+ my $report = FixMyStreet::DB->resultset("Problem")->search({}, { order_by => { -desc => 'id' } })->first;
+ ok $report, "Found the report";
+
+ is $report->state, 'confirmed', "report confirmed";
+ is $report->bodies_str, $body->id;
+ is $report->name, 'Anonymous Category';
+ is $report->anonymous, 1; # Doesn't change behaviour here, but uses anon account's name always
+ is $report->get_extra_metadata('contributed_as'), 'anonymous_user';
+};
+
+};
+
done_testing();