aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-09-03 15:56:49 +0100
committerStruan Donald <struan@exo.org.uk>2012-09-03 15:56:49 +0100
commitbef1a31660bd3fccdda72cf2ca670c207a7a54c2 (patch)
treed204ad488d25e767683d195ba60e1175102f5eba
parent5cd05ec4aba592894fd15c0351227fb93df147ea (diff)
do not display non public reports in reports list for a council
do include non public reports in council stats
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm4
-rw-r--r--perllib/FixMyStreet/TestMech.pm43
-rw-r--r--t/app/controller/reports.t97
3 files changed, 141 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 37766db44..dd725be19 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -236,6 +236,7 @@ sub council_check : Private {
type => $area_types,
min_generation => $c->cobrand->area_min_generation
);
+
if (keys %$areas == 1) {
($c->stash->{council}) = values %$areas;
return;
@@ -318,7 +319,8 @@ sub load_and_group_problems : Private {
my $page = $c->req->params->{p} || 1;
my $where = {
- state => [ FixMyStreet::DB::Result::Problem->visible_states() ]
+ non_public => 0,
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ]
};
if ($c->stash->{ward}) {
$where->{areas} = { 'like', '%,' . $c->stash->{ward}->{id} . ',%' };
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 2a49cc2f8..53ec7ad89 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -378,6 +378,49 @@ sub extract_update_metas {
return \@metas;
}
+=head2 extract_problem_list
+
+ $problems = $mech->extract_problem_list
+
+Returns an array ref of all problem titles on a page featuring standard issue lists
+
+=cut
+
+sub extract_problem_list {
+ my $mech = shift;
+
+ my $result = scraper {
+ process 'ul.issue-list-a li a h4', 'problems[]', 'TEXT';
+ }->scrape( $mech->response );
+
+ return $result->{ problems } || [];
+}
+
+=head2 extract_report_stats
+
+ $stats = $mech->extract_report_stats
+
+Returns a hash ref keyed by council name of all the council stats from the all reports
+page. Each value is an array ref with the first element being the council name and the
+rest being the stats in the order the appear in each row.
+
+=cut
+
+sub extract_report_stats {
+ my $mech = shift;
+
+ my $result = scraper {
+ process 'tr[align=center]', 'councils[]' => scraper {
+ process 'td.title a', 'council', 'TEXT',
+ process 'td', 'stats[]', 'TEXT'
+ }
+ }->scrape( $mech->response );
+
+ my %councils = map { $_->{council} => $_->{stats} } @{ $result->{councils} };
+
+ return \%councils;
+}
+
=head2 visible_form_values
$hashref = $mech->visible_form_values( );
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index 801dbeddb..5fd1a9962 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -1,10 +1,21 @@
use strict;
use warnings;
use Test::More;
-use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App';
+use FixMyStreet::TestMech;
use mySociety::MaPit;
+use FixMyStreet::App;
+use DateTime;
-ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' );
+ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
+
+delete_problems( 2504 );
+delete_problems( 2651 );
+
+my @westminster_problems = create_problems(5, 2504);
+my @edinburgh_problems = create_problems(3, 2651);
+
+is scalar @westminster_problems, 5, 'correct number of westminster problems created';
+is scalar @edinburgh_problems, 3, 'correct number of edinburgh problems created';
# Run the cron script that makes the data for /reports so we don't get an error.
system( "bin/cron-wrapper update-all-reports" );
@@ -13,8 +24,35 @@ system( "bin/cron-wrapper update-all-reports" );
$mech->get_ok('/reports');
$mech->title_like(qr{Summary reports});
$mech->content_contains('Birmingham');
+
+my $stats = $mech->extract_report_stats;
+
+is $stats->{'City of Edinburgh Council'}->[1], 3, 'correct number of reports for Edinburgh';
+is $stats->{'Westminster City Council'}->[1], 5, 'correct number of reports for Westminster';
+
$mech->follow_link_ok( { text_regex => qr/Birmingham/ } );
+$mech->get_ok('/reports/Westminster');
+$mech->title_like(qr/Westminster City Council/);
+$mech->content_contains('Westminster City Council');
+$mech->content_contains('All reports Test 3 for 2504', 'problem to be marked non public visible');
+
+my $problems = $mech->extract_problem_list;
+is scalar @$problems, 5, 'correct number of problems displayed';
+
+my $private = $westminster_problems[2];
+ok $private->update( { non_public => 1 } ), 'problem marked non public';
+
+$mech->get_ok('/reports/Westminster');
+$problems = $mech->extract_problem_list;
+is scalar @$problems, 4, 'only public problems are displayed';
+
+$mech->content_lacks('All reports Test 3 for 2504', 'non public problem is not visible');
+
+$mech->get_ok('/reports');
+$stats = $mech->extract_report_stats;
+is $stats->{'Westminster City Council'}->[1], 5, 'non public reports included in stats';
+
SKIP: {
skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 8 )
unless FixMyStreet::Cobrand->exists('emptyhomes');
@@ -33,5 +71,60 @@ SKIP: {
$mech->content_unlike(qr{Oslo">Oslo.*Oslo}s);
}
+sub create_problems {
+ my $count = shift;
+ my $area_id = shift;
+
+ my @problems;
+
+ my $dt = DateTime->now;
+
+ my $user =
+ FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
+
+ while ( $count ) {
+ my $problem = FixMyStreet::App->model('DB::Problem')->create( {
+ postcode => 'SW1A 1AA',
+ council => $area_id,
+ areas => ',105255,11806,11828,2247,2504,',
+ category => 'Other',
+ title => "All reports Test $count for $area_id",
+ detail => "All reports Test $count for $area_id Detail",
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '51.5016605453401',
+ longitude => '-0.142497580865087',
+ user_id => $user->id,
+ } );
+
+ push @problems, $problem;
+ $count--;
+ }
+
+
+ return @problems;
+}
+
+sub delete_problems {
+ my $area_id = shift;
+
+ my $reports = FixMyStreet::App->model('DB::Problem')->search( { council => $area_id } );
+ if ( $reports ) {
+ for my $r ( $reports->all ) {
+ $r->comments->delete;
+ }
+ $reports->delete;
+ }
+}
+
done_testing();