diff options
Diffstat (limited to 't')
30 files changed, 2258 insertions, 1224 deletions
diff --git a/t/app/controller/about.t b/t/app/controller/about.t index ed28eb584..b3562ea04 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -11,10 +11,9 @@ $mech->get_ok('/about'); $mech->content_like(qr{About us ::\s+FixMyStreet}); $mech->content_contains('html class="no-js" lang="en-gb"'); -SKIP: { - skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 8 ) - unless FixMyStreet::Cobrand->exists('emptyhomes'); - +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'emptyhomes' ], +}, sub { # check that geting the page as EHA produces a different page ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes'; $mech->get_ok('/about'); @@ -26,6 +25,6 @@ SKIP: { $mech->get_ok('/about'); $mech->content_like(qr{Amdanom ni ::\s+Rhoi gwybod am eiddo gwag}); $mech->content_contains('html lang="cy"'); -} +}; done_testing(); diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 521497f3e..e369968b4 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -53,6 +53,7 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( used_map => 't', name => 'Test User', anonymous => 'f', + external_id => '13', state => 'confirmed', confirmed => $dt->ymd . ' ' . $dt->hms, lang => 'en-gb', @@ -93,7 +94,11 @@ subtest 'check summary counts' => sub { my $alerts = FixMyStreet::App->model('DB::Alert')->search( { confirmed => { '>' => 0 } } ); my $a_count = $alerts->count; - $mech->get_ok('/admin'); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + }, sub { + $mech->get_ok('/admin'); + }; $mech->title_like(qr/Summary/); @@ -105,10 +110,9 @@ subtest 'check summary counts' => sub { $mech->content_contains( "$q_count questionnaires sent" ); - SKIP: { - skip( "Need 'barnet' in ALLOWED_COBRANDS config", 7 ) - unless FixMyStreet::Cobrand->exists('barnet'); - + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'barnet' ], + }, sub { ok $mech->host('barnet.fixmystreet.com'); $mech->get_ok('/admin'); @@ -137,19 +141,23 @@ subtest 'check summary counts' => sub { $alert->cobrand(''); $alert->update; - } + }; FixMyStreet::App->model('DB::Problem')->search( { bodies_str => 1 } )->update( { bodies_str => 2489 } ); ok $mech->host('fixmystreet.com'); }; -my $host = FixMyStreet->config('BASE_URL'); - my $body = $mech->create_body_ok(2650, 'Aberdeen City Council'); -$mech->get_ok('/admin/body/2650'); +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + MAPIT_TYPES => [ 'UTA' ], + BASE_URL => 'http://www.example.org', +}, sub { + $mech->get_ok('/admin/body/2650'); +}; $mech->content_contains('Aberdeen City Council'); $mech->content_like(qr{AB\d\d}); -$mech->content_contains("$host/around"); +$mech->content_contains("http://www.example.org/around"); subtest 'check contact creation' => sub { my $contact = FixMyStreet::App->model('DB::Contact')->search( @@ -555,7 +563,7 @@ foreach my $test ( $report->discard_changes; if ( $report->state eq 'confirmed' ) { - $mech->content_contains( 'type="submit" name="resend"', 'no resend button' ); + $mech->content_contains( 'type="submit" name="resend"', 'resend button' ); } else { $mech->content_lacks( 'type="submit" name="resend"', 'no resend button' ); } @@ -1032,13 +1040,19 @@ subtest 'report search' => sub { $mech->content_contains( $report->title ); my $r_id = $report->id; - $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id">$r_id</a>} ); + $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id"[^>]*>$r_id</a>} ); + + $mech->get_ok('/admin/reports?search=' . $report->external_id); + $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id"[^>]*>$r_id</a>} ); + + $mech->get_ok('/admin/reports?search=ref:' . $report->external_id); + $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id"[^>]*>$r_id</a>} ); $mech->get_ok('/admin/reports?search=' . $report->user->email); my $u_id = $update->id; - $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id">$r_id</a>} ); - $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id#update_$u_id">$u_id</a>} ); + $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id"[^>]*>$r_id</a>} ); + $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id#update_$u_id"[^>]*>$u_id</a>} ); $update->state('hidden'); $update->update; @@ -1056,7 +1070,7 @@ subtest 'report search' => sub { $report->update; $mech->get_ok('/admin/reports?search=' . $report->user->email); - $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id">$r_id</a>} ); + $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id"[^>]*>$r_id</a>} ); }; subtest 'search abuse' => sub { @@ -1205,6 +1219,26 @@ for my $test ( }; } +subtest "Test setting a report from unconfirmed to something else doesn't cause a front end error" => sub { + $report->update( { confirmed => undef, state => 'unconfirmed', non_public => 0 } ); + $mech->get_ok("/admin/report_edit/$report_id"); + $mech->submit_form_ok( { with_fields => { state => 'investigating' } } ); + $report->discard_changes; + ok( $report->confirmed, 'report has a confirmed timestamp' ); + $mech->get_ok("/report/$report_id"); +}; + +subtest "Check admin_base_url" => sub { + my $rs = FixMyStreet::App->model('DB::Problem'); + my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($report->cobrand)->new(); + + is (FixMyStreet::App->model('DB::Problem')->get_admin_url( + $cobrand, + $report), + (sprintf 'https://secure.mysociety.org/admin/bci/report_edit/%d', $report_id), + 'get_admin_url OK'); +}; + $mech->delete_user( $user ); $mech->delete_user( $user2 ); $mech->delete_user( $user3 ); diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 847aa1a17..6fab4d3e3 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -12,56 +12,61 @@ $mech->content_contains('Local RSS feeds and email alerts'); $mech->content_contains('html class="no-js" lang="en-gb"'); # check that we can get list page -$mech->get_ok('/alert/list'); -$mech->title_like(qr/^Local RSS feeds and email alerts/); -$mech->content_contains('Local RSS feeds and email alerts'); -$mech->content_contains('html class="no-js" lang="en-gb"'); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $mech->get_ok('/alert/list'); + $mech->title_like(qr/^Local RSS feeds and email alerts/); + $mech->content_contains('Local RSS feeds and email alerts'); + $mech->content_contains('html class="no-js" lang="en-gb"'); -$mech->get_ok('/alert/list?pc=EH99 1SP'); -$mech->title_like(qr/^Local RSS feeds and email alerts/); -$mech->content_contains('Here are the types of local problem alerts for ‘EH99 1SP’'); -$mech->content_contains('html class="no-js" lang="en-gb"'); -$mech->content_contains('Problems within 8.5km'); -$mech->content_contains('rss/pc/EH991SP/2'); -$mech->content_contains('rss/pc/EH991SP/5'); -$mech->content_contains('rss/pc/EH991SP/10'); -$mech->content_contains('rss/pc/EH991SP/20'); -$mech->content_contains('Problems within City of Edinburgh'); -$mech->content_contains('Problems within City Centre ward'); -$mech->content_contains('/rss/reports/City+of+Edinburgh'); -$mech->content_contains('/rss/reports/City+of+Edinburgh/City+Centre'); -$mech->content_contains('council:2651:City_of_Edinburgh'); -$mech->content_contains('ward:2651:20728:City_of_Edinburgh:City_Centre'); + $mech->get_ok('/alert/list?pc=EH99 1SP'); + $mech->title_like(qr/^Local RSS feeds and email alerts/); + $mech->content_contains('Here are the types of local problem alerts for ‘EH99 1SP’'); + $mech->content_contains('html class="no-js" lang="en-gb"'); + $mech->content_contains('Problems within 8.5km'); + $mech->content_contains('rss/pc/EH991SP/2'); + $mech->content_contains('rss/pc/EH991SP/5'); + $mech->content_contains('rss/pc/EH991SP/10'); + $mech->content_contains('rss/pc/EH991SP/20'); + $mech->content_contains('Problems within City of Edinburgh'); + $mech->content_contains('Problems within City Centre ward'); + $mech->content_contains('/rss/reports/City+of+Edinburgh'); + $mech->content_contains('/rss/reports/City+of+Edinburgh/City+Centre'); + $mech->content_contains('council:2651:City_of_Edinburgh'); + $mech->content_contains('ward:2651:20728:City_of_Edinburgh:City_Centre'); -$mech->get_ok('/alert/list?pc=High Street'); -$mech->content_contains('We found more than one match for that location'); + $mech->get_ok('/alert/list?pc=High Street'); + $mech->content_contains('We found more than one match for that location'); -$mech->get_ok('/alert/list?pc='); -$mech->content_contains('To find out what local alerts we have for you'); + $mech->get_ok('/alert/list?pc='); + $mech->content_contains('To find out what local alerts we have for you'); -$mech->get_ok('/alert/list?pc=GL502PR'); -$mech->content_contains('Problems within the boundary of'); + $mech->get_ok('/alert/list?pc=GL502PR'); + $mech->content_contains('Problems within the boundary of'); -$mech->get_ok('/alert/subscribe?rss=1&type=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy=' ); -$mech->content_contains('Please select the feed you want'); + $mech->get_ok('/alert/subscribe?rss=1&type=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy=' ); + $mech->content_contains('Please select the feed you want'); -$mech->get_ok('/alert/subscribe?rss=1&feed=invalid:1000:A_Locationtype=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy='); -$mech->content_contains('Illegal feed selection'); + $mech->get_ok('/alert/subscribe?rss=1&feed=invalid:1000:A_Locationtype=local&pc=ky16+8yg&rss=Give+me+an+RSS+feed&rznvy='); + $mech->content_contains('Illegal feed selection'); -$mech->create_body_ok(2504, 'Birmingham City Council'); -$mech->create_body_ok(2226, 'Gloucestershire County Council'); -$mech->create_body_ok(2326, 'Cheltenham Borough Council'); + $mech->create_body_ok(2504, 'Birmingham City Council'); + $mech->create_body_ok(2226, 'Gloucestershire County Council'); + $mech->create_body_ok(2326, 'Cheltenham Borough Council'); -$mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:Birmingham'); -is $mech->uri->path, '/rss/reports/Birmingham'; + $mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:Birmingham'); + is $mech->uri->path, '/rss/reports/Birmingham'; -$mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:1001:Cheltenham:Lansdown'); -is $mech->uri->path, '/rss/area/Cheltenham/Lansdown'; + $mech->get_ok('/alert/subscribe?rss=1&feed=area:1000:1001:Cheltenham:Lansdown'); + is $mech->uri->path, '/rss/area/Cheltenham/Lansdown'; -$mech->get_ok('/alert/subscribe?rss=1&feed=council:1000:Gloucestershire'); -is $mech->uri->path, '/rss/reports/Gloucestershire'; + $mech->get_ok('/alert/subscribe?rss=1&feed=council:1000:Gloucestershire'); + is $mech->uri->path, '/rss/reports/Gloucestershire'; -$mech->get_ok('/alert/subscribe?rss=1&feed=ward:1000:1001:Cheltenham:Lansdown'); -is $mech->uri->path, '/rss/reports/Cheltenham/Lansdown'; + $mech->get_ok('/alert/subscribe?rss=1&feed=ward:1000:1001:Cheltenham:Lansdown'); + is $mech->uri->path, '/rss/reports/Cheltenham/Lansdown'; +}; done_testing(); diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index 23240c3b9..1804da32e 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -207,7 +207,12 @@ foreach my $test ( $mech->log_in_ok( $test->{email} ); $mech->clear_emails_ok; - $mech->get_ok('/alert/list?pc=EH991SP'); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok('/alert/list?pc=EH991SP'); + }; $mech->set_visible( [ radio => 'council:2651:City_of_Edinburgh' ] ); $mech->click('alert'); @@ -306,13 +311,18 @@ subtest "Test two-tier council alerts" => sub { result => '/rss/reports/Gloucestershire/Lansdown+and+Park' }, ) { - $mech->get_ok( '/alert/list?pc=GL502PR' ); - $mech->submit_form_ok( { - button => 'rss', - with_fields => { - feed => $alert->{feed}, - } - } ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok( '/alert/list?pc=GL502PR' ); + $mech->submit_form_ok( { + button => 'rss', + with_fields => { + feed => $alert->{feed}, + } + } ); + }; is $mech->uri->path, $alert->{result}, 'Redirected to right RSS feed'; } }; @@ -344,11 +354,16 @@ subtest "Test normal alert signups and that alerts are sent" => sub { }, ) { $mech->get_ok( '/alert' ); - $mech->submit_form_ok( { with_fields => { pc => 'EH11BB' } } ); - $mech->submit_form_ok( { - button => 'alert', - with_fields => $alert->{fields}, - } ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH11BB' } } ); + $mech->submit_form_ok( { + button => 'alert', + with_fields => $alert->{fields}, + } ); + }; if ( $alert->{email_confirm} ) { my $email = $mech->get_email; $mech->clear_emails_ok; @@ -425,7 +440,11 @@ subtest "Test normal alert signups and that alerts are sent" => sub { $update_id = $update->id; ok $update, "created test update - $update_id"; - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; # TODO Note the below will fail if the db has an existing alert that matches $mech->email_count_is(3); my @emails = $mech->get_email; @@ -545,11 +564,19 @@ for my $test ( } ); $mech->clear_emails_ok; - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; $mech->email_count_is(0); $report->update( { non_public => 0 } ); - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; $mech->email_count_is(1); my $email = $mech->get_email; like $email->body, qr/Alert\s+test\s+for\s+non\s+public\s+reports/, 'alert contains public report'; diff --git a/t/app/controller/around.t b/t/app/controller/around.t index fa2d94aed..cbb110a1a 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -14,7 +14,11 @@ subtest "check that if no query we get sent back to the homepage" => sub { # historic links subtest "redirect x,y requests to lat/lon (301 - permanent)" => sub { - $mech->get_ok('/around?x=3281&y=1113'); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok('/around?x=3281&y=1113'); + }; # did we redirect to lat,lon? is $mech->uri->path, '/around', "still on /around"; @@ -75,8 +79,13 @@ foreach my $test ( { subtest "check lat/lng for '$test->{pc}'" => sub { $mech->get_ok('/'); - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "good location" ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "good location" ); + }; is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; is_deeply $mech->extract_location, $test, "got expected location for pc '$test->{pc}'"; @@ -93,8 +102,13 @@ subtest 'check non public reports are not displayed on around page' => sub { $mech->create_problems_for_body( 5, 2651, 'Around page', $params ); $mech->get_ok('/'); - $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } }, - "good location" ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } }, + "good location" ); + }; $mech->content_contains( 'Around page Test 3 for 2651', 'problem to be marked non public visible' ); diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t index c1e9c3ace..5e4b4cbeb 100644 --- a/t/app/controller/dashboard.t +++ b/t/app/controller/dashboard.t @@ -2,10 +2,6 @@ use strict; use warnings; use Test::More; -# XXX -plan skip_all => 'Disabling failing dashboard tests until they can be looked at'; -exit; - use FixMyStreet::TestMech; use Web::Scraper; @@ -28,579 +24,592 @@ my $p_user = FixMyStreet::App->model('DB::User')->find_or_create( { email => 'p_user@example.com' } ); -$mech->not_logged_in_ok; -$mech->get_ok('/dashboard'); - -$mech->content_contains( 'sign in' ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { -$mech->submit_form( - with_fields => { email => $test_user, password_sign_in => $test_pass } -); + $mech->not_logged_in_ok; + $mech->get_ok('/dashboard'); -is $mech->status, '404', 'If not council user get 404'; + $mech->content_contains( 'sign in' ); -$user->from_body( $test_council ); -$user->update; - -$mech->log_out_ok; -$mech->get_ok('/dashboard'); -$mech->submit_form_ok( { - with_fields => { email => $test_user, password_sign_in => $test_pass } -} ); + $mech->submit_form( + with_fields => { email => $test_user, password_sign_in => $test_pass } + ); -$mech->content_contains( 'City of Edinburgh' ); + is $mech->status, '404', 'If not council user get 404'; -FixMyStreet::App->model('DB::Contact')->search( { body_id => $test_council } ) - ->delete; + $user->from_body( $test_council ); + $user->update; -delete_problems(); + $mech->log_out_ok; + $mech->get_ok('/dashboard'); + $mech->submit_form_ok( { + with_fields => { email => $test_user, password_sign_in => $test_pass } + } ); -my @cats = qw( Grafitti Litter Potholes Other ); -for my $contact ( @cats ) { - FixMyStreet::App->model('DB::Contact')->create( - { - body_id => $test_council, - category => $contact, - email => "$contact\@example.org", - confirmed => 1, - whenedited => DateTime->now, - deleted => 0, - editor => 'test', - note => 'test', - } - ); -} + $mech->content_contains( 'City of Edinburgh' ); -$mech->get_ok('/dashboard'); - -my $categories = scraper { - process "select[name=category] > option", 'cats[]' => 'TEXT', - process "select[name=ward] > option", 'wards[]' => 'TEXT', - process "table[id=overview] > tr", 'rows[]' => scraper { - process 'td', 'cols[]' => 'TEXT' - }, - process "tr[id=total] > td", 'totals[]' => 'TEXT', - process "tr[id=fixed_council] > td", 'council[]' => 'TEXT', - process "tr[id=fixed_user] > td", 'user[]' => 'TEXT', - process "tr[id=total_fixed] > td", 'total_fixed[]' => 'TEXT', - process "tr[id=in_progress] > td", 'in_progress[]' => 'TEXT', - process "tr[id=action_scheduled] > td", 'action_scheduled[]' => 'TEXT', - process "tr[id=investigating] > td", 'investigating[]' => 'TEXT', - process "tr[id=marked] > td", 'marked[]' => 'TEXT', - process "tr[id=avg_marked] > td", 'avg_marked[]' => 'TEXT', - process "tr[id=avg_fixed] > td", 'avg_fixed[]' => 'TEXT', - process "tr[id=not_marked] > td", 'not_marked[]' => 'TEXT', - process "tr[id=closed] > td", 'closed[]' => 'TEXT', - process "table[id=reports] > tr > td", 'report_lists[]' => scraper { - process 'ul > li', 'reports[]' => 'TEXT' - }, -}; + FixMyStreet::App->model('DB::Contact')->search( { body_id => $test_council } ) + ->delete; -my $expected_cats = [ 'All', '-- Pick a category --', @cats ]; -my $res = $categories->scrape( $mech->content ); -is_deeply( $res->{cats}, $expected_cats, 'correct list of categories' ); + delete_problems(); -foreach my $row ( @{ $res->{rows} }[1 .. 11] ) { - foreach my $col ( @{ $row->{cols} } ) { - is $col, 0; + my @cats = qw( Grafitti Litter Potholes Other ); + for my $contact ( @cats ) { + FixMyStreet::App->model('DB::Contact')->create( + { + body_id => $test_council, + category => $contact, + email => "$contact\@example.org", + confirmed => 1, + whenedited => DateTime->now, + deleted => 0, + editor => 'test', + note => 'test', + } + ); } -} -for my $reports ( @{ $res->{report_lists} } ) { - is_deeply $reports, {}, 'No reports'; -} + $mech->get_ok('/dashboard'); -foreach my $test ( - { - desc => 'confirmed today with no state', - dt => DateTime->now, - counts => [1,1,1,1], - report_counts => [1, 0, 0], - }, - { - desc => 'confirmed last 7 days with no state', - dt => DateTime->now->subtract( days => 6, hours => 23 ), - counts => [1,2,2,2], - report_counts => [2, 0, 0], - }, - { - desc => 'confirmed last 8 days with no state', - dt => DateTime->now->subtract( days => 8 ), - counts => [1,2,3,3], - report_counts => [2, 1, 0], - }, - { - desc => 'confirmed last 4 weeks with no state', - dt => DateTime->now->subtract( weeks => 2 ), - counts => [1,2,4,4], - report_counts => [2, 1, 1], - }, - { - desc => 'confirmed this year with no state', - dt => DateTime->now->subtract( weeks => 7 ), - counts => [1,2,4,5], - report_counts => [2, 1, 1], - }, -) { - subtest $test->{desc} => sub { - make_problem( { state => 'confirmed', conf_dt => $test->{dt} } ); - - $mech->get_ok('/dashboard'); - $res = $categories->scrape( $mech->content ); - - check_row( $res, 'totals', $test->{counts} ); - check_row( $res, 'not_marked', $test->{counts} ); - - check_report_counts( $res, $test->{report_counts} ); + my $categories = scraper { + process "select[name=category] > option", 'cats[]' => 'TEXT', + process "select[name=ward] > option", 'wards[]' => 'TEXT', + process "table[id=overview] > tr", 'rows[]' => scraper { + process 'td', 'cols[]' => 'TEXT' + }, + process "tr[id=total] > td", 'totals[]' => 'TEXT', + process "tr[id=fixed_council] > td", 'council[]' => 'TEXT', + process "tr[id=fixed_user] > td", 'user[]' => 'TEXT', + process "tr[id=total_fixed] > td", 'total_fixed[]' => 'TEXT', + process "tr[id=in_progress] > td", 'in_progress[]' => 'TEXT', + process "tr[id=action_scheduled] > td", 'action_scheduled[]' => 'TEXT', + process "tr[id=investigating] > td", 'investigating[]' => 'TEXT', + process "tr[id=marked] > td", 'marked[]' => 'TEXT', + process "tr[id=avg_marked] > td", 'avg_marked[]' => 'TEXT', + process "tr[id=avg_fixed] > td", 'avg_fixed[]' => 'TEXT', + process "tr[id=not_marked] > td", 'not_marked[]' => 'TEXT', + process "tr[id=closed] > td", 'closed[]' => 'TEXT', + process "table[id=reports] > tr > td", 'report_lists[]' => scraper { + process 'ul > li', 'reports[]' => 'TEXT' + }, }; -} -delete_problems(); - -my $is_monday = DateTime->now->day_of_week == 1 ? 1 : 0; - -foreach my $test ( - { - desc => 'user fixed today', - confirm_dt => DateTime->now->subtract( days => 1 ), - mark_dt => DateTime->now, - state => 'fixed - user', - counts => { - totals => $is_monday ? [0,1,1,1] : [1,1,1,1], - user => [1,1,1,1], - council => [0,0,0,0], - avg_fixed => [0,0,0,0], - total_fixed => [1,1,1,1], - } - }, - { - desc => 'council fixed today', - confirm_dt => DateTime->now->subtract( days => 1 ), - mark_dt => DateTime->now, - state => 'fixed - council', - counts => { - totals => $is_monday ? [0,2,2,2] : [2,2,2,2], - user => [1,1,1,1], - council => [1,1,1,1], - avg_fixed => [1,1,1,1], - total_fixed => [2,2,2,2], - } - }, - { - desc => 'marked investigating today', - confirm_dt => DateTime->now->subtract( days => 1 ), - mark_dt => DateTime->now, - state => 'investigating', - counts => { - totals => $is_monday ? [0,3,3,3] : [3,3,3,3], - user => [1,1,1,1], - council => [1,1,1,1], - total_fixed => [2,2,2,2], - avg_marked => [1,1,1,1], - investigating => [1,1,1,1], - marked => [1,1,1,1] - } - }, - { - desc => 'marked in progress today', - confirm_dt => DateTime->now->subtract( days => 1 ), - mark_dt => DateTime->now, - state => 'in progress', - counts => { - totals => $is_monday ? [0,4,4,4] : [4,4,4,4], - user => [1,1,1,1], - council => [1,1,1,1], - total_fixed => [2,2,2,2], - avg_marked => [1,1,1,1], - investigating => [1,1,1,1], - in_progress => [1,1,1,1], - marked => [2,2,2,2] - } - }, - { - desc => 'marked as action scheduled today', - confirm_dt => DateTime->now->subtract( days => 1 ), - mark_dt => DateTime->now, - state => 'action scheduled', - counts => { - totals => $is_monday ? [ 0,5,5,5] : [5,5,5,5], - user => [1,1,1,1], - council => [1,1,1,1], - total_fixed => [2,2,2,2], - avg_marked => [1,1,1,1], - investigating => [1,1,1,1], - in_progress => [1,1,1,1], - action_scheduled => [1,1,1,1], - marked => [3,3,3,3] - } - }, - { - desc => 'marked as action scheduled today, confirmed a week ago', - confirm_dt => DateTime->now->subtract( days => 8 ), - mark_dt => DateTime->now, - state => 'action scheduled', - counts => { - totals => $is_monday ? [0,5,6,6] : [5,5,6,6], - user => [1,1,1,1], - council => [1,1,1,1], - total_fixed => [2,2,2,2], - avg_marked => [3,3,3,3], - investigating => [1,1,1,1], - in_progress => [1,1,1,1], - action_scheduled => [2,2,2,2], - marked => [4,4,4,4] - } - }, - { - desc => 'marked as council fixed today, confirmed a week ago', - confirm_dt => DateTime->now->subtract( days => 8 ), - mark_dt => DateTime->now, - state => 'fixed - council', - counts => { - totals => $is_monday ? [0,5,7,7] : [5,5,7,7], - user => [1,1,1,1], - council => [2,2,2,2], - total_fixed => [3,3,3,3], - avg_fixed => [5,5,5,5], - avg_marked => [3,3,3,3], - investigating => [1,1,1,1], - in_progress => [1,1,1,1], - action_scheduled => [2,2,2,2], - marked => [4,4,4,4] - } - }, - { - desc => 'marked as council fixed a week ago, confirmed 3 weeks ago', - confirm_dt => DateTime->now->subtract( days => 21), - mark_dt => DateTime->now->subtract( days => 8 ), - state => 'fixed - council', - counts => { - totals => $is_monday ? [0,5,8,8] : [5,5,8,8], - user => [1,1,1,1], - council => [2,2,3,3], - total_fixed => [3,3,4,4], - avg_fixed => [5,5,7,7], - avg_marked => [3,3,3,3], - investigating => [1,1,1,1], - in_progress => [1,1,1,1], - action_scheduled => [2,2,2,2], - marked => [4,4,4,4] - } - }, - { - desc => 'marked as user fixed 6 weeks ago, confirmed 7 weeks ago', - confirm_dt => DateTime->now->subtract( weeks => 6 ), - mark_dt => DateTime->now->subtract( weeks => 7 ), - state => 'fixed - user', - counts => { - totals => $is_monday ? [0,5,8,9] : [5,5,8,9], - user => [1,1,1,2], - council => [2,2,3,3], - total_fixed => [3,3,4,5], - avg_fixed => [5,5,7,7], - avg_marked => [3,3,3,3], - investigating => [1,1,1,1], - in_progress => [1,1,1,1], - action_scheduled => [2,2,2,2], - marked => [4,4,4,4] - } - }, - { - desc => 'marked as closed', - confirm_dt => DateTime->now->subtract( days => 1 ), - mark_dt => DateTime->now, - state => 'closed', - counts => { - totals => $is_monday ? [0,6,9,10] : [6,6,9,10], - user => [1,1,1,2], - council => [2,2,3,3], - total_fixed => [3,3,4,5], - avg_fixed => [5,5,7,7], - avg_marked => [2,2,2,2], - investigating => [1,1,1,1], - in_progress => [1,1,1,1], - action_scheduled => [2,2,2,2], - closed => [1,1,1,1], - marked => [5,5,5,5] - } - }, - { - desc => 'marked as planned', - confirm_dt => DateTime->now->subtract( days => 1 ), - mark_dt => DateTime->now, - state => 'planned', - counts => { - totals => $is_monday ? [0,7,10,11] : [7,7,10,11], - user => [1,1,1,2], - council => [2,2,3,3], - total_fixed => [3,3,4,5], - avg_fixed => [5,5,7,7], - avg_marked => [2,2,2,2], - investigating => [1,1,1,1], - in_progress => [1,1,1,1], - action_scheduled => [3,3,3,3], - closed => [1,1,1,1], - marked => [6,6,6,6] - } - }, -) { - subtest $test->{desc} => sub { - make_problem( - { - state => $test->{state}, - conf_dt => $test->{confirm_dt}, - mark_dt => $test->{mark_dt}, - } - ); + my $expected_cats = [ 'All', '-- Pick a category --', @cats ]; + my $res = $categories->scrape( $mech->content ); + is_deeply( $res->{cats}, $expected_cats, 'correct list of categories' ); - $mech->get_ok('/dashboard'); - $res = $categories->scrape( $mech->content ); - - foreach my $row ( keys %{ $test->{counts} } ) { - check_row( $res, $row, $test->{counts}->{$row} ); + foreach my $row ( @{ $res->{rows} }[1 .. 11] ) { + foreach my $col ( @{ $row->{cols} } ) { + is $col, 0; } - }; -} + } -delete_problems(); + for my $reports ( @{ $res->{report_lists} } ) { + is_deeply $reports, {}, 'No reports'; + } -for my $test ( - { - desc => 'Selecting no category does nothing', - p1 => { - state => 'confirmed', - conf_dt => DateTime->now(), - category => 'Potholes', + foreach my $test ( + { + desc => 'confirmed today with no state', + dt => DateTime->now, + counts => [1,1,1,1], + report_counts => [1, 0, 0], }, - p2 => { - state => 'confirmed', - conf_dt => DateTime->now(), - category => 'Litter', + { + desc => 'confirmed last 7 days with no state', + dt => DateTime->now->subtract( days => 6, hours => 23 ), + counts => [1,2,2,2], + report_counts => [2, 0, 0], + }, + { + desc => 'confirmed last 8 days with no state', + dt => DateTime->now->subtract( days => 8 ), + counts => [1,2,3,3], + report_counts => [2, 1, 0], }, - category => '', - counts => { - totals => [2,2,2,2], + { + desc => 'confirmed last 4 weeks with no state', + dt => DateTime->now->subtract( weeks => 2 ), + counts => [1,2,4,4], + report_counts => [2, 1, 1], }, - counts_after => { - totals => [2,2,2,2], + { + desc => 'confirmed this year with no state', + dt => DateTime->now->subtract( weeks => 7 ), + counts => [1,2,4,5], + report_counts => [2, 1, 1], + }, + ) { + subtest $test->{desc} => sub { + make_problem( { state => 'confirmed', conf_dt => $test->{dt} } ); + + $mech->get_ok('/dashboard'); + $res = $categories->scrape( $mech->content ); + + check_row( $res, 'totals', $test->{counts} ); + check_row( $res, 'not_marked', $test->{counts} ); + + check_report_counts( $res, $test->{report_counts} ); + }; + } + + delete_problems(); + + my $is_monday = DateTime->now->day_of_week == 1 ? 1 : 0; + + foreach my $test ( + { + desc => 'user fixed today', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'fixed - user', + counts => { + totals => $is_monday ? [0,1,1,1] : [1,1,1,1], + user => [1,1,1,1], + council => [0,0,0,0], + avg_fixed => [0,0,0,0], + total_fixed => [1,1,1,1], + } }, - report_counts => [2,0,0], - report_counts_after => [2,0,0], - }, - { - desc => 'Limit display by category', - category => 'Potholes', - counts => { - totals => [2,2,2,2], + { + desc => 'council fixed today', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'fixed - council', + counts => { + totals => $is_monday ? [0,2,2,2] : [2,2,2,2], + user => [1,1,1,1], + council => [1,1,1,1], + avg_fixed => [1,1,1,1], + total_fixed => [2,2,2,2], + } }, - counts_after => { - totals => [1,1,1,1], + { + desc => 'marked investigating today', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'investigating', + counts => { + totals => $is_monday ? [0,3,3,3] : [3,3,3,3], + user => [1,1,1,1], + council => [1,1,1,1], + total_fixed => [2,2,2,2], + avg_marked => [1,1,1,1], + investigating => [1,1,1,1], + marked => [1,1,1,1] + } }, - report_counts => [2,0,0], - report_counts_after => [1,0,0], - }, - { - desc => 'Limit display for category with no entries', - category => 'Grafitti', - counts => { - totals => [2,2,2,2], + { + desc => 'marked in progress today', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'in progress', + counts => { + totals => $is_monday ? [0,4,4,4] : [4,4,4,4], + user => [1,1,1,1], + council => [1,1,1,1], + total_fixed => [2,2,2,2], + avg_marked => [1,1,1,1], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + marked => [2,2,2,2] + } }, - counts_after => { - totals => [0,0,0,0], + { + desc => 'marked as action scheduled today', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'action scheduled', + counts => { + totals => $is_monday ? [ 0,5,5,5] : [5,5,5,5], + user => [1,1,1,1], + council => [1,1,1,1], + total_fixed => [2,2,2,2], + avg_marked => [1,1,1,1], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + action_scheduled => [1,1,1,1], + marked => [3,3,3,3] + } }, - report_counts => [2,0,0], - report_counts_after => [0,0,0], - }, - { - desc => 'Limit display by category for council fixed', - p1 => { - state => 'fixed - council', - conf_dt => DateTime->now()->subtract( weeks => 1 ), - mark_dt => DateTime->now()->subtract( weeks => 1 ), - category => 'Potholes', + { + desc => 'marked as action scheduled today, confirmed a week ago', + confirm_dt => DateTime->now->subtract( days => 8 ), + mark_dt => DateTime->now, + state => 'action scheduled', + counts => { + totals => $is_monday ? [0,5,6,6] : [5,5,6,6], + user => [1,1,1,1], + council => [1,1,1,1], + total_fixed => [2,2,2,2], + avg_marked => [3,3,3,3], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + action_scheduled => [2,2,2,2], + marked => [4,4,4,4] + } }, - p2 => { - state => 'fixed - council', - conf_dt => DateTime->now()->subtract( weeks => 1 ), - mark_dt => DateTime->now()->subtract( weeks => 1 ), - category => 'Litter', + { + desc => 'marked as council fixed today, confirmed a week ago', + confirm_dt => DateTime->now->subtract( days => 8 ), + mark_dt => DateTime->now, + state => 'fixed - council', + counts => { + totals => $is_monday ? [0,5,7,7] : [5,5,7,7], + user => [1,1,1,1], + council => [2,2,2,2], + total_fixed => [3,3,3,3], + avg_fixed => [5,5,5,5], + avg_marked => [3,3,3,3], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + action_scheduled => [2,2,2,2], + marked => [4,4,4,4] + } }, - category => 'Potholes', - counts => { - council => [0,0,2,2], - totals => [2,2,4,4], + { + desc => 'marked as council fixed a week ago, confirmed 3 weeks ago', + confirm_dt => DateTime->now->subtract( days => 21), + mark_dt => DateTime->now->subtract( days => 8 ), + state => 'fixed - council', + counts => { + totals => $is_monday ? [0,5,8,8] : [5,5,8,8], + user => [1,1,1,1], + council => [2,2,3,3], + total_fixed => [3,3,4,4], + avg_fixed => [5,5,7,7], + avg_marked => [3,3,3,3], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + action_scheduled => [2,2,2,2], + marked => [4,4,4,4] + } }, - counts_after => { - council => [0,0,1,1], - totals => [1,1,2,2], + { + desc => 'marked as user fixed 6 weeks ago, confirmed 7 weeks ago', + confirm_dt => DateTime->now->subtract( weeks => 6 ), + mark_dt => DateTime->now->subtract( weeks => 7 ), + state => 'fixed - user', + counts => { + totals => $is_monday ? [0,5,8,9] : [5,5,8,9], + user => [1,1,1,2], + council => [2,2,3,3], + total_fixed => [3,3,4,5], + avg_fixed => [5,5,7,7], + avg_marked => [3,3,3,3], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + action_scheduled => [2,2,2,2], + marked => [4,4,4,4] + } }, - report_counts => [2,2,0], - report_counts_after => [1,1,0], - }, - { - desc => 'Limit display by category for user fixed', - p1 => { - state => 'fixed - user', - conf_dt => DateTime->now()->subtract( weeks => 1 ), - mark_dt => DateTime->now()->subtract( weeks => 1 ), - category => 'Potholes', + { + desc => 'marked as closed', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'closed', + counts => { + totals => $is_monday ? [0,6,9,10] : [6,6,9,10], + user => [1,1,1,2], + council => [2,2,3,3], + total_fixed => [3,3,4,5], + avg_fixed => [5,5,7,7], + avg_marked => [2,2,2,2], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + action_scheduled => [2,2,2,2], + closed => [1,1,1,1], + marked => [5,5,5,5] + } }, - p2 => { - state => 'fixed - user', - conf_dt => DateTime->now()->subtract( weeks => 1 ), - mark_dt => DateTime->now()->subtract( weeks => 1 ), - category => 'Litter', + { + desc => 'marked as planned', + confirm_dt => DateTime->now->subtract( days => 1 ), + mark_dt => DateTime->now, + state => 'planned', + counts => { + totals => $is_monday ? [0,7,10,11] : [7,7,10,11], + user => [1,1,1,2], + council => [2,2,3,3], + total_fixed => [3,3,4,5], + avg_fixed => [5,5,7,7], + avg_marked => [2,2,2,2], + investigating => [1,1,1,1], + in_progress => [1,1,1,1], + action_scheduled => [3,3,3,3], + closed => [1,1,1,1], + marked => [6,6,6,6] + } }, - category => 'Potholes', - counts => { - user => [0,0,2,2], - council => [0,0,2,2], - totals => [2,2,6,6], + ) { + subtest $test->{desc} => sub { + make_problem( + { + state => $test->{state}, + conf_dt => $test->{confirm_dt}, + mark_dt => $test->{mark_dt}, + } + ); + + $mech->get_ok('/dashboard'); + $res = $categories->scrape( $mech->content ); + + foreach my $row ( keys %{ $test->{counts} } ) { + check_row( $res, $row, $test->{counts}->{$row} ); + } + }; + } + + delete_problems(); + + for my $test ( + { + desc => 'Selecting no category does nothing', + p1 => { + state => 'confirmed', + conf_dt => DateTime->now(), + category => 'Potholes', + }, + p2 => { + state => 'confirmed', + conf_dt => DateTime->now(), + category => 'Litter', + }, + category => '', + counts => { + totals => [2,2,2,2], + }, + counts_after => { + totals => [2,2,2,2], + }, + report_counts => [2,0,0], + report_counts_after => [2,0,0], }, - counts_after => { - user => [0,0,1,1], - council => [0,0,1,1], - totals => [1,1,3,3], + { + desc => 'Limit display by category', + category => 'Potholes', + counts => { + totals => [2,2,2,2], + }, + counts_after => { + totals => [1,1,1,1], + }, + report_counts => [2,0,0], + report_counts_after => [1,0,0], }, - report_counts => [2,4,0], - report_counts_after => [1,2,0], - }, - { - desc => 'Limit display by ward', - p1 => { - state => 'confirmed', - conf_dt => DateTime->now()->subtract( weeks => 1 ), - category => 'Potholes', - # in real life it has commas around it and the search - # uses them - areas => ',20720,', + { + desc => 'Limit display for category with no entries', + category => 'Grafitti', + counts => { + totals => [2,2,2,2], + }, + counts_after => { + totals => [0,0,0,0], + }, + report_counts => [2,0,0], + report_counts_after => [0,0,0], }, - p2 => { - state => 'fixed - council', - conf_dt => DateTime->now()->subtract( weeks => 1 ), - mark_dt => DateTime->now()->subtract( weeks => 1 ), - category => 'Litter', - areas => ',20720,', + { + desc => 'Limit display by category for council fixed', + p1 => { + state => 'fixed - council', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + mark_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Potholes', + }, + p2 => { + state => 'fixed - council', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + mark_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Litter', + }, + category => 'Potholes', + counts => { + council => [0,0,2,2], + totals => [2,2,4,4], + }, + counts_after => { + council => [0,0,1,1], + totals => [1,1,2,2], + }, + report_counts => [2,2,0], + report_counts_after => [1,1,0], }, - ward => 20720, - counts => { - user => [0,0,2,2], - council => [0,0,3,3], - totals => [2,2,8,8], + { + desc => 'Limit display by category for user fixed', + p1 => { + state => 'fixed - user', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + mark_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Potholes', + }, + p2 => { + state => 'fixed - user', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + mark_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Litter', + }, + category => 'Potholes', + counts => { + user => [0,0,2,2], + council => [0,0,2,2], + totals => [2,2,6,6], + }, + counts_after => { + user => [0,0,1,1], + council => [0,0,1,1], + totals => [1,1,3,3], + }, + report_counts => [2,4,0], + report_counts_after => [1,2,0], }, - counts_after => { - user => [0,0,0,0], - council => [0,0,1,1], - totals => [0,0,2,2], + { + desc => 'Limit display by ward', + p1 => { + state => 'confirmed', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Potholes', + # in real life it has commas around it and the search + # uses them + areas => ',20720,', + }, + p2 => { + state => 'fixed - council', + conf_dt => DateTime->now()->subtract( weeks => 1 ), + mark_dt => DateTime->now()->subtract( weeks => 1 ), + category => 'Litter', + areas => ',20720,', + }, + ward => 20720, + counts => { + user => [0,0,2,2], + council => [0,0,3,3], + totals => [2,2,8,8], + }, + counts_after => { + user => [0,0,0,0], + council => [0,0,1,1], + totals => [0,0,2,2], + }, + report_counts => [2,6,0], + report_counts_after => [0,2,0], }, - report_counts => [2,6,0], - report_counts_after => [0,2,0], - }, -) { - subtest $test->{desc} => sub { - make_problem( $test->{p1} ) if $test->{p1}; - make_problem( $test->{p2} ) if $test->{p2}; + ) { + subtest $test->{desc} => sub { + make_problem( $test->{p1} ) if $test->{p1}; + make_problem( $test->{p2} ) if $test->{p2}; - $mech->get_ok('/dashboard'); + $mech->get_ok('/dashboard'); - $res = $categories->scrape( $mech->content ); + $res = $categories->scrape( $mech->content ); - foreach my $row ( keys %{ $test->{counts} } ) { - check_row( $res, $row, $test->{counts}->{$row} ); - } + foreach my $row ( keys %{ $test->{counts} } ) { + check_row( $res, $row, $test->{counts}->{$row} ); + } - check_report_counts( $res, $test->{report_counts} ); + check_report_counts( $res, $test->{report_counts} ); - $mech->submit_form_ok( { - with_fields => { - category => $test->{category}, - ward => $test->{ward}, - } - } ); + $mech->submit_form_ok( { + with_fields => { + category => $test->{category}, + ward => $test->{ward}, + } + } ); - $res = $categories->scrape( $mech->content ); + $res = $categories->scrape( $mech->content ); - foreach my $row ( keys %{ $test->{counts_after} } ) { - check_row( $res, $row, $test->{counts_after}->{$row} ); - } - check_report_counts( $res, $test->{report_counts_after} ); - }; -} + foreach my $row ( keys %{ $test->{counts_after} } ) { + check_row( $res, $row, $test->{counts_after}->{$row} ); + } + check_report_counts( $res, $test->{report_counts_after} ); + }; + } -delete_problems(); + delete_problems(); -for my $test ( - { - desc => 'Selecting no state does nothing', - p1 => { - state => 'fixed - user', - conf_dt => DateTime->now(), - category => 'Potholes', - }, - p2 => { - state => 'confirmed', - conf_dt => DateTime->now(), - category => 'Litter', + for my $test ( + { + desc => 'Selecting no state does nothing', + p1 => { + state => 'fixed - user', + conf_dt => DateTime->now(), + category => 'Potholes', + }, + p2 => { + state => 'confirmed', + conf_dt => DateTime->now(), + category => 'Litter', + }, + state => '', + report_counts => [2,0,0], + report_counts_after => [2,0,0], }, - state => '', - report_counts => [2,0,0], - report_counts_after => [2,0,0], - }, - { - desc => 'limit by state works', - state => 'fixed', - report_counts => [2,0,0], - report_counts_after => [1,0,0], - }, - { - desc => 'planned counted as action scheduled', - p1 => { - state => 'planned', - conf_dt => DateTime->now(), - category => 'Potholes', + { + desc => 'limit by state works', + state => 'fixed', + report_counts => [2,0,0], + report_counts_after => [1,0,0], }, - state => 'action scheduled', - report_counts => [3,0,0], - report_counts_after => [1,0,0], - }, - { - desc => 'All fixed states count as fixed', - p1 => { - state => 'fixed - council', - conf_dt => DateTime->now(), - category => 'Potholes', + { + desc => 'planned counted as action scheduled', + p1 => { + state => 'planned', + conf_dt => DateTime->now(), + category => 'Potholes', + }, + state => 'action scheduled', + report_counts => [3,0,0], + report_counts_after => [1,0,0], }, - p2 => { - state => 'fixed', - conf_dt => DateTime->now(), - category => 'Potholes', + { + desc => 'All fixed states count as fixed', + p1 => { + state => 'fixed - council', + conf_dt => DateTime->now(), + category => 'Potholes', + }, + p2 => { + state => 'fixed', + conf_dt => DateTime->now(), + category => 'Potholes', + }, + state => 'fixed', + report_counts => [5,0,0], + report_counts_after => [3,0,0], }, - state => 'fixed', - report_counts => [5,0,0], - report_counts_after => [3,0,0], - }, -) { - subtest $test->{desc} => sub { - make_problem( $test->{p1} ) if $test->{p1}; - make_problem( $test->{p2} ) if $test->{p2}; + ) { + subtest $test->{desc} => sub { + make_problem( $test->{p1} ) if $test->{p1}; + make_problem( $test->{p2} ) if $test->{p2}; - $mech->get_ok('/dashboard'); + $mech->get_ok('/dashboard'); - $res = $categories->scrape( $mech->content ); + $res = $categories->scrape( $mech->content ); - check_report_counts( $res, $test->{report_counts} ); + check_report_counts( $res, $test->{report_counts} ); - $mech->submit_form_ok( { - with_fields => { - state => $test->{state}, - } - } ); + $mech->submit_form_ok( { + with_fields => { + state => $test->{state}, + } + } ); + + $res = $categories->scrape( $mech->content ); - $res = $categories->scrape( $mech->content ); + check_report_counts( $res, $test->{report_counts_after} ); + }; + } - check_report_counts( $res, $test->{report_counts_after} ); + subtest 'export as csv' => sub { + $mech->get_ok('/dashboard?export=1'); + my @lines = split /\n/, $mech->content; + is scalar @lines, 6, '1 (header) + 5 (reports) = 6 lines'; }; -} +}; + sub make_problem { my $args = shift; diff --git a/t/app/controller/index.t b/t/app/controller/index.t index 47c08291f..7fc15ab4b 100644 --- a/t/app/controller/index.t +++ b/t/app/controller/index.t @@ -47,7 +47,11 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub { $uri->query_form( $test->{in} ); # get the uri and check for 302 - $mech->get_ok($uri); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok($uri); + }; # check that we are at /around is $mech->uri->path, '/around', "Got to /around"; diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index 5c81a43d1..3468909b9 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -383,10 +383,9 @@ for my $test ( }; } -SKIP: { - skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 18 ) - unless FixMyStreet::Cobrand->exists('emptyhomes'); - +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'emptyhomes', 'fixmystreet' ], +}, sub { # EHA extra checking ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; @@ -436,12 +435,11 @@ SKIP: { ok $questionnaire, 'found questionnaire'; $questionnaire2->delete; -} - -SKIP: { - skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 5 ) - unless FixMyStreet::Cobrand->exists('fiksgatami'); +}; +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fiksgatami' ], +}, sub { # I18N Unicode extra testing using FiksGataMi $report->send_questionnaire( 1 ); $report->cobrand( 'fiksgatami' ); @@ -455,7 +453,7 @@ SKIP: { like $email->body, qr/Testing =96 Detail/, 'email contains encoded character from user'; like $email->body, qr/sak p=E5 FiksGataMi/, 'email contains encoded character from template'; is $email->header('Content-Type'), 'text/plain; charset="windows-1252"', 'email is in right encoding'; -} +}; $mech->delete_user('test@example.com'); done_testing(); diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 7904b6736..07e8caa9b 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -97,15 +97,16 @@ subtest "change report to unconfirmed and check for 404 status" => sub { subtest "Zurich unconfirmeds are 200" => sub { - if ( !FixMyStreet::Cobrand->exists('zurich') ) { - plan skip_all => 'Skipping Zurich test without Zurich cobrand'; - } - $mech->host( 'zurich.fixmystreet.com' ); - ok $report->update( { state => 'unconfirmed' } ), 'unconfirm report'; - $mech->get_ok("/report/$report_id"); - $mech->content_contains( 'Überprüfung ausstehend' ); - ok $report->update( { state => 'confirmed' } ), 'confirm report again'; - $mech->host( 'www.fixmystreet.com' ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->host( 'zurich.example.com' ); + ok $report->update( { state => 'unconfirmed' } ), 'unconfirm report'; + $mech->get_ok("/report/$report_id"); + $mech->content_contains( 'Überprüfung ausstehend' ); + ok $report->update( { state => 'confirmed' } ), 'confirm report again'; + $mech->host( 'www.fixmystreet.com' ); + }; }; subtest "change report to hidden and check for 410 status" => sub { @@ -183,14 +184,14 @@ foreach my $meta ( category => '', service => 'Transport service', meta => -'Reported by Transport service by Test User at 15:47, Sat 16 April 2011' +'Reported via Transport service by Test User at 15:47, Sat 16 April 2011' }, { anonymous => 'f', category => 'Roads', service => 'Transport service', meta => -'Reported by Transport service in the Roads category by Test User at 15:47, Sat 16 April 2011' +'Reported via Transport service in the Roads category by Test User at 15:47, Sat 16 April 2011' }, { anonymous => 't', @@ -210,14 +211,14 @@ foreach my $meta ( category => '', service => 'Transport service', meta => -'Reported by Transport service anonymously at 15:47, Sat 16 April 2011' +'Reported via Transport service anonymously at 15:47, Sat 16 April 2011' }, { anonymous => 't', category => 'Roads', service => 'Transport service', meta => -'Reported by Transport service in the Roads category anonymously at 15:47, Sat 16 April 2011' +'Reported via Transport service in the Roads category anonymously at 15:47, Sat 16 April 2011' }, ) { @@ -400,10 +401,10 @@ for my $test ( } subtest "Zurich banners are displayed correctly" => sub { - if ( !FixMyStreet::Cobrand->exists('zurich') ) { - plan skip_all => 'Skipping Zurich test without Zurich cobrand'; - } - $mech->host( 'zurich.fixmystreet.com' ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->host( 'zurich.example.com' ); for my $test ( { @@ -466,6 +467,7 @@ subtest "Zurich banners are displayed correctly" => sub { } $mech->host( 'www.fixmystreet.com' ); + }; }; $mech->create_body_ok(2504, 'Westminster City Council'); diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index e25764c4b..a6ccc9604 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -63,10 +63,14 @@ subtest "Test creating bad partial entries" => sub { { $mech->get_ok('/import'); - $mech->submit_form_ok( # - { with_fields => $test->{fields} }, - "fill in form" - ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + }, sub { + $mech->submit_form_ok( # + { with_fields => $test->{fields} }, + "fill in form" + ); + }; is_deeply( $mech->import_errors, $test->{errors}, "expected errors" ); } @@ -103,7 +107,11 @@ subtest "Submit a correct entry" => sub { ok $token_url, "Found a token url $token_url"; # go to the token url - $mech->get_ok($token_url); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok($token_url); + }; # check that we are on '/around' is $mech->uri->path, '/around', "sent to /around"; @@ -112,10 +120,15 @@ subtest "Submit a correct entry" => sub { is_deeply $mech->visible_form_values, { pc => '' }, "check only pc field is shown"; - $mech->submit_form_ok( # - { with_fields => { pc => 'SW1A 1AA' } }, - "fill in postcode" - ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( + { with_fields => { pc => 'SW1A 1AA' } }, + "fill in postcode" + ); + }; is $mech->uri->path, '/report/new', "sent to report page"; @@ -136,14 +149,19 @@ subtest "Submit a correct entry" => sub { $mech->content_contains( '<img align="right" src="/photo/' ); $mech->content_contains('latitude" value="51.50101"', 'Check latitude'); $mech->content_contains('longitude" value="-0.141587"', 'Check longitude'); - $mech->submit_form_ok( - { - button => 'tile_32742.21793', - x => 10, - y => 10, - }, - "New map location" - ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( + { + button => 'tile_32742.21793', + x => 10, + y => 10, + }, + "New map location" + ); + }; $mech->content_contains( '<img align="right" src="/photo/' ); $mech->content_contains('latitude" value="51.50519"', 'Check latitude'); $mech->content_contains('longitude" value="-0.142608"', 'Check longitude'); @@ -162,19 +180,24 @@ subtest "Submit a correct entry" => sub { "check imported fields are shown"; # change the details - $mech->submit_form_ok( # - { - with_fields => { - name => 'New Test User', - title => 'New Test report', - detail => 'This is a test report', - phone => '01234 567 890', - may_show_name => '1', - category => 'Street lighting', - } - }, - "Update details and save" - ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( + { + with_fields => { + name => 'New Test User', + title => 'New Test report', + detail => 'This is a test report', + phone => '01234 567 890', + may_show_name => '1', + category => 'Street lighting', + } + }, + "Update details and save" + ); + }; # check that report has been created my $user = @@ -221,7 +244,12 @@ subtest "Submit a correct entry (with location)" => sub { ok $token_url, "Found a token url $token_url"; # go to the token url - $mech->get_ok($token_url); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok($token_url); + }; # check that we are on '/report/new' is $mech->uri->path, '/report/new', "sent to /report/new"; @@ -240,19 +268,24 @@ subtest "Submit a correct entry (with location)" => sub { "check imported fields are shown"; # change the details - $mech->submit_form_ok( # - { - with_fields => { - name => 'New Test User ll', - title => 'New Test report ll', - detail => 'This is a test report ll', - phone => '01234 567 890', - may_show_name => '1', - category => 'Street lighting', - } - }, - "Update details and save" - ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( # + { + with_fields => { + name => 'New Test User ll', + title => 'New Test report ll', + detail => 'This is a test report ll', + phone => '01234 567 890', + may_show_name => '1', + category => 'Street lighting', + } + }, + "Update details and save" + ); + }; # check that report has been created my $user = @@ -268,72 +301,71 @@ subtest "Submit a correct entry (with location)" => sub { }; subtest "Submit a correct entry (with location) to cobrand" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fiksgatami' ], + MAPIT_URL => 'http://mapit.nuug.no/', + }, sub { + ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; - SKIP: { - skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 20 ) - unless FixMyStreet::Cobrand->exists('fiksgatami'); - mySociety::MaPit::configure('http://mapit.nuug.no/'); - ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; + $mech->get_ok('/import'); - $mech->get_ok('/import'); + $mech->submit_form_ok( # + { + with_fields => { + service => 'test-script', + lat => '59', + lon => '10', + name => 'Test User ll', + email => 'test-ll@example.com', + subject => 'Test report ll', + detail => 'This is a test report ll', + photo => $sample_file, + } + }, + "fill in form" + ); - $mech->submit_form_ok( # - { - with_fields => { - service => 'test-script', - lat => '59', - lon => '10', - name => 'Test User ll', - email => 'test-ll@example.com', - subject => 'Test report ll', - detail => 'This is a test report ll', - photo => $sample_file, - } - }, - "fill in form" - ); + is_deeply( $mech->import_errors, [], "got no errors" ); + is $mech->content, 'SUCCESS', "Got success response"; - is_deeply( $mech->import_errors, [], "got no errors" ); - is $mech->content, 'SUCCESS', "Got success response"; + # check that we have received the email + $mech->email_count_is(1); + my $email = $mech->get_email; + $mech->clear_emails_ok; - # check that we have received the email - $mech->email_count_is(1); - my $email = $mech->get_email; - $mech->clear_emails_ok; + my ($token_url) = $email->body =~ m{(http://\S+)}; + ok $token_url, "Found a token url $token_url"; - my ($token_url) = $email->body =~ m{(http://\S+)}; - ok $token_url, "Found a token url $token_url"; + # go to the token url + $mech->get_ok($token_url); - # go to the token url - $mech->get_ok($token_url); + # check that we are on '/report/new' + is $mech->uri->path, '/report/new', "sent to /report/new"; - # check that we are on '/report/new' - is $mech->uri->path, '/report/new', "sent to /report/new"; - - # check that fields are prefilled for us - is_deeply $mech->visible_form_values, - { - name => 'Test User ll', - title => 'Test report ll', - detail => 'This is a test report ll', - photo => '', - phone => '', - may_show_name => '1', - }, - "check imported fields are shown"; - - my $user = - FixMyStreet::App->model('DB::User') - ->find( { email => 'test-ll@example.com' } ); - ok $user, "Found a user"; - - my $report = $user->problems->first; - is $report->state, 'partial', 'is still partial'; - is $report->title, 'Test report ll', 'title is correct'; - is $report->lang, 'nb', 'language is correct'; - - $mech->delete_user($user); - } + # check that fields are prefilled for us + is_deeply $mech->visible_form_values, + { + name => 'Test User ll', + title => 'Test report ll', + detail => 'This is a test report ll', + photo => '', + phone => '', + may_show_name => '1', + }, + "check imported fields are shown"; + + my $user = + FixMyStreet::App->model('DB::User') + ->find( { email => 'test-ll@example.com' } ); + ok $user, "Found a user"; + + my $report = $user->problems->first; + is $report->state, 'partial', 'is still partial'; + is $report->title, 'Test report ll', 'title is correct'; + is $report->lang, 'nb', 'language is correct'; + + $mech->delete_user($user); + }; }; done_testing(); diff --git a/t/app/controller/report_interest_count.t b/t/app/controller/report_interest_count.t index bfd1a8d1f..3de931c74 100644 --- a/t/app/controller/report_interest_count.t +++ b/t/app/controller/report_interest_count.t @@ -51,10 +51,9 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( my $report_id = $report->id; ok $report, "created test report - $report_id"; -SKIP: { - skip( "Need 'fixmybarangay' in ALLOWED_COBRANDS config", 29 ) - unless FixMyStreet::Cobrand->exists('fixmybarangay'); - +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmybarangay' ], +}, sub { $mech->create_body_ok(2504, 'Westminster City Council'); for my $test ( diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index d1f246e95..2993eddac 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -454,17 +454,22 @@ foreach my $test ( $mech->get_ok('/around'); # submit initial pc form - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "submit location" ); - is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; - - # click through to the report page - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" ); - - # submit the main form - $mech->submit_form_ok( { with_fields => $test->{fields} }, - "submit form" ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "submit location" ); + is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; + + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); + + # submit the main form + $mech->submit_form_ok( { with_fields => $test->{fields} }, + "submit form" ); + }; # check that we got the errors expected is_deeply $mech->page_errors, $test->{errors}, "check errors"; @@ -522,30 +527,35 @@ foreach my $test ( # submit initial pc form $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, - "submit location" ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, + "submit location" ); - # click through to the report page - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" ); + # click through to the report page + $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.', - photo => '', - name => 'Joe Bloggs', - may_show_name => '1', - email => 'test-1@example.com', - phone => '07903 123 456', - category => 'Street lighting', - password_register => $test->{password} ? 'secret' : '', - } - }, - "submit good details" - ); + $mech->submit_form_ok( + { + button => 'submit_register', + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + email => 'test-1@example.com', + phone => '07903 123 456', + category => 'Street lighting', + password_register => $test->{password} ? 'secret' : '', + } + }, + "submit good details" + ); + }; # check that we got the errors expected is_deeply $mech->page_errors, [], "check there were no errors"; @@ -635,27 +645,32 @@ subtest "test password errors for a user who is signing in as they report" => su # submit initial pc form $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, - "submit location" ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, + "submit location" ); - # click through to the report page - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" ); + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); - $mech->submit_form_ok( - { - button => 'submit_sign_in', - with_fields => { - title => 'Test Report', - detail => 'Test report details.', - photo => '', - email => 'test-2@example.com', - password_sign_in => 'secret1', - category => 'Street lighting', - } - }, - "submit with wrong password" - ); + $mech->submit_form_ok( + { + button => 'submit_sign_in', + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + email => 'test-2@example.com', + password_sign_in => 'secret1', + category => 'Street lighting', + } + }, + "submit with wrong password" + ); + }; # check that we got the errors expected is_deeply $mech->page_errors, [ @@ -682,42 +697,47 @@ subtest "test report creation for a user who is signing in as they report" => su # submit initial pc form $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, - "submit location" ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, + "submit location" ); - # click through to the report page - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" ); + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); - $mech->submit_form_ok( - { - button => 'submit_sign_in', - with_fields => { - title => 'Test Report', - detail => 'Test report details.', - photo => '', - email => 'test-2@example.com', - password_sign_in => 'secret2', - category => 'Street lighting', - } - }, - "submit good details" - ); + $mech->submit_form_ok( + { + button => 'submit_sign_in', + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + email => 'test-2@example.com', + password_sign_in => 'secret2', + category => 'Street lighting', + } + }, + "submit good details" + ); - # check that we got the errors expected - is_deeply $mech->page_errors, [ - 'You have successfully signed in; please check and confirm your details are accurate:', - ], "check there were errors"; + # check that we got the errors expected + is_deeply $mech->page_errors, [ + 'You have successfully signed in; please check and confirm your details are accurate:', + ], "check there were errors"; - # Now submit with a name - $mech->submit_form_ok( - { - with_fields => { - name => 'Joe Bloggs', - } - }, - "submit good details" - ); + # Now submit with a name + $mech->submit_form_ok( + { + with_fields => { + name => 'Joe Bloggs', + } + }, + "submit good details" + ); + }; # find the report my $report = $user->problems->first; @@ -776,42 +796,47 @@ foreach my $test ( # submit initial pc form $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, - "submit location" ); - - # click through to the report page - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" ); - - # check that the fields are correctly prefilled - is_deeply( - $mech->visible_form_values, - { - title => '', - detail => '', - may_show_name => '1', - name => 'Test User', - phone => '01234 567 890', - photo => '', - category => '-- Pick a category --', - }, - "user's details prefilled" - ); - - $mech->submit_form_ok( - { - with_fields => { - title => "Test Report at café", - detail => 'Test report details.', - photo => '', - name => 'Joe Bloggs', + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR', } }, + "submit location" ); + + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); + + # check that the fields are correctly prefilled + is_deeply( + $mech->visible_form_values, + { + title => '', + detail => '', may_show_name => '1', - phone => '07903 123 456', - category => $test->{category}, - } - }, - "submit good details" - ); + name => 'Test User', + phone => '01234 567 890', + photo => '', + category => '-- Pick a category --', + }, + "user's details prefilled" + ); + + $mech->submit_form_ok( + { + with_fields => { + title => "Test Report at café", + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + phone => '07903 123 456', + category => $test->{category}, + } + }, + "submit good details" + ); + }; # find the report my $report = $user->problems->first; @@ -870,27 +895,32 @@ subtest "test report creation for a category that is non public" => sub { # submit initial pc form $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, - "submit location" ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, + "submit location" ); - # click through to the report page - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" ); + # click through to the report page + $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.', - photo => '', - email => 'test-2@example.com', - name => 'Joe Bloggs', - category => 'Street lighting', - } - }, - "submit good details" - ); + $mech->submit_form_ok( + { + button => 'submit_register', + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + email => 'test-2@example.com', + name => 'Joe Bloggs', + category => 'Street lighting', + } + }, + "submit good details" + ); + }; # find the report my $report = $user->problems->first; @@ -927,11 +957,22 @@ subtest "test report creation for a category that is non public" => sub { $contact2->category( "Pothol\xc3\xa9s" ); $contact2->update; -my $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=' . $saved_lat . '&longitude=' . $saved_lon ); +my $extra_details; +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=' . $saved_lat . '&longitude=' . $saved_lon ); +}; $mech->content_contains( "Pothol\xc3\xa9s" ); ok !$extra_details->{titles_list}, 'Non Bromley does not send back list of titles'; -$extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.4021&longitude=0.01578'); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $extra_details = $mech->get_ok_json( '/report/new/ajax?latitude=51.4021&longitude=0.01578'); +}; ok $extra_details->{titles_list}, 'Bromley sends back list of titles'; #### test uploading an image @@ -940,18 +981,22 @@ ok $extra_details->{titles_list}, 'Bromley sends back list of titles'; #### possibly manual testing # create report without using map -# create report by clicking on may with javascript off +# create report by clicking on map with javascript off # create report with images off subtest "check that a lat/lon off coast leads to /around" => sub { my $off_coast_latitude = 50.78301; my $off_coast_longitude = -0.646929; - $mech->get_ok( # - "/report/new" - . "?latitude=$off_coast_latitude" - . "&longitude=$off_coast_longitude" - ); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok( # + "/report/new" + . "?latitude=$off_coast_latitude" + . "&longitude=$off_coast_longitude" + ); + }; is $mech->uri->path, '/around', "redirected to '/around'"; @@ -1015,9 +1060,10 @@ for my $test ( ) { subtest $test->{desc} => sub { - if ( $test->{host} =~ /bromley/ && !FixMyStreet::Cobrand->exists('bromley') ) { - plan skip_all => 'Skipping Bromley tests without Bromley cobrand'; - } + my $override = { + ALLOWED_COBRANDS => [ $test->{host} =~ /bromley/ ? 'bromley' : 'fixmystreet' ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }; $mech->host( $test->{host} ); @@ -1025,12 +1071,14 @@ for my $test ( $mech->clear_emails_ok; $mech->get_ok('/'); - $mech->submit_form_ok( { with_fields => { pc => $test->{postcode}, } }, - "submit location" ); - $mech->follow_link_ok( - { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" - ); + FixMyStreet::override_config $override, sub { + $mech->submit_form_ok( { with_fields => { pc => $test->{postcode}, } }, + "submit location" ); + $mech->follow_link_ok( + { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" + ); + }; my $fields = $mech->visible_form_values('mapSkippedForm'); if ( $test->{fms_extra_title} ) { @@ -1072,8 +1120,10 @@ for my $test ( $submission_fields->{name} = 'Test User'; } - $mech->submit_form_ok( { with_fields => $submission_fields }, - "submit good details" ); + FixMyStreet::override_config $override, sub { + $mech->submit_form_ok( { with_fields => $submission_fields }, + "submit good details" ); + }; my $email = $mech->get_email; ok $email, "got an email"; @@ -1128,18 +1178,23 @@ subtest 'user title not reset if no user title in submission' => sub { }; $mech->get_ok('/'); - $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP', } }, - "submit location" ); - $mech->follow_link_ok( - { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" - ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP', } }, + "submit location" ); + $mech->follow_link_ok( + { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" + ); - my $fields = $mech->visible_form_values('mapSkippedForm'); - ok !exists( $fields->{fms_extra_title} ), 'user title field not displayed'; + my $fields = $mech->visible_form_values('mapSkippedForm'); + ok !exists( $fields->{fms_extra_title} ), 'user title field not displayed'; - $mech->submit_form_ok( { with_fields => $submission_fields }, - "submit good details" ); + $mech->submit_form_ok( { with_fields => $submission_fields }, + "submit good details" ); + }; $user->discard_changes; my $report = $user->problems->first; @@ -1148,10 +1203,7 @@ subtest 'user title not reset if no user title in submission' => sub { is $user->title, 'MR', 'User title unchanged'; }; -SKIP: { - skip( "Need 'lichfielddc' in ALLOWED_COBRANDS config", 100 ) - unless FixMyStreet::Cobrand->exists('lichfielddc'); - +subtest "test Lichfield" => sub { for my $test ( { desc => 'confirm link for cobrand council in two tier cobrand links to cobrand site', @@ -1190,32 +1242,38 @@ SKIP: { my $user = $mech->log_in_ok($test_email) if $test->{redirect}; - $mech->get_ok('/around'); - $mech->content_contains( "Lichfield District Council FixMyStreet" ); - $mech->submit_form_ok( { with_fields => { pc => 'WS13 7RD' } }, "submit location" ); - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); - my %optional_fields = $test->{redirect} ? () : - ( email => $test_email, phone => '07903 123 456' ); - - # we do this as otherwise test::www::mechanize::catalyst - # goes to the value set in ->host above irregardless and - # that is a 404. It works but it is not pleasant. - $mech->clear_host if $test->{redirect} && $test->{national}; - $mech->submit_form_ok( - { - button => $test->{button}, - with_fields => { - title => 'Test Report', - detail => 'Test report details.', - photo => '', - name => 'Joe Bloggs', - may_show_name => '1', - category => $test->{category}, - %optional_fields - } - }, - "submit good details" - ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'lichfielddc', 'fixmystreet' ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok('/around'); + $mech->content_contains( "Lichfield District Council FixMyStreet" ); + $mech->submit_form_ok( { with_fields => { pc => 'WS13 7RD' } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + my %optional_fields = $test->{redirect} ? () : + ( email => $test_email, phone => '07903 123 456' ); + + # we do this as otherwise test::www::mechanize::catalyst + # goes to the value set in ->host above irregardless and + # that is a 404. It works but it is not pleasant. + $mech->clear_host if $test->{redirect} && $test->{national}; + $mech->submit_form_ok( + { + button => $test->{button}, + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + photo => '', + name => 'Joe Bloggs', + may_show_name => '1', + category => $test->{category}, + %optional_fields + } + }, + "submit good details" + ); + }; is_deeply $mech->page_errors, [], "check there were no errors"; # check that the user has been created/ not changed @@ -1232,9 +1290,8 @@ SKIP: { if ( $test->{redirect} ) { is $mech->uri->path, "/report/" . $report->id, "redirected to report page"; - my $base = FixMyStreet->config('BASE_URL'); - $base =~ s{http://}{}; - $base = "lichfielddc.$base" unless $test->{national}; + my $base = 'www.fixmystreet.com'; + $base = "lichfielddc.fixmystreet.com" unless $test->{national}; is $mech->uri->host, $base, 'redirected to correct site'; } else { # receive token @@ -1246,21 +1303,34 @@ SKIP: { ok $url, "extracted confirm url '$url'"; # confirm token - $mech->get_ok($url); - - my $base = FixMyStreet->config('BASE_URL'); - $base =~ s{http://}{http://lichfielddc.} unless $test->{national}; + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'lichfielddc', 'fixmystreet' ], + BASE_URL => 'http://www.fixmystreet.com', + }, sub { + $mech->get_ok($url); + }; + + my $base = 'www.fixmystreet.com'; + $base = 'lichfielddc.fixmystreet.com' unless $test->{national}; $mech->content_contains( $base . '/report/' . $report->id, 'confirm page links to correct site' ); if ( $test->{national} ) { # Shouldn't be found, as it was a county problem - is $mech->get( '/report/' . $report->id )->code, 404, "report not found"; + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'lichfielddc', 'fixmystreet' ], + }, sub { + is $mech->get( '/report/' . $report->id )->code, 404, "report not found"; + }; # But should be on the main site $mech->host( 'www.fixmystreet.com' ); } - $mech->get_ok( '/report/' . $report->id ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'lichfielddc', 'fixmystreet' ], + }, sub { + $mech->get_ok( '/report/' . $report->id ); + }; } $report->discard_changes; @@ -1271,12 +1341,9 @@ SKIP: { $mech->delete_user($user); }; } -} - -SKIP: { - skip( "Need 'seesomething' in ALLOWED_COBRANDS config", 100 ) - unless FixMyStreet::Cobrand->exists('seesomething'); +}; +subtest "test SeeSomething" => sub { $mech->host('seesomething.fixmystreet.com'); $mech->clear_emails_ok; $mech->log_out_ok; @@ -1346,22 +1413,27 @@ SKIP: { } $mech->get_ok( '/around' ); - $mech->submit_form_ok( - { - with_fields => { - pc => $test->{pc}, + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'seesomething' ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( + { + with_fields => { + pc => $test->{pc}, + }, }, - }, - 'submit around form', - ); - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + 'submit around form', + ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); - $mech->submit_form_ok( - { - with_fields => $test->{fields}, - }, - 'Submit form details with no user details', - ); + $mech->submit_form_ok( + { + with_fields => $test->{fields}, + }, + 'Submit form details with no user details', + ); + }; is_deeply $mech->page_errors, [], "check there were no errors"; $user = @@ -1385,7 +1457,25 @@ SKIP: { } $bus_contact->delete; -} +}; + +subtest "categories from deleted bodies shouldn't be visible for new reports" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok('/report/new/ajax?latitude=51.89&longitude=-2.09'); # Cheltenham + ok $mech->content_contains( $contact3->category ); + + # Delete the body which the contact belongs to. + $contact3->body->update( { deleted => 1 } ); + + $mech->get_ok('/report/new/ajax?latitude=51.89&longitude=-2.09'); # Cheltenham + ok $mech->content_lacks( $contact3->category ); + + $contact3->body->update( { deleted => 0 } ); + }; +}; $contact1->delete; $contact2->delete; diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index ed26d58d5..4745d92cd 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -116,17 +116,22 @@ foreach my $test ( $mech->get_ok('/around'); # submit initial pc form - $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, - "submit location" ); - is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; - - # click through to the report page - $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, - "follow 'skip this step' link" ); - - # submit the main form - $mech->submit_form_ok( { with_fields => $test->{fields} }, - "submit form" ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, + "submit location" ); + is_deeply $mech->page_errors, [], "no errors for pc '$test->{pc}'"; + + # click through to the report page + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, + "follow 'skip this step' link" ); + + # submit the main form + $mech->submit_form_ok( { with_fields => $test->{fields} }, + "submit form" ); + }; # check that we got the errors expected is_deeply $mech->page_errors, $test->{errors}, "check errors"; @@ -152,7 +157,12 @@ foreach my $test ( %{ $test->{fields} }, %{ $test->{submit_with} }, }; - $mech->submit_form_ok( { with_fields => $new_values } ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->submit_form_ok( { with_fields => $new_values } ); + }; $user = FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); ok $user, 'created user'; diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 14a4b2150..42e69fd03 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -42,9 +42,13 @@ is $stats->{'City of Edinburgh Council'}->[2], 1, 'correct number of older repor is $stats->{'Westminster City Council'}->[1], 5, 'correct number of reports for Westminster'; -$mech->follow_link_ok( { text_regex => qr/Birmingham/ } ); +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $mech->follow_link_ok( { text_regex => qr/Birmingham/ } ); + $mech->get_ok('/reports/Westminster'); +}; -$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'); @@ -55,7 +59,11 @@ 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'); +FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $mech->get_ok('/reports/Westminster'); +}; $problems = $mech->extract_problem_list; is scalar @$problems, 4, 'only public problems are displayed'; @@ -65,24 +73,30 @@ $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'); - ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; - $mech->get_ok('/reports'); - # EHA lacks one column the others have - $mech->content_lacks('state unknown'); - - skip( "Need 'fiksgatami' in ALLOWED_COBRANDS config", 8 ) - unless FixMyStreet::Cobrand->exists('fiksgatami'); - $mech->create_body_ok(3, 'Oslo'); - mySociety::MaPit::configure('http://mapit.nuug.no/'); - ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; - $mech->get_ok('/reports'); - # There should only be one Oslo - $mech->content_contains('Oslo'); - $mech->content_unlike(qr{Oslo">Oslo.*Oslo}s); -} +subtest "test emptyhomes all reports page" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'emptyhomes' ], + }, sub { + ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes'; + $mech->get_ok('/reports'); + # EHA lacks one column the others have + $mech->content_lacks('state unknown'); + }; +}; + +subtest "test fiksgatami all reports page" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fiksgatami' ], + MAPIT_URL => 'http://mapit.nuug.no/', + }, sub { + $mech->create_body_ok(3, 'Oslo'); + ok $mech->host("fiksgatami.no"), 'change host to fiksgatami'; + $mech->get_ok('/reports'); + # There should only be one Oslo + $mech->content_contains('Oslo'); + $mech->content_unlike(qr{Oslo">Oslo.*Oslo}s); + } +}; done_testing(); diff --git a/t/app/controller/rss.t b/t/app/controller/rss.t index ec6a01b50..bafa1ddc0 100644 --- a/t/app/controller/rss.t +++ b/t/app/controller/rss.t @@ -42,8 +42,13 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { user_id => $user1->id, } ); - -$mech->get_ok("/rss/pc/EH11BB/2"); +$mech->host('www.fixmystreet.com'); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $mech->get_ok("/rss/pc/EH11BB/2"); +}; $mech->content_contains( "Testing, 10th October" ); $mech->content_lacks( 'Nearest road to the pin' ); @@ -111,7 +116,12 @@ $report->geocode( ); $report->update(); -$mech->get_ok("/rss/pc/EH11BB/2"); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $mech->get_ok("/rss/pc/EH11BB/2"); +}; $mech->content_contains( "Testing, 10th October" ); $mech->content_contains( '18 North Bridge, Edinburgh' ); @@ -168,11 +178,17 @@ my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_c subtest "check RSS feeds on cobrand have correct URLs for non-cobrand reports" => sub { $mech->host('lichfielddc.fixmystreet.com'); - $mech->get_ok("/rss/area/Lichfield"); - my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id; - my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('lichfielddc')->new(); - my $expected2 = $cobrand->base_url . '/report/' . $report_to_council->id; + my $expected2; + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'lichfielddc' ], + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + $mech->get_ok("/rss/area/Lichfield"); + my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('lichfielddc')->new(); + $expected2 = $cobrand->base_url . '/report/' . $report_to_council->id; + }; $mech->content_contains($expected1, 'non cobrand area report point to fixmystreet.com'); $mech->content_contains($expected2, 'cobrand area report point to cobrand url'); diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t index ba48300b2..ae413978f 100644 --- a/t/app/model/alert_type.t +++ b/t/app/model/alert_type.t @@ -97,6 +97,7 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( alert_type => 'new_updates', whensubscribed => $dt->ymd . ' ' . $dt->hms, confirmed => 1, + cobrand => 'default', } ); @@ -107,6 +108,7 @@ my $alert3 = FixMyStreet::App->model('DB::Alert')->find_or_create( alert_type => 'new_updates', whensubscribed => $dt->ymd . ' ' . $dt->hms, confirmed => 1, + cobrand => 'default', } ); @@ -185,7 +187,11 @@ subtest "correct text for title after URL" => sub { parameter => $report->id, } )->delete; - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; my $email = $mech->get_email; (my $title = $report->title) =~ s/ /\\s+/; @@ -318,7 +324,11 @@ foreach my $test ( $report->geocode( $g ); $report->update(); - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; my $email = $mech->get_email; my $body = $email->body; @@ -423,7 +433,11 @@ subtest "check alerts from cobrand send main site url for alerts for different c } )->delete; - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.mysociety.org/', + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; my $email = $mech->get_email; my $body = $email->body; @@ -473,7 +487,34 @@ subtest "check local alerts from cobrand send main site url for alerts for diffe like $body, qr#$expected2#, 'cobrand area report point to cobrand url'; }; -$report->comments->delete(); -$report->delete(); -done_testing(); +# Test that email alerts are sent in the right language. +subtest "correct i18n-ed summary for state of closed" => sub { + $mech->clear_emails_ok; + + $report->update( { state => 'closed' } ); + $alert->update( { lang => 'nb', cobrand => 'fiksgatami' } ); + FixMyStreet::App->model('DB::AlertSent')->search( { + alert_id => $alert->id, + parameter => $comment->id, + } )->delete; + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fiksgatami' ], + }, sub { + FixMyStreet::App->model('DB::AlertType')->email_alerts(); + }; + + $mech->email_count_is( 1 ); + my $email = $mech->get_email; + my $body = $email->body; + my $msg = 'Denne rapporten er for tiden markert som lukket'; + like $body, qr/$msg/, 'email says problem is closed, in Norwegian'; +}; + +END { + $mech->delete_user($user) if $user; + $mech->delete_user($user2) if $user2; + $mech->delete_user($user3) if $user3; + done_testing(); +} diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 7daa653fc..fa8cf89ae 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -9,6 +9,7 @@ use FixMyStreet; use FixMyStreet::App; use FixMyStreet::TestMech; use mySociety::Locale; +use Sub::Override; mySociety::Locale::gettext_domain('FixMyStreet'); @@ -464,8 +465,8 @@ foreach my $test ( { desc => 'email to two tier council', unset_whendef => 1, email_count => 1, - to => qr'Gloucestershire County Council.*Cheltenham Borough Council', - dear => qr'Dear Gloucestershire County Council and Cheltenham Borough', + to => qr'Cheltenham Borough Council.*Gloucestershire County Council', + dear => qr'Dear Cheltenham Borough Council and Gloucestershire County', body => '2226,2326', multiple => 1, }, { @@ -496,7 +497,7 @@ foreach my $test ( { dear => qr'Dear Staffordshire County Council,', body => '2240', cobrand => 'lichfielddc', - url => '', + url => 'www.', }, { %common, desc => 'directs NI correctly, 1', @@ -525,8 +526,13 @@ foreach my $test ( { }, ) { subtest $test->{ desc } => sub { - if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ && !FixMyStreet::Cobrand->exists('lichfielddc') ) { - plan skip_all => 'Skipping Lichfield tests without Lichfield cobrand'; + my $override = { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }; + if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ ) { + $override->{ALLOWED_COBRANDS} = [ 'lichfielddc' ]; } $mech->clear_emails_ok; @@ -548,7 +554,9 @@ foreach my $test ( { cobrand => $test->{ cobrand } || 'fixmystreet', } ); - FixMyStreet::App->model('DB::Problem')->send_reports(); + FixMyStreet::override_config $override, sub { + FixMyStreet::App->model('DB::Problem')->send_reports(); + }; $mech->email_count_is( $test->{ email_count } ); if ( $test->{ email_count } ) { @@ -567,9 +575,8 @@ foreach my $test ( { } if ( $test->{url} ) { - (my $base_url = FixMyStreet->config('BASE_URL')) =~ s{http://}{}; my $id = $problem->id; - like $email->body, qr[$test->{url}$base_url/report/$id], 'URL present is correct'; + like $email->body, qr[$test->{url}fixmystreet.com/report/$id], 'URL present is correct'; } $problem->discard_changes; @@ -582,10 +589,57 @@ foreach my $test ( { }; } -subtest 'check can turn on report sent email alerts' => sub { - eval 'use Test::MockModule; 1' or - plan skip_all => 'Skipping tests that rely on Test::MockModule'; +subtest 'check can set mutiple emails as a single contact' => sub { + my $override = { + ALLOWED_COBRANDS => [ 'fixmystreet' ], + BASE_URL => 'http://www.fixmystreet.com', + MAPIT_URL => 'http://mapit.mysociety.org/', + }; + + my $contact = { + body_id => 2651, # Edinburgh + category => 'trees', + email => '2636@example.com,2636-2@example.com', + }; + my $new_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + %$contact } ); + ok $new_contact, "created multiple email test contact"; + + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + bodies_str => $contact->{ body_id }, + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + category => 'trees', + name => 'Test User', + cobrand => 'fixmystreet', + send_fail_count => 0, + } ); + FixMyStreet::override_config $override, sub { + FixMyStreet::App->model('DB::Problem')->send_reports(); + }; + + $mech->email_count_is(1); + my $email = $mech->get_email; + is $email->header('To'), '"City of Edinburgh Council" <2636@example.com>, "City of Edinburgh Council" <2636-2@example.com>', 'To contains two email addresses'; +}; + +subtest 'check can turn on report sent email alerts' => sub { + my $send_confirmation_mail_override = Sub::Override->new( + "FixMyStreet::Cobrand::Default::report_sent_confirmation_email", + sub { return 1; } + ); $mech->clear_emails_ok; FixMyStreet::App->model('DB::Problem')->search( @@ -606,9 +660,6 @@ subtest 'check can turn on report sent email alerts' => sub { send_fail_count => 0, } ); - my $m = new Test::MockModule( - 'FixMyStreet::Cobrand::FixMyStreet' ); - $m->mock( report_sent_confirmation_email => 1 ); FixMyStreet::App->model('DB::Problem')->send_reports(); $mech->email_count_is( 2 ); @@ -628,8 +679,88 @@ subtest 'check can turn on report sent email alerts' => sub { $email = $emails[1]; like $email->header('Subject'), qr/Problem Report Sent/, 'report sent email title correct'; like $email->body, qr/Your report about/, 'report sent body correct'; + + $send_confirmation_mail_override->restore(); }; + +subtest 'check iOS app store test reports not sent' => sub { + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + bodies_str => 2651, + title => 'App store test', + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + category => 'potholes', + send_fail_count => 0, + } ); + + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( 0 ); + + $problem->discard_changes(); + is $problem->state, 'hidden', 'iOS test reports are hidden automatically'; + is $problem->whensent, undef, 'iOS test reports are not sent'; +}; + +subtest 'check reports from abuser not sent' => sub { + $mech->clear_emails_ok; + + FixMyStreet::App->model('DB::Problem')->search( + { + whensent => undef + } + )->update( { whensent => \'ms_current_timestamp()' } ); + + $problem->discard_changes; + $problem->update( { + bodies_str => 2651, + title => 'Report', + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + category => 'potholes', + send_fail_count => 0, + } ); + + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( 1 ); + + $problem->discard_changes(); + ok $problem->whensent, 'Report has been sent'; + + $problem->update( { + state => 'confirmed', + confirmed => \'ms_current_timestamp()', + whensent => undef, + } ); + + my $abuse = FixMyStreet::App->model('DB::Abuse')->create( { email => $problem->user->email } ); + + $mech->clear_emails_ok; + FixMyStreet::App->model('DB::Problem')->send_reports(); + + $mech->email_count_is( 0 ); + + $problem->discard_changes(); + is $problem->state, 'hidden', 'reports from abuse user are hidden automatically'; + is $problem->whensent, undef, 'reports from abuse user are not sent'; + + ok $abuse->delete(), 'user removed from abuse table'; +}; + + $problem->comments->delete; $problem->delete; $mech->delete_user( $user ); diff --git a/t/app/model/rabx_column.t b/t/app/model/rabx_column.t new file mode 100644 index 000000000..607d578ce --- /dev/null +++ b/t/app/model/rabx_column.t @@ -0,0 +1,23 @@ +use strict; +use warnings; + +use Test::More; + +use_ok "FixMyStreet::DB::RABXColumn"; + +# Test that the class names are correctly normalised +my @tests = ( + ["FixMyStreet::DB::Result::Token", "Token"], + ["FixMyStreet::App::Model::DB::Token", "Token"], +); + +foreach my $test (@tests) { + my ($input, $expected) = @$test; + is( + FixMyStreet::DB::RABXColumn::_get_class_identifier($input), + $expected, + "$input -> $expected" + ); +} + +done_testing(); diff --git a/t/app/model/token.t b/t/app/model/token.t index 12945975e..637477fa3 100644 --- a/t/app/model/token.t +++ b/t/app/model/token.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 45; +use Test::More; use FixMyStreet; use FixMyStreet::App; @@ -94,3 +94,47 @@ foreach my $test_data_name ( sort keys %tests ) { undef, "token gone with m::AT"; } + + + +# Test that the inflation and deflation works as expected +{ + my $token = + $token_rs->create( { scope => 'testing', data => {} } ); + END { $token->delete() }; + + # Add in temporary check to test that the data is updated as expected. + is_deeply($token->data, {}, "data is empty"); + + # store something in it + $token->update({ data => { foo => 'bar' } }); + $token->discard_changes(); + is_deeply($token->data, { foo => 'bar' }, "data has content"); + + # change the hash stored + $token->update({ data => { baz => 'bundy' } }); + $token->discard_changes(); + is_deeply($token->data, { baz => 'bundy' }, "data has new content"); + + # change the hashref in place + { + my $data = $token->data; + $data->{baz} = 'new'; + $token->data( $data ); + $token->update(); + $token->discard_changes(); + is_deeply($token->data, { baz => 'new' }, "data has been updated"); + } + + # change the hashref in place + { + my $data = $token->data; + $data->{baz} = 'new'; + $token->update({ data => $data }); + $token->discard_changes(); + is_deeply($token->data, { baz => 'new' }, "data has been updated"); + } + +} + +done_testing(); diff --git a/t/app/uri_for.t b/t/app/uri_for.t index bf965fb62..810aade62 100644 --- a/t/app/uri_for.t +++ b/t/app/uri_for.t @@ -44,25 +44,29 @@ is( 'FiksGataMi url with lat not zoom' ); -SKIP: { - skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 2 ) - unless FixMyStreet::Cobrand->exists('emptyhomes'); - +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'emptyhomes' ], +}, sub { like( $reh_en_c->uri_for_email( '/foo' ), qr{^http://en.}, 'adds en to retain language' ); +}; - # instantiate this here otherwise sets locale to cy and breaks test - # above - my $reh_cy_c = ctx_request('http://cy.reportemptyhomes.com/'); +# instantiate this here otherwise sets locale to cy and breaks test +# above +my $reh_cy_c; +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'emptyhomes' ], +}, sub { + $reh_cy_c = ctx_request('http://cy.reportemptyhomes.com/'); like( $reh_cy_c->uri_for_email( '/foo' ), qr{^http://cy.}, 'retains language' ); -} +}; done_testing(); diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t new file mode 100644 index 000000000..91a7038ec --- /dev/null +++ b/t/cobrand/bromley.t @@ -0,0 +1,42 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +# Create test data +my $user = $mech->create_user_ok( 'bromley@example.com' ); +my $body = $mech->create_body_ok( 2482, 'Bromley' ); + +my @reports = $mech->create_problems_for_body( 1, 2482, 'Test', { + cobrand => 'bromley', + user => $user, +}); +my $report = $reports[0]; + +for my $update ('in progress', 'unable to fix') { + FixMyStreet::App->model('DB::Comment')->find_or_create( { + problem_state => $update, + problem_id => $report->id, + user_id => $user->id, + name => 'User', + mark_fixed => 'f', + text => "This update marks it as $update", + state => 'confirmed', + confirmed => 'now()', + anonymous => 'f', + } ); +} + +# Test Bromley special casing of 'unable to fix' +$mech->get_ok( '/report/' . $report->id ); +$mech->content_contains( 'marks it as in progress' ); +$mech->content_contains( 'marked as in progress' ); +$mech->content_contains( 'marks it as unable to fix' ); +$mech->content_contains( 'marked as no further action' ); + +# Clean up +$mech->delete_user($user); +$mech->delete_problems_for_body( 2482 ); +done_testing(); diff --git a/t/cobrand/councils.t b/t/cobrand/councils.t index 8fb10cfbe..0cf25ebdf 100644 --- a/t/cobrand/councils.t +++ b/t/cobrand/councils.t @@ -6,13 +6,13 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; foreach my $council (qw/southampton reading bromley/) { - SKIP: { - skip( "Need '$council' in ALLOWED_COBRANDS config", 3 ) - unless FixMyStreet::Cobrand->exists($council); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ $council ], + }, sub { ok $mech->host("$council.fixmystreet.com"), "change host to $council"; $mech->get_ok('/'); - $mech->content_like( qr/$council/i ); - } + $mech->content_like( qr/\u$council/ ); + }; } done_testing(); diff --git a/t/cobrand/fixmybarangay.t b/t/cobrand/fixmybarangay.t index c0823eac4..b996fa0a6 100644 --- a/t/cobrand/fixmybarangay.t +++ b/t/cobrand/fixmybarangay.t @@ -2,9 +2,6 @@ use strict; use warnings; use Test::More; -plan skip_all => 'Skipping FixMyBarangay test without FixMyBarangay cobrand' - unless FixMyStreet::Cobrand->exists('fixmybarangay'); - BEGIN { use FixMyStreet; FixMyStreet->test_mode(1); @@ -16,7 +13,11 @@ my $mech = FixMyStreet::TestMech->new; # Front page test ok $mech->host("www.fixmybarangay.com"), "change host to FixMyBarangay"; -$mech->get_ok('/'); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmybarangay' ], +}, sub { + $mech->get_ok('/'); +}; $mech->content_like( qr/FixMyBarangay/ ); # Set up bodies @@ -80,7 +81,11 @@ $mech->get_ok( '/report/' . $dps_report->id ); $mech->email_count_is(0); -FixMyStreet::App->model('DB::Problem')->send_reports('fixmybarangay'); +FixMyStreet::override_config { + SEND_REPORTS_ON_STAGING => 1, +}, sub { + FixMyStreet::App->model('DB::Problem')->send_reports('fixmybarangay'); +}; # Check BGY one sent by email my $email = $mech->get_email; @@ -111,7 +116,11 @@ is $luz_report->state, 'confirmed', 'should be confirmed'; $user = $mech->log_in_ok($fmb_test_email); -$mech->get_ok( '/report/' . $luz_report->id ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmybarangay' ], +}, sub { + $mech->get_ok( '/report/' . $luz_report->id ); +}; $mech->content_contains( "Remove from site" ); $mech->content_lacks( "Report abuse" ); diff --git a/t/cobrand/get_body_sender.t b/t/cobrand/get_body_sender.t index 245cb1a13..964f5c0e4 100644 --- a/t/cobrand/get_body_sender.t +++ b/t/cobrand/get_body_sender.t @@ -21,10 +21,15 @@ my $body = FixMyStreet::App->model('DB::Body')->find_or_create({ }); my $body_area = $body->body_areas->find_or_create({ area_id => 1000 }); -is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'defaults to email'; - -$body_area->update({ area_id => 2481 }); # Croydon LBO -is_deeply $c->get_body_sender( $body ), { method => 'London' }, 'returns london report it if London borough'; +FixMyStreet::override_config { + MAPIT_TYPES => [ 'LBO' ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'defaults to email'; + + $body_area->update({ area_id => 2481 }); # Croydon LBO + is_deeply $c->get_body_sender( $body ), { method => 'London' }, 'returns london report it if London borough'; +}; $body->send_method( 'TestMethod' ); is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to London'; diff --git a/t/cobrand/hart.t b/t/cobrand/hart.t new file mode 100644 index 000000000..f4a2473eb --- /dev/null +++ b/t/cobrand/hart.t @@ -0,0 +1,16 @@ +use strict; +use warnings; +use Test::More; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'hart' ], +}, sub { + ok $mech->host("hart.fixmystreet.com"), "change host to hart"; + $mech->get_ok('/'); + $mech->content_like( qr/Hart\b/ ); +}; + +done_testing(); diff --git a/t/cobrand/loading.t b/t/cobrand/loading.t index bd83da07f..48a10293e 100644 --- a/t/cobrand/loading.t +++ b/t/cobrand/loading.t @@ -9,51 +9,92 @@ use FixMyStreet; use_ok 'FixMyStreet::Cobrand'; # check that the allowed cobrands is correctly loaded from config -{ +sub check_allowed_cobrands { + my $should = shift; + $should = [ map { { moniker => $_, host => $_ } } @$should ]; my $allowed = FixMyStreet::Cobrand->get_allowed_cobrands; - ok $allowed, "got the allowed_cobrands"; + ok $allowed, "got the allowed_cobrands"; isa_ok $allowed, "ARRAY"; - cmp_ok scalar @$allowed, '>', 1, "got more than one"; + is_deeply $allowed, $should, "allowed_cobrands matched"; } -# fake the allowed cobrands for testing -my $override = Sub::Override->new( # - 'FixMyStreet::Cobrand::_get_allowed_cobrands' => - sub { return ['emptyhomes'] } -); -is_deeply FixMyStreet::Cobrand->get_allowed_cobrands, [ { moniker => 'emptyhomes', host => 'emptyhomes' } ], - 'overidden get_allowed_cobrands'; +FixMyStreet::override_config { ALLOWED_COBRANDS => 'fixmyhouse' }, + sub { check_allowed_cobrands([ 'fixmyhouse' ]); }; +FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixmyhouse' ] }, + sub { check_allowed_cobrands([ 'fixmyhouse' ]); }; +FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixmyhouse', 'fixmyshed' ] }, + sub { check_allowed_cobrands([ 'fixmyhouse', 'fixmyshed' ]); }; sub run_host_tests { my %host_tests = @_; for my $host ( sort keys %host_tests ) { - is FixMyStreet::Cobrand->get_class_for_host($host), - "FixMyStreet::Cobrand::$host_tests{$host}", - "does $host -> F::C::$host_tests{$host}"; + # get the cobrand class by host + my $cobrand = FixMyStreet::Cobrand->get_class_for_host($host); + my $test_class = $host_tests{$host}; + my $test_moniker = lc $test_class; + is $cobrand, "FixMyStreet::Cobrand::$test_class", "does $host -> F::C::$test_class"; + my $c = $cobrand->new(); + is $c->moniker, $test_moniker; } } -# get the cobrand class by host -run_host_tests( - 'www.fixmystreet.com' => 'Default', - 'reportemptyhomes.com' => 'EmptyHomes', - 'barnet.fixmystreet.com' => 'Default', # not in the allowed_cobrands list - 'some.odd.site.com' => 'Default', -); +# Only one cobrand, always use it +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'fixmystreet' ], +}, sub { + run_host_tests( + 'www.fixmystreet.com' => 'FixMyStreet', + 'reportemptyhomes.com' => 'FixMyStreet', + 'barnet.fixmystreet.com' => 'FixMyStreet', + 'some.odd.site.com' => 'FixMyStreet', + ); +}; + +# Only one cobrand, no .pm file, should still work +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'nopmfile' ], +}, sub { + run_host_tests( + 'www.fixmystreet.com' => 'nopmfile', + 'some.odd.site.com' => 'nopmfile', + ); +}; + +# Couple of cobrands, hostname checking and default fallback +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'emptyhomes', 'fixmystreet' ], +}, sub { + run_host_tests( + 'www.fixmystreet.com' => 'FixMyStreet', + 'reportemptyhomes.com' => 'EmptyHomes', + 'barnet.fixmystreet.com' => 'FixMyStreet', # not in the allowed_cobrands list + 'some.odd.site.com' => 'Default', + ); +}; # now enable barnet too and check that it works -$override->replace( # - 'FixMyStreet::Cobrand::_get_allowed_cobrands' => - sub { return [ 'emptyhomes', 'barnet' ] } -); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'emptyhomes', 'barnet', 'fixmystreet' ], +}, sub { + run_host_tests( + 'www.fixmystreet.com' => 'FixMyStreet', + 'reportemptyhomes.com' => 'EmptyHomes', + 'barnet.fixmystreet.com' => 'Barnet', # found now it is in allowed_cobrands + 'some.odd.site.com' => 'Default', + ); +}; -# get the cobrand class by host -run_host_tests( - 'www.fixmystreet.com' => 'Default', - 'reportemptyhomes.com' => 'EmptyHomes', - 'barnet.fixmystreet.com' => 'Barnet', # found now it is in allowed_cobrands - 'some.odd.site.com' => 'Default', -); +# And a check with some regex matching +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { 'fixmystreet' => 'empty' }, 'barnet', { 'testing' => 'fixmystreet' } ], +}, sub { + run_host_tests( + 'www.fixmystreet.com' => 'testing', + 'reportemptyhomes.com' => 'FixMyStreet', + 'barnet.fixmystreet.com' => 'Barnet', + 'some.odd.site.com' => 'Default', + ); +}; # check that the moniker works as expected both on class and object. is FixMyStreet::Cobrand::EmptyHomes->moniker, 'emptyhomes', diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 721e6517a..73007ff59 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -1,20 +1,55 @@ # TODO -# Overdue alerts +# Overdue alerts use strict; use warnings; use DateTime; use Test::More; - -plan skip_all => 'Skipping Zurich test without Zurich cobrand' - unless FixMyStreet::Cobrand->exists('zurich'); +use JSON; + +# Check that you have the required locale installed - the following +# should return a line with de_CH.utf8 in. If not install that locale. +# +# locale -a | grep de_CH +# +# To generate the translations use: +# +# commonlib/bin/gettext-makemo FixMyStreet + +use FixMyStreet; + +# This is a helper method that will send the reports but with the config +# correctly set - notably SEND_REPORTS_ON_STAGING needs to be true. +sub send_reports_for_zurich { + FixMyStreet::override_config { SEND_REPORTS_ON_STAGING => 1 }, sub { + # Actually send the report + FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); + }; +} +sub reset_report_state { + my ($report, $created) = @_; + $report->discard_changes; + my $extra = $report->extra; + delete $extra->{moderated_overdue}; + delete $extra->{subdiv_overdue}; + delete $extra->{closed_overdue}; + $report->update({ + extra => { %$extra }, + state => 'unconfirmed', + $created ? ( created => $created ) : (), + }); +} use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; # Front page test -ok $mech->host("zurich.fixmystreet.com"), "change host to Zurich"; -$mech->get_ok('/'); +ok $mech->host("zurich.example.com"), "change host to Zurich"; +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok('/'); +}; $mech->content_like( qr/zurich/i ); # Set up bodies @@ -36,6 +71,40 @@ $external_body->send_method( 'Zurich' ); $external_body->endpoint( 'external_body@example.org' ); $external_body->update; +sub cleanup { + $mech->delete_problems_for_body( $division->id ); + $mech->delete_problems_for_body( $subdivision->id ); + $mech->delete_user( 'dm1@example.org' ); + $mech->delete_user( 'sdm1@example.org' ); +} + +sub get_export_rows_count { + my $mech = shift; + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get_ok( '/admin/stats?export=1' ); + }; + is $mech->res->code, 200, 'csv retrieved ok'; + is $mech->content_type, 'text/csv', 'content_type correct' and do { + my @lines = split /\n/, $mech->content; + return @lines - 1; + }; + return; +} + +cleanup(); + +my $EXISTING_REPORT_COUNT = 0; + +subtest "set up superuser" => sub { + my $superuser = $mech->log_in_ok( 'super@example.org' ); + # a user from body $zurich is a superuser, as $zurich has no parent id! + $superuser->update({ from_body => $zurich->id }); + $EXISTING_REPORT_COUNT = get_export_rows_count($mech); + $mech->log_out_ok; +}; + my @reports = $mech->create_problems_for_body( 1, 2, 'Test', { state => 'unconfirmed', confirmed => undef, @@ -43,61 +112,230 @@ my @reports = $mech->create_problems_for_body( 1, 2, 'Test', { }); my $report = $reports[0]; -$mech->get_ok( '/report/' . $report->id ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/report/' . $report->id ); +}; $mech->content_contains('Überprüfung ausstehend'); # Check logging in to deal with this report -$mech->get_ok( '/admin' ); -is $mech->uri->path, '/auth', "got sent to the sign in page"; - -my $user = $mech->log_in_ok( 'dm1@example.org') ; -$user->from_body( undef ); -$user->update; -$mech->get_ok( '/admin' ); -is $mech->uri->path, '/my', "got sent to /my"; -$user->from_body( 2 ); -$user->update; - -$mech->get_ok( '/admin' ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/admin' ); + is $mech->uri->path, '/auth', "got sent to the sign in page"; + + my $user = $mech->log_in_ok( 'dm1@example.org') ; + $user->from_body( undef ); + $user->update; + $mech->get_ok( '/admin' ); + is $mech->uri->path, '/my', "got sent to /my"; + $user->from_body( 2 ); + $user->update; + + $mech->get_ok( '/admin' ); +}; is $mech->uri->path, '/admin', "am logged in"; $mech->content_contains( 'report_edit/' . $report->id ); $mech->content_contains( DateTime->now->strftime("%d.%m.%Y") ); $mech->content_contains( 'Erfasst' ); -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->content_contains( 'Unbestätigt' ); # Unconfirmed email -$mech->submit_form_ok( { with_fields => { state => 'confirmed' } } ); -$mech->get_ok( '/report/' . $report->id ); -$mech->content_contains('Aufgenommen'); -$mech->content_contains('Test Test'); -$mech->content_lacks('photo/' . $report->id . '.jpeg'); -$mech->email_count_is(0); - -# Photo publishing -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->submit_form_ok( { with_fields => { publish_photo => 1 } } ); -$mech->get_ok( '/report/' . $report->id ); -$mech->content_contains('photo/' . $report->id . '.jpeg'); - -# Internal notes -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->submit_form_ok( { with_fields => { internal_notes => 'Some internal notes.' } } ); -$mech->content_contains( 'Some internal notes' ); - -# Original description -$mech->submit_form_ok( { with_fields => { detail => 'Edited details text.' } } ); -$mech->content_contains( 'Edited details text.' ); -$mech->content_contains( 'Originaltext: “Test Test 1 for 2 Detail”' ); - -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->submit_form_ok( { with_fields => { body_subdivision => 3 } } ); - -$mech->get_ok( '/report/' . $report->id ); -$mech->content_contains('In Bearbeitung'); -$mech->content_contains('Test Test'); -FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); +subtest "changing of categories" => sub { + # create a few categories (which are actually contacts) + foreach my $name ( qw/Cat1 Cat2/ ) { + FixMyStreet::App->model('DB::Contact')->find_or_create({ + body => $division, + category => $name, + email => "$name\@example.org", + confirmed => 1, + deleted => 0, + editor => "editor", + whenedited => DateTime->now(), + note => "note for $name", + }); + } + + # put report into known category + my $original_category = $report->category; + $report->update({ category => 'Cat1' }); + is( $report->category, "Cat1", "Category set to Cat1" ); + + # get the latest comment + my $comments_rs = $report->comments->search({},{ order_by => { -desc => "created" } }); + ok ( !$comments_rs->first, "There are no comments yet" ); + + # change the category via the web interface + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { category => 'Cat2' } } ); + }; + + # check changes correctly saved + $report->discard_changes(); + is( $report->category, "Cat2", "Category changed to Cat2 as expected" ); + + # Check that a new comment has been created. + my $new_comment = $comments_rs->first(); + is( $new_comment->text, "Weitergeleitet von Cat1 an Cat2", "category change comment created" ); + + # restore report to original category. + $report->update({category => $original_category }); +}; + +sub get_moderated_count { + # my %date_params = ( ); + # my $moderated = FixMyStreet::App->model('DB::Problem')->search({ + # extra => { like => '%moderated_overdue,I1:0%' }, %date_params } )->count; + # return $moderated; + + # use a separate mech to avoid stomping on test state + my $mech = FixMyStreet::TestMech->new; + my $user = $mech->log_in_ok( 'super@example.org' ); + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get( '/admin/stats' ); + }; + if ($mech->content =~/Innerhalb eines Arbeitstages moderiert: (\d+)/) { + return $1; + } + else { + fail sprintf "Could not get moderation results (%d)", $mech->status; + return undef; + } +} + +subtest "report_edit" => sub { + + ok ( ! exists ${$report->extra}{moderated_overdue}, 'Report currently unmoderated' ); + + is get_moderated_count(), 0; + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->content_contains( 'Unbestätigt' ); # Unconfirmed email + $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } ); + $mech->get_ok( '/report/' . $report->id ); + }; + + $mech->content_contains('Aufgenommen'); + $mech->content_contains('Test Test'); + $mech->content_lacks('photo/' . $report->id . '.jpeg'); + $mech->email_count_is(0); + + $report->discard_changes; + + is ( $report->extra->{moderated_overdue}, 0, 'Report now marked moderated' ); + is get_moderated_count(), 1; + + + # Set state back to 10 days ago so that report is overdue + my $created = $report->created; + reset_report_state($report, $created->clone->subtract(days => 10)); + + is get_moderated_count(), 0; + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } ); + $mech->get_ok( '/report/' . $report->id ); + }; + $report->discard_changes; + is ( $report->extra->{moderated_overdue}, 1, 'moderated_overdue set correctly when overdue' ); + is get_moderated_count(), 0, 'Moderated count not increased when overdue'; + + reset_report_state($report, $created); + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } ); + $mech->get_ok( '/report/' . $report->id ); + }; + $report->discard_changes; + is ( $report->extra->{moderated_overdue}, 0, 'Marking confirmed sets moderated_overdue' ); + is ( $report->extra->{closed_overdue}, undef, 'Marking confirmed does NOT set closed_overdue' ); + is get_moderated_count(), 1; + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'hidden' } } ); + $mech->get_ok( '/admin/report_edit/' . $report->id ); + }; + $report->discard_changes; + is ( $report->extra->{moderated_overdue}, 0, 'Still marked moderated_overdue' ); + is ( $report->extra->{closed_overdue}, 0, 'Marking hidden also set closed_overdue' ); + is get_moderated_count(), 1, 'Check still counted moderated' + or diag $report->get_column('extra'); + + reset_report_state($report); + + is ( $report->extra->{moderated_overdue}, undef, 'Sanity check' ); + is get_moderated_count(), 0; + + # Check that setting to 'hidden' also triggers moderation + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'hidden' } } ); + $mech->get_ok( '/admin/report_edit/' . $report->id ); + }; + $report->discard_changes; + is ( $report->extra->{moderated_overdue}, 0, 'Marking hidden from scratch sets moderated_overdue' ); + is ( $report->extra->{closed_overdue}, 0, 'Marking hidden from scratch also set closed_overdue' ); + is get_moderated_count(), 1; + + is (FixMyStreet::Cobrand::Zurich->new->get_or_check_overdue($report), 0, 'sanity check'); + $report->update({ created => $created->clone->subtract(days => 10) }); + is (FixMyStreet::Cobrand::Zurich->new->get_or_check_overdue($report), 0, 'overdue call not increased'); + + reset_report_state($report, $created); +}; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + # Photo publishing + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'confirmed', publish_photo => 1 } } ); + $mech->get_ok( '/report/' . $report->id ); + $mech->content_contains('photo/' . $report->id . '.jpeg'); + + # Internal notes + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { new_internal_note => 'Initial internal note.' } } ); + $mech->submit_form_ok( { with_fields => { new_internal_note => 'Another internal note.' } } ); + $mech->content_contains( 'Initial internal note.' ); + $mech->content_contains( 'Another internal note.' ); + + # Original description + $mech->submit_form_ok( { with_fields => { detail => 'Edited details text.' } } ); + $mech->content_contains( 'Edited details text.' ); + $mech->content_contains( 'Originaltext: “Test Test 1 for 2 Detail”' ); + + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { body_subdivision => 3, send_rejected_email => 1 } } ); + + $mech->get_ok( '/report/' . $report->id ); + $mech->content_contains('In Bearbeitung'); + $mech->content_contains('Test Test'); +}; + +send_reports_for_zurich(); my $email = $mech->get_email; like $email->header('Subject'), qr/Neue Meldung/, 'subject looks okay'; like $email->header('To'), qr/subdivision\@example.org/, 'to line looks correct'; @@ -105,34 +343,47 @@ $mech->clear_emails_ok; $mech->log_out_ok; -$user = $mech->log_in_ok( 'sdm1@example.org') ; -$mech->get_ok( '/admin' ); +my $user = $mech->log_in_ok( 'sdm1@example.org') ; +$user->update({ from_body => undef }); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/admin' ); +}; is $mech->uri->path, '/my', "got sent to /my"; $user->from_body( 3 ); $user->update; -$mech->get_ok( '/admin' ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/admin' ); +}; is $mech->uri->path, '/admin', "am logged in"; $mech->content_contains( 'report_edit/' . $report->id ); $mech->content_contains( DateTime->now->strftime("%d.%m.%Y") ); $mech->content_contains( 'In Bearbeitung' ); -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->content_contains( 'Some internal notes' ); - -$mech->submit_form_ok( { with_fields => { status_update => 'This is an update.' } } ); -is $mech->uri->path, '/admin/report_edit/' . $report->id, "still on edit page"; -$mech->content_contains('This is an update'); -ok $mech->form_with_fields( 'status_update' ); -$mech->submit_form_ok( { button => 'no_more_updates' } ); -is $mech->uri->path, '/admin/summary', "redirected now finished with report."; - -$mech->get_ok( '/report/' . $report->id ); -$mech->content_contains('In Bearbeitung'); -$mech->content_contains('Test Test'); - -FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->content_contains( 'Initial internal note' ); + + $mech->submit_form_ok( { with_fields => { status_update => 'This is an update.' } } ); + is $mech->uri->path, '/admin/report_edit/' . $report->id, "still on edit page"; + $mech->content_contains('This is an update'); + ok $mech->form_with_fields( 'status_update' ); + $mech->submit_form_ok( { button => 'no_more_updates' } ); + is $mech->uri->path, '/admin/summary', "redirected now finished with report."; + + $mech->get_ok( '/report/' . $report->id ); + $mech->content_contains('In Bearbeitung'); + $mech->content_contains('Test Test'); +}; + +send_reports_for_zurich(); $email = $mech->get_email; like $email->header('Subject'), qr/Feedback/, 'subject looks okay'; like $email->header('To'), qr/division\@example.org/, 'to line looks correct'; @@ -143,7 +394,11 @@ is $report->state, 'planned', 'Report now in planned state'; $mech->log_out_ok; $user = $mech->log_in_ok( 'dm1@example.org') ; -$mech->get_ok( '/admin' ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/admin' ); +}; $mech->content_contains( 'report_edit/' . $report->id ); $mech->content_contains( DateTime->now->strftime("%d.%m.%Y") ); @@ -154,13 +409,17 @@ $extra->{email_confirmed} = 1; $report->extra ( { %$extra } ); $report->update; -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->content_lacks( 'Unbestätigt' ); # Confirmed email -$mech->submit_form_ok( { with_fields => { status_update => 'FINAL UPDATE' } } ); -$mech->form_with_fields( 'status_update' ); -$mech->submit_form_ok( { button => 'publish_response' } ); - -$mech->get_ok( '/report/' . $report->id ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->content_lacks( 'Unbestätigt' ); # Confirmed email + $mech->submit_form_ok( { with_fields => { status_update => 'FINAL UPDATE' } } ); + $mech->form_with_fields( 'status_update' ); + $mech->submit_form_ok( { button => 'publish_response' } ); + + $mech->get_ok( '/report/' . $report->id ); +}; $mech->content_contains('Beantwortet'); $mech->content_contains('Test Test'); $mech->content_contains('FINAL UPDATE'); @@ -179,17 +438,25 @@ $mech->clear_emails_ok; }); $report = $reports[0]; -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->submit_form_ok( { with_fields => { state => 'planned' } } ); -$mech->get_ok( '/report/' . $report->id ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'planned' } } ); + $mech->get_ok( '/report/' . $report->id ); +}; $mech->content_contains('In Bearbeitung'); $mech->content_contains('Second Test'); -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->content_contains( 'Unbestätigt' ); -$mech->submit_form_ok( { button => 'publish_response', with_fields => { status_update => 'FINAL UPDATE' } } ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->content_contains( 'Unbestätigt' ); + $mech->submit_form_ok( { button => 'publish_response', with_fields => { status_update => 'FINAL UPDATE' } } ); -$mech->get_ok( '/report/' . $report->id ); + $mech->get_ok( '/report/' . $report->id ); +}; $mech->content_contains('Beantwortet'); $mech->content_contains('Second Test'); $mech->content_contains('FINAL UPDATE'); @@ -205,13 +472,17 @@ $mech->email_count_is(0); }); $report = $reports[0]; -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->submit_form_ok( { with_fields => { body_external => 4 } } ); -$mech->get_ok( '/report/' . $report->id ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { body_external => 4 } } ); + $mech->get_ok( '/report/' . $report->id ); +}; $mech->content_contains('Beantwortet'); $mech->content_contains('Third Test'); $mech->content_contains('Wir haben Ihr Anliegen an External Body weitergeleitet'); -FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); +send_reports_for_zurich(); $email = $mech->get_email; like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay'; like $email->header('To'), qr/external_body\@example.org/, 'to line looks correct'; @@ -220,17 +491,21 @@ unlike $email->body, qr/test\@example.com/, 'body does not contain email address $mech->clear_emails_ok; # Test calling back, and third_personal boolean setting -$mech->get_ok( '/admin' ); -is $mech->uri->path, '/admin', "am logged in"; -$mech->content_contains( 'report_edit/' . $report->id ); -$mech->get_ok( '/admin/report_edit/' . $report->id ); -$mech->submit_form_ok( { with_fields => { state => 'unconfirmed' } } ); -$mech->submit_form_ok( { with_fields => { body_external => 4, third_personal => 1 } } ); -$mech->get_ok( '/report/' . $report->id ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], +}, sub { + $mech->get_ok( '/admin' ); + is $mech->uri->path, '/admin', "am logged in"; + $mech->content_contains( 'report_edit/' . $report->id ); + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'unconfirmed' } } ); + $mech->submit_form_ok( { with_fields => { body_external => 4, third_personal => 1 } } ); + $mech->get_ok( '/report/' . $report->id ); +}; $mech->content_contains('Beantwortet'); $mech->content_contains('Third Test'); $mech->content_contains('Wir haben Ihr Anliegen an External Body weitergeleitet'); -FixMyStreet::App->model('DB::Problem')->send_reports('zurich'); +send_reports_for_zurich(); $email = $mech->get_email; like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay'; like $email->header('To'), qr/external_body\@example.org/, 'to line looks correct'; @@ -239,21 +514,167 @@ like $email->body, qr/test\@example.com/, 'body does contain email address'; $mech->clear_emails_ok; $mech->log_out_ok; -# Test only superuser can edit bodies -$user = $mech->log_in_ok( 'dm1@example.org') ; -$mech->get( '/admin/body/' . $zurich->id ); -is $mech->res->code, 404, "only superuser should be able to edit bodies"; -$mech->log_out_ok; - -# Test only superuser can see "Add body" form -$user = $mech->log_in_ok( 'dm1@example.org') ; -$mech->get_ok( '/admin/bodies' ); -$mech->content_lacks( '<form method="post" action="bodies"' ); -$mech->log_out_ok; - -$mech->delete_problems_for_body( 2 ); -$mech->delete_user( 'dm1@example.org' ); -$mech->delete_user( 'sdm1@example.org' ); +subtest "only superuser can see stats" => sub { + $user = $mech->log_in_ok( 'super@example.org' ); + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get( '/admin/stats' ); + }; + is $mech->res->code, 200, "superuser should be able to see stats page"; + $mech->log_out_ok; + + $user = $mech->log_in_ok( 'dm1@example.org' ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get( '/admin/stats' ); + }; + is $mech->res->code, 404, "only superuser should be able to see stats page"; + $mech->log_out_ok; +}; + +subtest "only superuser can edit bodies" => sub { + $user = $mech->log_in_ok( 'dm1@example.org' ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get( '/admin/body/' . $zurich->id ); + }; + is $mech->res->code, 404, "only superuser should be able to edit bodies"; + $mech->log_out_ok; +}; + +subtest "only superuser can see 'Add body' form" => sub { + $user = $mech->log_in_ok( 'dm1@example.org' ); + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_TYPES => [ 'O08' ], + MAPIT_ID_WHITELIST => [ 423017 ], + }, sub { + $mech->get_ok( '/admin/bodies' ); + }; + $mech->content_lacks( '<form method="post" action="bodies"' ); + $mech->log_out_ok; +}; + +subtest "phone number is mandatory" => sub { + FixMyStreet::override_config { + MAPIT_TYPES => [ 'O08' ], + MAPIT_URL => 'http://global.mapit.mysociety.org/', + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $user = $mech->log_in_ok( 'dm1@example.org' ); + $mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' ); + $mech->submit_form( with_fields => { phone => "" } ); + $mech->content_contains( 'Diese Information wird benötigt' ); + $mech->log_out_ok; + }; +}; + +subtest "phone number is not mandatory for reports from mobile apps" => sub { + FixMyStreet::override_config { + MAPIT_TYPES => [ 'O08' ], + MAPIT_URL => 'http://global.mapit.mysociety.org/', + }, sub { + $mech->post_ok( '/report/new/mobile?lat=47.381817&lon=8.529156' , { + service => 'iPhone', + detail => 'Problem-Bericht', + lat => 47.381817, + lon => 8.529156, + email => 'user@example.org', + pc => '', + name => '', + }); + my $res = $mech->response; + ok $res->header('Content-Type') =~ m{^application/json\b}, 'response should be json'; + unlike $res->content, qr/Diese Information wird benötigt/, 'response should not contain phone error'; + # Clear out the mailq + $mech->clear_emails_ok; + }; +}; + +subtest "problems can't be assigned to deleted bodies" => sub { + $user = $mech->log_in_ok( 'dm1@example.org' ); + $user->from_body( 1 ); + $user->update; + $report->state( 'confirmed' ); + $report->update; + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_TYPES => [ 'O08' ], + MAPIT_ID_WHITELIST => [ 423017 ], + }, sub { + $mech->get_ok( '/admin/body/' . $external_body->id ); + $mech->submit_form_ok( { with_fields => { deleted => 1 } } ); + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->content_lacks( $external_body->name ); + }; + $user->from_body( 2 ); + $user->update; + $mech->log_out_ok; +}; + +subtest "hidden report email are only sent when requested" => sub { + $user = $mech->log_in_ok( 'dm1@example.org') ; + $extra = $report->extra; + $extra->{email_confirmed} = 1; + $report->extra ( { %$extra } ); + $report->update; + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'hidden', send_rejected_email => 1 } } ); + $mech->email_count_is(1); + $mech->clear_emails_ok; + $mech->get_ok( '/admin/report_edit/' . $report->id ); + $mech->submit_form_ok( { with_fields => { state => 'hidden', send_rejected_email => undef } } ); + $mech->email_count_is(0); + $mech->clear_emails_ok; + $mech->log_out_ok; + }; +}; + +subtest "test stats" => sub { + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'zurich' ], + }, sub { + $user = $mech->log_in_ok( 'super@example.org' ); + + $mech->get_ok( '/admin/stats' ); + is $mech->res->code, 200, "superuser should be able to see stats page"; + + $mech->content_contains('Innerhalb eines Arbeitstages moderiert: 2'); # now including hidden + $mech->content_contains('Innerhalb von fünf Arbeitstagen abgeschlossen: 3'); + # my @data = $mech->content =~ /(?:moderiert|abgeschlossen): \d+/g; + # diag Dumper(\@data); use Data::Dumper; + + my $export_count = get_export_rows_count($mech); + if (defined $export_count) { + is $export_count - $EXISTING_REPORT_COUNT, 3, 'Correct number of reports'; + $mech->content_contains(',fixed - council,'); + $mech->content_contains(',hidden,'); + } + + $mech->log_out_ok; + }; +}; + +subtest "test admin_log" => sub { + diag $report->id; + my @entries = FixMyStreet::App->model('DB::AdminLog')->search({ + object_type => 'problem', + object_id => $report->id, + }); + is scalar @entries, 4, 'State changes logged'; + is $entries[-1]->action, 'state change to hidden', 'State change logged as expected'; +}; + +cleanup(); ok $mech->host("www.fixmystreet.com"), "change host back"; @@ -3,15 +3,12 @@ use warnings; use Test::More; -use FixMyStreet; -use mySociety::Locale; -use Encode; -use Data::Dumper; use HTTP::Headers; use Sort::Key qw(keysort); use POSIX 'strcoll'; -local $Data::Dumper::Sortkeys = 1; -use utf8; + +use FixMyStreet; +use mySociety::Locale; # check that the mo files have been generated die "You need to run 'commonlib/bin/gettext-makemo --quiet FixMyStreet' " @@ -59,10 +56,6 @@ my @EN_sorted = qw( A Å Ø Z ); my @NO_sorted = qw( A Z Ø Å ); my @default_sorted = qw( A Z Å Ø ); -sub utf8_diag { - diag encode_utf8( Dumper(@_) ); -} - { mySociety::Locale::negotiate_language( # diff --git a/t/open311.t b/t/open311.t index 2dd9119c9..a029c7502 100644 --- a/t/open311.t +++ b/t/open311.t @@ -156,7 +156,7 @@ for my $test ( ], }, { - title => 'magic fms_extra parameters handled correctly', + desc => 'magic fms_extra parameters handled correctly', extra => [ { name => 'fms_extra_title', @@ -192,7 +192,7 @@ for my $test ( for my $test ( { - title => 'Check uses report name over user name', + desc => 'Check uses report name over user name', name => 'Nom de Report', first_name => 'Nom', last_name => 'de Report', diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index e700aef38..00c25a83e 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -133,7 +133,6 @@ $problem->insert; for my $test ( { desc => 'OPEN status for confirmed problem does not change state', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -145,7 +144,6 @@ for my $test ( }, { desc => 'bad state does not update states but does create update', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -158,7 +156,6 @@ for my $test ( { desc => 'investigating status changes problem status', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -170,7 +167,6 @@ for my $test ( }, { desc => 'in progress status changes problem status', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -182,7 +178,6 @@ for my $test ( }, { desc => 'action scheduled status changes problem status', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -194,7 +189,6 @@ for my $test ( }, { desc => 'not responsible status changes problem status', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -206,7 +200,6 @@ for my $test ( }, { desc => 'internal referral status changes problem status', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -218,7 +211,6 @@ for my $test ( }, { desc => 'duplicate status changes problem status', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -230,7 +222,6 @@ for my $test ( }, { desc => 'fixed status marks report as fixed - council', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -242,7 +233,6 @@ for my $test ( }, { desc => 'status of CLOSED marks report as fixed - council', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -254,7 +244,6 @@ for my $test ( }, { desc => 'status of OPEN re-opens fixed report', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'fixed - user', @@ -266,7 +255,6 @@ for my $test ( }, { desc => 'action sheduled re-opens fixed report as action scheduled', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'fixed - user', @@ -278,7 +266,6 @@ for my $test ( }, { desc => 'open status re-opens closed report', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'not responsible', @@ -290,7 +277,6 @@ for my $test ( }, { desc => 'fixed status leaves fixed - user report as fixed - user', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'fixed - user', @@ -302,7 +288,6 @@ for my $test ( }, { desc => 'closed status updates fixed report', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'fixed - user', @@ -314,7 +299,6 @@ for my $test ( }, { desc => 'no futher action status closes report', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'confirmed', @@ -326,7 +310,6 @@ for my $test ( }, { desc => 'fixed status sets closed report as fixed', - updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ), description => 'This is a note', external_id => 638344, start_state => 'unable to fix', @@ -336,10 +319,22 @@ for my $test ( problem_state => 'fixed - council', end_state => 'fixed - council', }, + { + desc => 'open status does not re-open hidden report', + description => 'This is a note', + external_id => 638344, + start_state => 'hidden', + comment_status => 'OPEN', + mark_fixed => 0, + mark_open => 0, + problem_state => 'confirmed', + end_state => 'hidden', + }, ) { subtest $test->{desc} => sub { my $local_requests_xml = $requests_xml; - $local_requests_xml =~ s/UPDATED_DATETIME/$test->{updated_datetime}/; + my $updated_datetime = sprintf( '<updated_datetime>%s</updated_datetime>', $dt ); + $local_requests_xml =~ s/UPDATED_DATETIME/$updated_datetime/; $local_requests_xml =~ s#<service_request_id>\d+</service_request_id>#<service_request_id>@{[$problem->external_id]}</service_request_id>#; $local_requests_xml =~ s#<service_request_id_ext>\d+</service_request_id_ext>#<service_request_id_ext>@{[$problem->id]}</service_request_id_ext>#; $local_requests_xml =~ s#<status>\w+</status>#<status>$test->{comment_status}</status># if $test->{comment_status}; @@ -632,10 +627,22 @@ foreach my $test ( { foreach my $test ( { desc => 'normally alerts are not suppressed', + num_alerts => 1, suppress_alerts => 0, }, { desc => 'alerts suppressed if suppress_alerts set', + num_alerts => 1, + suppress_alerts => 1, + }, + { + desc => 'alert suppression ok even if no alerts', + num_alerts => 0, + suppress_alerts => 1, + }, + { + desc => 'alert suppression ok even if 2x alerts', + num_alerts => 2, suppress_alerts => 1, } ) { @@ -657,12 +664,14 @@ foreach my $test ( { $problem->lastupdate( $dt->subtract( hours => 3 ) ); $problem->update; - my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( { - alert_type => 'new_updates', - parameter => $problem->id, - confirmed => 1, - user_id => $problem->user->id, - } ); + my @alerts = map { + my $alert = FixMyStreet::App->model('DB::Alert')->create( { + alert_type => 'new_updates', + parameter => $problem->id, + confirmed => 1, + user_id => $problem->user->id, + } ) + } (1..$test->{num_alerts}); $requests_xml =~ s/UPDATED_DATETIME/$dt/; @@ -679,19 +688,21 @@ foreach my $test ( { my $alerts_sent = FixMyStreet::App->model('DB::AlertSent')->search( { - alert_id => $alert->id, + alert_id => [ map $_->id, @alerts ], parameter => $problem->comments->first->id, } ); if ( $test->{suppress_alerts} ) { - ok $alerts_sent->count(), 'alerts suppressed'; + is $alerts_sent->count(), $test->{num_alerts}, 'alerts suppressed'; } else { is $alerts_sent->count(), 0, 'alerts not suppressed'; } $alerts_sent->delete; - $alert->delete; + for my $alert (@alerts) { + $alert->delete; + } } } |