diff options
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/about.t | 9 | ||||
-rw-r--r-- | t/app/controller/admin.t | 64 | ||||
-rw-r--r-- | t/app/controller/alert.t | 85 | ||||
-rw-r--r-- | t/app/controller/alert_new.t | 59 | ||||
-rw-r--r-- | t/app/controller/around.t | 24 | ||||
-rw-r--r-- | t/app/controller/dashboard.t | 1045 | ||||
-rw-r--r-- | t/app/controller/index.t | 6 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 18 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 36 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 236 | ||||
-rw-r--r-- | t/app/controller/report_interest_count.t | 7 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 542 | ||||
-rw-r--r-- | t/app/controller/report_new_open311.t | 34 | ||||
-rw-r--r-- | t/app/controller/reports.t | 56 | ||||
-rw-r--r-- | t/app/controller/rss.t | 30 |
15 files changed, 1252 insertions, 999 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'); |