use Test::MockTime ':all'; use strict; use warnings; use FixMyStreet::TestMech; use Web::Scraper; set_absolute_time('2014-02-01T12:00:00'); my $mech = FixMyStreet::TestMech->new; my $other_body = $mech->create_body_ok(1234, 'Some Other Council'); my $body = $mech->create_body_ok(2651, 'City of Edinburgh Council'); my @cats = ('Litter', 'Other', 'Potholes', 'Traffic lights'); for my $contact ( @cats ) { $mech->create_contact_ok(body_id => $body->id, category => $contact, email => "$contact\@example.org"); } my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1); my $counciluser = $mech->create_user_ok('counciluser@example.com', name => 'Council User', from_body => $body); my $normaluser = $mech->create_user_ok('normaluser@example.com', name => 'Normal User'); my $body_id = $body->id; my $area_id = '60705'; my $alt_area_id = '62883'; my $last_month = DateTime->now->subtract(months => 2); $mech->create_problems_for_body(2, $body->id, 'Title', { areas => ",$area_id,2651,", category => 'Potholes', cobrand => 'fixmystreet' }); $mech->create_problems_for_body(3, $body->id, 'Title', { areas => ",$area_id,2651,", category => 'Traffic lights', cobrand => 'fixmystreet', dt => $last_month }); $mech->create_problems_for_body(1, $body->id, 'Title', { areas => ",$alt_area_id,2651,", category => 'Litter', cobrand => 'fixmystreet' }); my @scheduled_problems = $mech->create_problems_for_body(7, $body->id, 'Title', { areas => ",$area_id,2651,", category => 'Traffic lights', cobrand => 'fixmystreet' }); my @fixed_problems = $mech->create_problems_for_body(4, $body->id, 'Title', { areas => ",$area_id,2651,", category => 'Potholes', cobrand => 'fixmystreet' }); my @closed_problems = $mech->create_problems_for_body(3, $body->id, 'Title', { areas => ",$area_id,2651,", category => 'Traffic lights', cobrand => 'fixmystreet' }); foreach my $problem (@scheduled_problems) { $problem->update({ state => 'action scheduled' }); $mech->create_comment_for_problem($problem, $counciluser, 'Title', 'text', 0, 'confirmed', 'action scheduled'); } foreach my $problem (@fixed_problems) { $problem->update({ state => 'fixed - council' }); $mech->create_comment_for_problem($problem, $counciluser, 'Title', 'text', 0, 'confirmed', 'fixed'); } foreach my $problem (@closed_problems) { $problem->update({ state => 'closed' }); $mech->create_comment_for_problem($problem, $counciluser, 'Title', 'text', 0, 'confirmed', 'closed', { confirmed => \'current_timestamp' }); } my $categories = scraper { process "select[name=category] > option", 'cats[]' => 'TEXT', process "table[id=overview] > tr", 'rows[]' => scraper { process 'td', 'cols[]' => 'TEXT' }, }; FixMyStreet::override_config { ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], MAPIT_URL => 'http://mapit.uk/', }, sub { subtest 'not logged in, redirected to login' => sub { $mech->not_logged_in_ok; $mech->get_ok('/dashboard'); $mech->content_contains( 'sign in' ); }; subtest 'normal user, 404' => sub { $mech->log_in_ok( $normaluser->email ); $mech->get('/dashboard'); is $mech->status, '404', 'If not council user get 404'; }; subtest 'superuser, body list' => sub { $mech->log_in_ok( $superuser->email ); $mech->get_ok('/dashboard'); # Contains body name, in list of bodies $mech->content_contains('Some Other Council'); $mech->content_contains('Edinburgh Council'); $mech->content_lacks('Category:'); $mech->get_ok('/dashboard?body=' . $body->id); $mech->content_lacks('Some Other Council'); $mech->content_contains('Edinburgh Council'); $mech->content_contains('Trowbridge'); $mech->content_contains('Category:'); }; subtest 'council user, ward list' => sub { $mech->log_in_ok( $counciluser->email ); $mech->get_ok('/dashboard'); $mech->content_lacks('Some Other Council'); $mech->content_contains('Edinburgh Council'); $mech->content_contains('Trowbridge'); $mech->content_contains('Category:'); }; subtest 'area user can only see their area' => sub { $counciluser->update({area_id => $area_id}); $mech->get_ok("/dashboard"); $mech->content_contains('