aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm3
-rw-r--r--t/app/controller/around.t31
3 files changed, 37 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index 4c5c36106..7b98f01f8 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -254,6 +254,9 @@ sub check_and_stash_category : Private {
distinct => 1
}
)->all_sorted;
+ # Ensure only uniquely named categories are shown
+ my %seen;
+ @categories = grep { !$seen{$_->category_display}++ } @categories;
$c->stash->{filter_categories} = \@categories;
my %categories_mapped = map { $_->category => 1 } @categories;
$c->forward('/report/stash_category_groups', [ \@categories ]) if $c->cobrand->enable_category_groups;
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index 9d57c5e1d..52a3a8cef 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -197,6 +197,9 @@ sub setup_page_data : Private {
distinct => 1,
order_by => [ "$table.category" ],
} )->all;
+ # Ensure only uniquely named categories are shown
+ my %seen;
+ @categories = grep { !$seen{$_->category_display}++ } @categories;
$c->stash->{filter_categories} = \@categories;
if ($c->cobrand->enable_category_groups) {
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index 29752ab02..3f5d31c02 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -309,6 +309,37 @@ subtest 'check category, status and extra filtering works on /around' => sub {
is scalar @$pins, 1, 'correct number of external_body reports';
};
+subtest 'check categories with same name are only shown once in filters' => sub {
+ my $params = {
+ postcode => 'OX20 1SZ',
+ latitude => 51.754926,
+ longitude => -1.256179,
+ };
+ my $bbox = ($params->{longitude} - 0.01) . ',' . ($params->{latitude} - 0.01)
+ . ',' . ($params->{longitude} + 0.01) . ',' . ($params->{latitude} + 0.01);
+
+ my $district = $mech->create_body_ok(2421, "Oxford City");
+ # Identically-named categories should be combined even if their extra metadata is different
+ my $contact2 = $mech->create_contact_ok( category => "Pothole", body_id => $district->id, email => 'pothole@district-example.org' );
+ $contact2->set_extra_metadata(some_extra_field => "dummy");
+ $contact2->update;
+ # And categories with the same display name should be combined too
+ my $contact3 = $mech->create_contact_ok( category => "Pothole (alternative)", body_id => $district->id, email => 'pothole-alternative@district-example.org' );
+ $contact3->set_extra_metadata(display_name => "Pothole");
+ $contact3->update;
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'fixmystreet',
+ MAPIT_URL => 'http://mapit.uk/',
+ COBRAND_FEATURES => { category_groups => { fixmystreet => 1 } },
+ }, sub {
+ $mech->get_ok( '/around?bbox=' . $bbox );
+ $mech->content_contains('<option value="Pothole">');
+ $mech->content_unlike(qr{Pothole</option>.*<option value="Pothole">\s*Pothole</option>}s, "Pothole category only appears once");
+ $mech->content_lacks('<option value="Pothole (alternative)">');
+ };
+};
+
subtest 'check old problems not shown by default on around page' => sub {
my $params = {
postcode => 'OX20 1SZ',