aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller')
-rw-r--r--t/app/controller/about.t11
-rw-r--r--t/app/controller/admin.t178
-rw-r--r--t/app/controller/alert.t110
-rw-r--r--t/app/controller/alert_new.t230
-rw-r--r--t/app/controller/around.t28
-rw-r--r--t/app/controller/auth.t7
-rw-r--r--t/app/controller/contact.t111
-rw-r--r--t/app/controller/dashboard.t1036
-rw-r--r--t/app/controller/index.t10
-rw-r--r--t/app/controller/json.t8
-rw-r--r--t/app/controller/questionnaire.t39
-rw-r--r--t/app/controller/report_display.t166
-rw-r--r--t/app/controller/report_import.t241
-rw-r--r--t/app/controller/report_interest_count.t45
-rw-r--r--t/app/controller/report_new.t857
-rw-r--r--t/app/controller/report_new_open311.t55
-rw-r--r--t/app/controller/report_updates.t592
-rw-r--r--t/app/controller/reports.t77
-rw-r--r--t/app/controller/rss.t99
19 files changed, 2695 insertions, 1205 deletions
diff --git a/t/app/controller/about.t b/t/app/controller/about.t
index 4e49cdac9..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');
@@ -24,8 +23,8 @@ SKIP: {
# check that geting the page as EHA in welsh produces a different page
ok $mech->host("cy.reportemptyhomes.co.uk"), 'host to cy.reportemptyhomes';
$mech->get_ok('/about');
- $mech->content_like(qr{Amdanom ni ::\s+Adrodd am Eiddo Gwag});
+ $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 9ec15ec21..e369968b4 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -45,7 +45,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Report to Edit',
@@ -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',
@@ -84,7 +85,7 @@ subtest 'check summary counts' => sub {
my $problem_count = $problems->count;
$problems->update( { cobrand => '' } );
- FixMyStreet::App->model('DB::Problem')->search( { council => 2489 } )->update( { council => 1 } );
+ FixMyStreet::App->model('DB::Problem')->search( { bodies_str => 2489 } )->update( { bodies_str => 1 } );
my $q = FixMyStreet::App->model('DB::Questionnaire')->find_or_new( { problem => $report, });
$q->whensent( \'ms_current_timestamp()' );
@@ -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');
@@ -118,7 +122,7 @@ subtest 'check summary counts' => sub {
my ($num_alerts) = $mech->content =~ /(\d+) confirmed alerts/;
my ($num_qs) = $mech->content =~ /(\d+) questionnaires sent/;
- $report->council(2489);
+ $report->bodies_str(2489);
$report->cobrand('barnet');
$report->update;
@@ -131,36 +135,42 @@ subtest 'check summary counts' => sub {
$mech->content_contains( ($num_alerts+1) . " confirmed alerts" );
$mech->content_contains( ($num_qs+1) . " questionnaires sent" );
- $report->council(2504);
+ $report->bodies_str(2504);
$report->cobrand('');
$report->update;
$alert->cobrand('');
$alert->update;
- }
+ };
- FixMyStreet::App->model('DB::Problem')->search( { council => 1 } )->update( { council => 2489 } );
+ FixMyStreet::App->model('DB::Problem')->search( { bodies_str => 1 } )->update( { bodies_str => 2489 } );
ok $mech->host('fixmystreet.com');
};
-my $host = FixMyStreet->config('BASE_URL');
-$mech->get_ok('/admin/council_contacts/2650');
+my $body = $mech->create_body_ok(2650, 'Aberdeen City Council');
+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(
- { area_id => 2650, category => [ 'test category', 'test/category' ] }
+ { body_id => 2650, category => [ 'test category', 'test/category' ] }
);
$contact->delete_all;
my $history = FixMyStreet::App->model('DB::ContactsHistory')->search(
- { area_id => 2650, category => [ 'test category', 'test/category' ] }
+ { body_id => 2650, category => [ 'test category', 'test/category' ] }
);
$history->delete_all;
- $mech->get_ok('/admin/council_contacts/2650');
+ $mech->get_ok('/admin/body/2650');
$mech->submit_form_ok( { with_fields => {
category => 'test category',
@@ -190,12 +200,12 @@ subtest 'check contact creation' => sub {
note => 'test/note',
non_public => 'on',
} } );
- $mech->get_ok('/admin/council_edit/2650/test/category');
+ $mech->get_ok('/admin/body_edit/2650/test/category');
};
subtest 'check contact editing' => sub {
- $mech->get_ok('/admin/council_edit/2650/test%20category');
+ $mech->get_ok('/admin/body_edit/2650/test%20category');
$mech->submit_form_ok( { with_fields => {
email => 'test2@example.com',
@@ -216,31 +226,29 @@ subtest 'check contact editing' => sub {
$mech->content_contains( '<td>Non Public' );
- $mech->get_ok('/admin/council_edit/2650/test%20category');
+ $mech->get_ok('/admin/body_edit/2650/test%20category');
$mech->content_contains( '<td><strong>test2@example.com' );
};
subtest 'check contact updating' => sub {
- $mech->get_ok('/admin/council_edit/2650/test%20category');
+ $mech->get_ok('/admin/body_edit/2650/test%20category');
$mech->content_like(qr{test2\@example.com</strong>[^<]*</td>[^<]*<td>No}s);
- $mech->get_ok('/admin/council_contacts/2650');
+ $mech->get_ok('/admin/body/2650');
$mech->form_number( 1 );
$mech->tick( 'confirmed', 'test category' );
$mech->submit_form_ok({form_number => 1});
$mech->content_like(qr'test2@example.com</td>[^<]*<td>Yes's);
- $mech->get_ok('/admin/council_edit/2650/test%20category');
+ $mech->get_ok('/admin/body_edit/2650/test%20category');
$mech->content_like(qr{test2\@example.com[^<]*</td>[^<]*<td><strong>Yes}s);
};
-my $open311 =
- FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } );
-$open311->delete if $open311;
+$body->update({ send_method => undef });
subtest 'check open311 configuring' => sub {
- $mech->get_ok('/admin/council_contacts/2650/');
+ $mech->get_ok('/admin/body/2650');
$mech->content_lacks('Council contacts configured via Open311');
$mech->form_number(3);
@@ -258,11 +266,7 @@ subtest 'check open311 configuring' => sub {
$mech->content_contains('Council contacts configured via Open311');
$mech->content_contains('Configuration updated - contacts will be generated automatically later');
- $open311 =
- FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } );
-
- is $open311->count, 1, 'only one configuration';
- my $conf = $open311->first;
+ my $conf = FixMyStreet::App->model('DB::Body')->find( 2650 );
is $conf->endpoint, 'http://example.com/open311', 'endpoint configured';
is $conf->api_key, 'api key', 'api key configured';
is $conf->jurisdiction, 'mySociety', 'jurisdiction configures';
@@ -282,18 +286,14 @@ subtest 'check open311 configuring' => sub {
$mech->content_contains('Configuration updated');
- $open311 =
- FixMyStreet::App->model('DB::Open311Conf')->search( { area_id => 2650 } );
-
- is $open311->count, 1, 'only one configuration';
- $conf = $open311->first;
+ $conf = FixMyStreet::App->model('DB::Body')->find( 2650 );
is $conf->endpoint, 'http://example.org/open311', 'endpoint updated';
is $conf->api_key, 'new api key', 'api key updated';
is $conf->jurisdiction, 'open311', 'jurisdiction configures';
};
subtest 'check text output' => sub {
- $mech->get_ok('/admin/council_contacts/2650?text=1');
+ $mech->get_ok('/admin/body/2650?text=1');
is $mech->content_type, 'text/plain';
$mech->content_contains('test category');
};
@@ -563,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' );
}
@@ -845,6 +845,8 @@ for my $test (
};
}
+$mech->create_body_ok(2504, 'Westminster City Council');
+
for my $test (
{
desc => 'user is problem owner',
@@ -853,17 +855,17 @@ for my $test (
update_fixed => 0,
update_reopen => 0,
update_state => undef,
- user_council => undef,
+ user_body => undef,
content => 'user is problem owner',
},
{
- desc => 'user is council user',
+ desc => 'user is body user',
problem_user => $user,
update_user => $user2,
update_fixed => 0,
update_reopen => 0,
update_state => undef,
- user_council => 2504,
+ user_body => 2504,
content => 'user is from same council as problem - 2504',
},
{
@@ -873,7 +875,7 @@ for my $test (
update_fixed => 0,
update_reopen => 0,
update_state => 'planned',
- user_council => 2504,
+ user_body => 2504,
content => 'Update changed problem state to planned',
},
{
@@ -883,7 +885,7 @@ for my $test (
update_fixed => 1,
update_reopen => 0,
update_state => undef,
- user_council => undef,
+ user_body => undef,
content => 'Update marked problem as fixed',
},
{
@@ -893,7 +895,7 @@ for my $test (
update_fixed => 0,
update_reopen => 1,
update_state => undef,
- user_council => undef,
+ user_body => undef,
content => 'Update reopened problem',
},
) {
@@ -907,7 +909,7 @@ for my $test (
$update->mark_open( $test->{update_reopen} );
$update->update;
- $test->{update_user}->from_council( $test->{user_council} );
+ $test->{update_user}->from_body( $test->{user_body} );
$test->{update_user}->update;
$mech->get_ok('/admin/update_edit/' . $update->id );
@@ -1033,41 +1035,47 @@ subtest 'report search' => sub {
$update->user($report->user);
$update->update;
- $mech->get_ok('/admin/search_reports');
- $mech->get_ok('/admin/search_reports?search=' . $report->id );
+ $mech->get_ok('/admin/reports');
+ $mech->get_ok('/admin/reports?search=' . $report->id );
$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/search_reports?search=' . $report->user->email);
+ $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;
- $mech->get_ok('/admin/search_reports?search=' . $report->user->email);
+ $mech->get_ok('/admin/reports?search=' . $report->user->email);
$mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $u_id \s* </td>}xs );
$report->state('hidden');
$report->update;
- $mech->get_ok('/admin/search_reports?search=' . $report->user->email);
- $mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $r_id \s* </td>}xs );
+ $mech->get_ok('/admin/reports?search=' . $report->user->email);
+ $mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td[^>]*> \s* $r_id \s* </td>}xs );
$report->state('fixed - user');
$report->update;
- $mech->get_ok('/admin/search_reports?search=' . $report->user->email);
- $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id/">$r_id</a>} );
+ $mech->get_ok('/admin/reports?search=' . $report->user->email);
+ $mech->content_like( qr{href="http://[^/]*[^.]/report/$r_id"[^>]*>$r_id</a>} );
};
subtest 'search abuse' => sub {
- $mech->get_ok( '/admin/search_users?search=example' );
- $mech->content_like(qr/test4\@example.com.*\n.*\n.*Email in abuse table/);
+ $mech->get_ok( '/admin/users?search=example' );
+ $mech->content_like(qr{test4\@example.com.*</td>\s*<td>.*?</td>\s*<td>\(Email in abuse table});
};
subtest 'show flagged entries' => sub {
@@ -1077,27 +1085,29 @@ subtest 'show flagged entries' => sub {
$user->flagged( 1 );
$user->update;
- $mech->get_ok('/admin/list_flagged');
+ $mech->get_ok('/admin/flagged');
$mech->content_contains( $report->title );
$mech->content_contains( $user->email );
};
+$mech->create_body_ok(2509, 'Haringey Borough Council');
+
subtest 'user search' => sub {
- $mech->get_ok('/admin/search_users');
- $mech->get_ok('/admin/search_users?search=' . $user->name);
+ $mech->get_ok('/admin/users');
+ $mech->get_ok('/admin/users?search=' . $user->name);
$mech->content_contains( $user->name);
my $u_id = $user->id;
$mech->content_like( qr{user_edit/$u_id">Edit</a>} );
- $mech->get_ok('/admin/search_users?search=' . $user->email);
+ $mech->get_ok('/admin/users?search=' . $user->email);
$mech->content_like( qr{user_edit/$u_id">Edit</a>} );
- $user->from_council(2509);
+ $user->from_body(2509);
$user->update;
- $mech->get_ok('/admin/search_users?search=2509' );
- $mech->content_contains(2509);
+ $mech->get_ok('/admin/users?search=2509' );
+ $mech->content_contains('Haringey');
};
$log_entries = FixMyStreet::App->model('DB::AdminLog')->search(
@@ -1115,13 +1125,15 @@ is $log_entries->count, 0, 'no admin log entries';
$user->flagged( 0 );
$user->update;
+$mech->create_body_ok(2607, 'Southend-on-Sea Borough Council');
+
for my $test (
{
desc => 'edit user name',
fields => {
name => 'Test User',
email => 'test@example.com',
- council => 2509,
+ body => 2509,
flagged => undef,
},
changes => {
@@ -1135,7 +1147,7 @@ for my $test (
fields => {
name => 'Changed User',
email => 'test@example.com',
- council => 2509,
+ body => 2509,
flagged => undef,
},
changes => {
@@ -1145,15 +1157,15 @@ for my $test (
log_entries => [qw/edit edit/],
},
{
- desc => 'edit user council',
+ desc => 'edit user body',
fields => {
name => 'Changed User',
email => 'changed@example.com',
- council => 2509,
+ body => 2509,
flagged => undef,
},
changes => {
- council => 2607,
+ body => 2607,
},
log_count => 3,
log_entries => [qw/edit edit edit/],
@@ -1163,7 +1175,7 @@ for my $test (
fields => {
name => 'Changed User',
email => 'changed@example.com',
- council => 2607,
+ body => 2607,
flagged => undef,
},
changes => {
@@ -1177,7 +1189,7 @@ for my $test (
fields => {
name => 'Changed User',
email => 'changed@example.com',
- council => 2607,
+ body => 2607,
flagged => 'on',
},
changes => {
@@ -1207,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 3d95bef6d..6fab4d3e3 100644
--- a/t/app/controller/alert.t
+++ b/t/app/controller/alert.t
@@ -2,11 +2,8 @@ use strict;
use warnings;
use Test::More;
-
-use Catalyst::Test 'FixMyStreet::App';
-use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App';
-
-ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' );
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
# check that we can get the page
$mech->get_ok('/alert');
@@ -15,52 +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"');
-
-$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 &lsquo;EH99&nbsp;1SP&rsquo;');
-$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=');
-$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/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=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=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';
+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 &lsquo;EH99&nbsp;1SP&rsquo;');
+ $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=');
+ $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/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->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: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=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 c849b9485..594d4c7a6 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -3,6 +3,7 @@ use warnings;
use Test::More;
use FixMyStreet::TestMech;
+use FixMyStreet::App;
my $mech = FixMyStreet::TestMech->new;
@@ -206,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');
@@ -277,29 +283,8 @@ for my $test (
ok $alert, "Found the alert";
- my $email = $mech->get_email;
- ok $email, "got an email";
- like $email->body, qr/$test->{email_text}/i, "Correct email text";
-
- my ( $url, $url_token ) = $email->body =~ m{(http://\S+/A/)(\S+)};
- ok $url, "extracted confirm url '$url'";
-
- my $token = FixMyStreet::App->model('DB::Token')->find(
- {
- token => $url_token,
- scope => 'alert'
- }
- );
- ok $token, 'Token found in database';
- ok $alert->id == $token->data->{id}, 'token alertid matches alert id';
-
$mech->clear_emails_ok;
- $mech->get_ok("/A/$url_token");
- $mech->content_contains('error confirming');
-
- $alert->discard_changes;
-
ok !$alert->confirmed, 'alert not set to confirmed';
$abuse->delete;
@@ -307,43 +292,52 @@ for my $test (
};
}
+$mech->create_body_ok(2226, 'Gloucestershire County Council');
+$mech->create_body_ok(2326, 'Cheltenham Borough Council');
+
subtest "Test two-tier council alerts" => sub {
for my $alert (
{ feed => "local:51.896269:-2.093063", result => '/rss/l/51.896269,-2.093063' },
{ feed => "area:2326:Cheltenham", result => '/rss/area/Cheltenham' },
{ feed => "area:2326:4544:Cheltenham:Lansdown", result => '/rss/area/Cheltenham/Lansdown' },
{ feed => "area:2226:Gloucestershire", result => '/rss/area/Gloucestershire' },
- { feed => "area:2226:14949:Gloucestershire:Lansdown%2C_Park_and_Warden_Hill",
- result => '/rss/area/Gloucestershire/Lansdown%2C+Park+and+Warden+Hill'
+ { feed => "area:2226:14949:Gloucestershire:Lansdown_and_Park",
+ result => '/rss/area/Gloucestershire/Lansdown+and+Park'
},
{ feed => "council:2326:Cheltenham", result => '/rss/reports/Cheltenham' },
{ feed => "ward:2326:4544:Cheltenham:Lansdown", result => '/rss/reports/Cheltenham/Lansdown' },
{ feed => "council:2226:Gloucestershire", result => '/rss/reports/Gloucestershire' },
- { feed => "ward:2226:14949:Gloucestershire:Lansdown%2C_Park_and_Warden_Hill",
- result => '/rss/reports/Gloucestershire/Lansdown%2C+Park+and+Warden+Hill'
+ { feed => "ward:2226:14949:Gloucestershire:Lansdown_and_Park",
+ 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';
}
};
subtest "Test normal alert signups and that alerts are sent" => sub {
+ $mech->delete_user( 'reporter@example.com' );
+ $mech->delete_user( 'alerts@example.com' );
+
my $user1 = FixMyStreet::App->model('DB::User')
->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } );
ok $user1, "created test user";
- $user1->alerts->delete;
my $user2 = FixMyStreet::App->model('DB::User')
->find_or_create( { email => 'alerts@example.com', name => 'Alert User' } );
ok $user2, "created test user";
- $user2->alerts->delete;
for my $alert (
{
@@ -360,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;
@@ -379,10 +378,12 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
my $dt = DateTime->now()->add( days => 2);
+ my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
+
my $report_time = '2011-03-01 12:00:00';
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
postcode => 'EH1 1BB',
- council => '2651',
+ bodies_str => '2651',
areas => ',11808,135007,14419,134935,2651,20728,',
category => 'Street lighting',
title => 'Testing',
@@ -391,9 +392,9 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
name => $user1->name,
anonymous => 0,
state => 'fixed - user',
- confirmed => $dt,
- lastupdate => $dt,
- whensent => $dt->clone->add( minutes => 5 ),
+ confirmed => $dt_parser->format_datetime($dt),
+ lastupdate => $dt_parser->format_datetime($dt),
+ whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )),
lang => 'en-gb',
service => '',
cobrand => 'default',
@@ -439,14 +440,18 @@ 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;
my $count;
for (@emails) {
$count++ if $_->body =~ /The following updates have been left on this problem:/;
- $count++ if $_->body =~ /The following new problems have been reported to City of\s*Edinburgh Council:/;
+ $count++ if $_->body =~ /The following new problems have been reported to City of\s+Edinburgh\s+Council:/;
$count++ if $_->body =~ /The following nearby problems have been added:/;
$count++ if $_->body =~ /\s+-\s+Testing/;
}
@@ -509,15 +514,16 @@ for my $test (
},
) {
subtest $test->{desc} => sub {
+ $mech->delete_user( 'reporter@example.com' );
+ $mech->delete_user( 'alerts@example.com' );
+
my $user1 = FixMyStreet::App->model('DB::User')
->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } );
ok $user1, "created test user";
- $user1->alerts->delete;
my $user2 = FixMyStreet::App->model('DB::User')
->find_or_create( { email => 'alerts@example.com', name => 'Alert User' } );
ok $user2, "created test user";
- $user2->alerts->delete;
my $dt = DateTime->now->add( minutes => -30 );
my $r_dt = $dt->clone->add( minutes => 20 );
@@ -530,9 +536,11 @@ for my $test (
my $alert_user1 = FixMyStreet::App->model('DB::Alert')->create( $alert_params );
ok $alert_user1, "alert created";
+ my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
+
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
postcode => 'EH1 1BB',
- council => '2651',
+ bodies_str => '2651',
areas => ',11808,135007,14419,134935,2651,20728,',
category => 'Street lighting',
title => 'Alert test for non public reports',
@@ -541,9 +549,9 @@ for my $test (
name => $user2->name,
anonymous => 0,
state => 'confirmed',
- confirmed => $r_dt,
- lastupdate => $r_dt,
- whensent => $r_dt->clone->add( minutes => 5 ),
+ confirmed => $dt_parser->format_datetime($r_dt),
+ lastupdate => $dt_parser->format_datetime($r_dt),
+ whensent => $dt_parser->format_datetime($r_dt->clone->add( minutes => 5 )),
lang => 'en-gb',
service => '',
cobrand => 'default',
@@ -556,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';
@@ -571,15 +587,16 @@ for my $test (
}
subtest 'check new updates alerts for non public reports only go to report owner' => sub {
+ $mech->delete_user( 'reporter@example.com' );
+ $mech->delete_user( 'alerts@example.com' );
+
my $user1 = FixMyStreet::App->model('DB::User')
->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } );
ok $user1, "created test user";
- $user1->alerts->delete;
my $user2 = FixMyStreet::App->model('DB::User')
->find_or_create( { email => 'alerts@example.com', name => 'Alert User' } );
ok $user2, "created test user";
- $user2->alerts->delete;
my $user3 = FixMyStreet::App->model('DB::User')
->find_or_create( { email => 'updates@example.com', name => 'Update User' } );
@@ -588,9 +605,11 @@ subtest 'check new updates alerts for non public reports only go to report owner
my $dt = DateTime->now->add( minutes => -30 );
my $r_dt = $dt->clone->add( minutes => 20 );
+ my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
+
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
postcode => 'EH1 1BB',
- council => '2651',
+ bodies_str => '2651',
areas => ',11808,135007,14419,134935,2651,20728,',
category => 'Street lighting',
title => 'Alert test for non public reports',
@@ -599,9 +618,9 @@ subtest 'check new updates alerts for non public reports only go to report owner
name => $user2->name,
anonymous => 0,
state => 'confirmed',
- confirmed => $r_dt,
- lastupdate => $r_dt,
- whensent => $r_dt->clone->add( minutes => 5 ),
+ confirmed => $dt_parser->format_datetime($r_dt),
+ lastupdate => $dt_parser->format_datetime($r_dt),
+ whensent => $dt_parser->format_datetime($r_dt->clone->add( minutes => 5 )),
lang => 'en-gb',
service => '',
cobrand => 'default',
@@ -664,4 +683,95 @@ subtest 'check new updates alerts for non public reports only go to report owner
$mech->delete_user( $user3 );
};
+subtest 'check setting inlude dates in new updates cobrand option' => sub {
+ my $include_date_in_alert_override= Sub::Override->new(
+ "FixMyStreet::Cobrand::Default::include_time_in_update_alerts",
+ sub { return 1; }
+ );
+ $mech->delete_user( 'reporter@example.com' );
+ $mech->delete_user( 'alerts@example.com' );
+
+ my $user1 = FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } );
+ ok $user1, "created test user";
+
+ my $user2 = FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'alerts@example.com', name => 'Alert User' } );
+ ok $user2, "created test user";
+
+ my $user3 = FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'updates@example.com', name => 'Update User' } );
+ ok $user3, "created test user";
+
+ my $dt = DateTime->now->add( minutes => -30 );
+ my $r_dt = $dt->clone->add( minutes => 20 );
+
+ my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
+
+ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
+ postcode => 'EH1 1BB',
+ bodies_str => '2651',
+ areas => ',11808,135007,14419,134935,2651,20728,',
+ category => 'Street lighting',
+ title => 'Alert test for non public reports',
+ detail => 'Testing Detail',
+ used_map => 1,
+ name => $user2->name,
+ anonymous => 0,
+ state => 'confirmed',
+ confirmed => $dt_parser->format_datetime($r_dt),
+ lastupdate => $dt_parser->format_datetime($r_dt),
+ whensent => $dt_parser->format_datetime($r_dt->clone->add( minutes => 5 )),
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 1,
+ latitude => '55.951963',
+ longitude => '-3.189944',
+ user_id => $user2->id,
+ } );
+
+ my $update = FixMyStreet::App->model('DB::Comment')->create( {
+ problem_id => $report->id,
+ user_id => $user3->id,
+ name => 'Anonymous User',
+ mark_fixed => 'false',
+ text => 'This is some more update text',
+ state => 'confirmed',
+ confirmed => $r_dt->clone->add( minutes => 8 ),
+ anonymous => 't',
+ } );
+
+ my $alert_user1 = FixMyStreet::App->model('DB::Alert')->create( {
+ user => $user1,
+ alert_type => 'new_updates',
+ parameter => $report->id,
+ confirmed => 1,
+ whensubscribed => $dt,
+ } );
+ ok $alert_user1, "alert created";
+
+
+ $mech->clear_emails_ok;
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+ $mech->email_count_is(1);
+
+ # if we don't do this then we're applying the date inflation code and
+ # it's timezone munging to the DateTime object above and not the DateTime
+ # object that's inflated from the database value and these turn out to be
+ # different as the one above has a UTC timezone and not the floating one
+ # that those from the DB do.
+ $update->discard_changes();
+
+ my $date_in_alert = Utils::prettify_dt( $update->confirmed );
+ my $email = $mech->get_email;
+ like $email->body, qr/$date_in_alert/, 'alert contains date';
+
+ $mech->delete_user( $user1 );
+ $mech->delete_user( $user2 );
+ $mech->delete_user( $user3 );
+ $include_date_in_alert_override->restore();
+};
+
done_testing();
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index d973543ce..cbb110a1a 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -7,14 +7,18 @@ my $mech = FixMyStreet::TestMech->new;
subtest "check that if no query we get sent back to the homepage" => sub {
$mech->get_ok('/around');
- is $mech->uri->path, '/around', "still at '/around'";
+ is $mech->uri->path, '/', "redirected to '/'";
};
# x,y requests were generated by the old map code. We keep the behavior for
# 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}'";
@@ -90,11 +99,16 @@ subtest 'check non public reports are not displayed on around page' => sub {
longitude => -3.17492254484,
};
my @edinburgh_problems =
- $mech->create_problems_for_council( 5, 2651, 'Around page', $params );
+ $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/auth.t b/t/app/controller/auth.t
index 67466e959..3d52c0925 100644
--- a/t/app/controller/auth.t
+++ b/t/app/controller/auth.t
@@ -91,13 +91,8 @@ $mech->not_logged_in_ok;
is $mech->uri->path, '/my', "redirected to the 'my' section of site";
$mech->logged_in_ok;
- # logout and try to use the token again
+ # logout
$mech->log_out_ok;
- $mech->get_ok($link);
- is $mech->uri, $link, "not logged in";
- $mech->content_contains( 'Link too old or already used',
- 'token now invalid' );
- $mech->not_logged_in_ok;
}
# get a sign in email and change password
diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t
index 11e0d30cf..89a1db5b2 100644
--- a/t/app/controller/contact.t
+++ b/t/app/controller/contact.t
@@ -8,7 +8,7 @@ my $mech = FixMyStreet::TestMech->new;
$mech->get_ok('/contact');
$mech->title_like(qr/Contact Us/);
-$mech->content_contains("We'd love to hear what you think about this site");
+$mech->content_contains("It's often quickest to ");
my $problem_main;
@@ -282,6 +282,115 @@ for my $test (
};
}
+for my $test (
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => undef,
+ },
+ page_errors =>
+ [ 'There were problems with your report. Please see below.',
+ 'Please enter who your message is for',
+ ]
+ },
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => 'council',
+ },
+ page_errors =>
+ [ 'There were problems with your report. Please see below.',
+ 'You can only contact the team behind FixMyStreet using our contact form',
+ ]
+ },
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => 'update',
+ },
+ page_errors =>
+ [ 'There were problems with your report. Please see below.',
+ 'You can only contact the team behind FixMyStreet using our contact form',
+ ]
+ },
+ )
+{
+ subtest 'check submit page incorrect destination handling' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ }, sub {
+ $mech->host('www.fixmystreet.com');
+ $mech->get_ok( $test->{url} ? $test->{url} : '/contact' );
+ $mech->submit_form_ok( { with_fields => $test->{fields} } );
+ is_deeply $mech->page_errors, $test->{page_errors}, 'page errors';
+
+ # we santise this when we submit so need to remove it
+ delete $test->{fields}->{id}
+ if $test->{fields}->{id} and $test->{fields}->{id} eq 'invalid';
+ is_deeply $mech->visible_form_values, $test->{fields}, 'form values';
+
+ if ( $test->{fields}->{dest} and $test->{fields}->{dest} eq 'update' ) {
+ $mech->content_contains( 'www.writetothem.com', 'includes link to WTT if trying to update report' );
+ } elsif ( $test->{fields}->{dest} and $test->{fields}->{dest} eq 'council' ) {
+ $mech->content_lacks( 'www.writetothem.com', 'does not include link to WTT if trying to contact council' );
+ $mech->content_contains( 'should find contact details', 'mentions checking council website for contact details' );
+ }
+ }
+ };
+}
+
+for my $test (
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => 'help',
+ },
+ },
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => 'feedback',
+ },
+ },
+ {
+ fields => {
+ em => 'test@example.com',
+ name => 'A name',
+ subject => 'A subject',
+ message => 'A message',
+ dest => 'from_council',
+ },
+ },
+ )
+{
+ subtest 'check email sent correctly with dest field set to us' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ }, sub {
+ $mech->clear_emails_ok;
+ $mech->get_ok('/contact');
+ $mech->submit_form_ok( { with_fields => $test->{fields} } );
+ $mech->content_contains('Thanks for your feedback');
+ $mech->email_count_is(1);
+ }
+ };
+}
+
$problem_main->delete;
done_testing();
diff --git a/t/app/controller/dashboard.t b/t/app/controller/dashboard.t
index 47d10ff5c..4e62028b5 100644
--- a/t/app/controller/dashboard.t
+++ b/t/app/controller/dashboard.t
@@ -1,6 +1,7 @@
use strict;
use warnings;
use Test::More;
+use Test::MockTime ':all';
use FixMyStreet::TestMech;
use Web::Scraper;
@@ -12,6 +13,8 @@ my $test_pass = 'password';
my $test_council = 2651;
my $test_ward = 20723;
+$mech->create_body_ok($test_council, 'City of Edinburgh Council');
+
$mech->delete_user( $test_user );
my $user = FixMyStreet::App->model('DB::User')->create( {
email => $test_user,
@@ -22,549 +25,606 @@ 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' );
+# Dashboard tests assume we are not too early in year, to allow reporting
+# within same year, as a convenience.
+set_absolute_time('2014-03-01T12:00:00');
+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_council( $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( { area_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(
- {
- area_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=planned] > td", 'planned[]' => '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 planned today',
- confirm_dt => DateTime->now->subtract( days => 1 ),
- mark_dt => DateTime->now,
- state => 'planned',
- 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],
- planned => [1,1,1,1],
- marked => [3,3,3,3]
- }
- },
- {
- desc => 'marked as planned today, confirmed a week ago',
- confirm_dt => DateTime->now->subtract( days => 8 ),
- mark_dt => DateTime->now,
- state => 'planned',
- 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],
- planned => [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],
- planned => [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],
- planned => [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],
- planned => [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],
- planned => [2,2,2,2],
- closed => [1,1,1,1],
- marked => [5,5,5,5]
- }
- },
-) {
- 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 );
+ my $expected_cats = [ 'All', '-- Pick a category --', @cats ];
+ my $res = $categories->scrape( $mech->content );
+ is_deeply( $res->{cats}, $expected_cats, 'correct list of categories' );
- 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',
+ my $now = DateTime->now(time_zone => 'local');
+ foreach my $test (
+ {
+ desc => 'confirmed today with no state',
+ dt => $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 => $now->clone->subtract( days => 6, hours => 23 ),
+ counts => [1,2,2,2],
+ report_counts => [2, 0, 0],
},
- category => '',
- counts => {
- totals => [2,2,2,2],
+ {
+ desc => 'confirmed last 8 days with no state',
+ dt => $now->clone->subtract( days => 8 ),
+ counts => [1,2,3,3],
+ report_counts => [2, 1, 0],
},
- counts_after => {
- totals => [2,2,2,2],
+ {
+ desc => 'confirmed last 2 weeks with no state',
+ dt => $now->clone->subtract( weeks => 2 ),
+ counts => [1,2,4,4],
+ report_counts => [2, 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 => 'confirmed this year with no state',
+ dt => $now->clone->subtract( weeks => 7 ),
+ counts => [1,2,4,5],
+ report_counts => [2, 1, 1],
},
- counts_after => {
- totals => [1,1,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 => [1,0,0],
- },
- {
- desc => 'Limit display for category with no entries',
- category => 'Grafitti',
- 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 => [0,0,0,0],
+ {
+ 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 => [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 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]
+ }
},
- p2 => {
- state => 'fixed - council',
- conf_dt => DateTime->now()->subtract( weeks => 1 ),
- mark_dt => DateTime->now()->subtract( weeks => 1 ),
- category => 'Litter',
+ {
+ 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]
+ }
},
- 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',
+ 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],
},
- p2 => {
- state => 'confirmed',
- conf_dt => DateTime->now(),
- category => 'Litter',
+ {
+ desc => 'limit by state works',
+ state => 'fixed',
+ report_counts => [2,0,0],
+ report_counts_after => [1,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 => '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 => [4,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 {
+ make_problem( {
+ detail => "this report\nis split across\nseveral lines",
+ state => "confirmed",
+ conf_dt => DateTime->now(),
+ } );
+ $mech->get_ok('/dashboard?export=1');
+ open my $data_handle, '<', \$mech->content;
+ my $csv = Text::CSV->new( { binary => 1 } );
+ my @rows;
+ while ( my $row = $csv->getline( $data_handle ) ) {
+ push @rows, $row;
+ }
+ is scalar @rows, 7, '1 (header) + 6 (reports) = 7 lines';
};
-}
+};
+restore_time;
sub make_problem {
my $args = shift;
@@ -573,12 +633,12 @@ sub make_problem {
title => 'a problem',
name => 'a user',
anonymous => 1,
- detail => 'some detail',
+ detail => $args->{detail} || 'some detail',
state => $args->{state},
confirmed => $args->{conf_dt},
whensent => $args->{conf_dt},
lastupdate => $args->{mark_dt} || $args->{conf_dt},
- council => $test_council,
+ bodies_str => $test_council,
postcode => 'EH99 1SP',
latitude => '51',
longitude => '1',
@@ -632,10 +692,10 @@ sub check_report_counts {
sub delete_problems {
FixMyStreet::App->model('DB::Comment')
- ->search( { 'problem.council' => $test_council }, { join => 'problem' } )
+ ->search( { 'problem.bodies_str' => $test_council }, { join => 'problem' } )
->delete;
FixMyStreet::App->model('DB::Problem')
- ->search( { council => $test_council } )->delete();
+ ->search( { bodies_str => $test_council } )->delete();
}
done_testing;
diff --git a/t/app/controller/index.t b/t/app/controller/index.t
index 462b21064..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";
@@ -55,12 +59,12 @@ subtest "does pc, (x,y), (e,n) or (lat,lon) go to /around" => sub {
}
};
-$mech->delete_problems_for_council( 2651 );
+$mech->delete_problems_for_body( 2651 );
my $problem_rs = FixMyStreet::App->model('DB::Problem');
my $num = $problem_rs->count;
-my @edinburgh_problems = $mech->create_problems_for_council(5, 2651, 'Front page');
+my @edinburgh_problems = $mech->create_problems_for_body(5, 2651, 'Front page');
is scalar @edinburgh_problems, 5, 'correct number of edinburgh problems created';
$mech->get_ok('/report/' . $edinburgh_problems[2]->id);
diff --git a/t/app/controller/json.t b/t/app/controller/json.t
index 468fa5b31..405a84821 100644
--- a/t/app/controller/json.t
+++ b/t/app/controller/json.t
@@ -45,9 +45,11 @@ is_deeply #
# put an entry in the database for this test
my $user = $mech->create_user_ok('test@example.com');
+my $body = $mech->create_body_ok(2501, 'Wandsworth Borough Council');
+
my $problem_args = {
postcode => 'sw1a 1aa',
- council => '2501',
+ bodies_str => '2501',
areas => ',105164,11806,11827,2247,2501,34817,42011,66045,70786,8519,',
category => 'test category',
title => 'Test title',
@@ -86,7 +88,7 @@ is_deeply #
'category' => 'test category',
'confirmed' => '2000-01-01 12:01:00',
'lastupdate' => '2000-01-01 12:00:00',
- 'council' => 'Wandsworth Borough Council',
+ 'bodies_str' => 'Wandsworth Borough Council',
'detail' => 'Test detail',
'id' => $problem->id,
'name' => 'Test Name',
@@ -103,7 +105,7 @@ is_deeply #
'category' => 'test category',
'confirmed' => '2000-01-01 12:02:00',
'lastupdate' => '2000-01-01 12:00:00',
- 'council' => 'Wandsworth Borough Council',
+ 'bodies_str' => 'Wandsworth Borough Council',
'detail' => 'Test detail',
'id' => $anon_problem->id,
'name' => '',
diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t
index 3a6a3d6ad..6ee7ba58f 100644
--- a/t/app/controller/questionnaire.t
+++ b/t/app/controller/questionnaire.t
@@ -30,7 +30,7 @@ my $sent_time = $sent->ymd . ' ' . $sent->hms;
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'EH1 1BB',
- council => '2651',
+ bodies_str => '2651',
areas => ',11808,135007,14419,134935,2651,20728,',
category => 'Street lighting',
title => 'Testing',
@@ -329,6 +329,10 @@ for my $test (
fixed => 0
},
{
+ state => 'action scheduled',
+ fixed => 0
+ },
+ {
state => 'in progress',
fixed => 0
},
@@ -337,6 +341,18 @@ for my $test (
fixed => 0
},
{
+ state => 'duplicate',
+ fixed => 0
+ },
+ {
+ state => 'not responsible',
+ fixed => 0
+ },
+ {
+ state => 'unable to fix',
+ fixed => 0
+ },
+ {
state => 'closed',
fixed => 0
},
@@ -367,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';
@@ -386,7 +401,8 @@ SKIP: {
ok $email, "got an email";
$mech->clear_emails_ok;
- like $email->body, qr/fill in this short questionnaire/i, "got questionnaire email";
+ (my $body = $email->body) =~ s/\s+/ /g;
+ like $body, qr/fill in this short questionnaire/i, "got questionnaire email";
($token) = $email->body =~ m{http://.*?/Q/(\S+)};
ok $token, "extracted questionnaire token '$token'";
@@ -420,12 +436,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' );
@@ -439,7 +454,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 3bb0913f1..07e8caa9b 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -5,6 +5,7 @@ use Test::More;
use FixMyStreet::TestMech;
use Web::Scraper;
use Path::Class;
+use Test::LongString;
use DateTime;
my $mech = FixMyStreet::TestMech->new;
@@ -33,7 +34,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
@@ -94,6 +95,20 @@ subtest "change report to unconfirmed and check for 404 status" => sub {
ok $report->update( { state => 'confirmed' } ), 'confirm report again';
};
+
+subtest "Zurich unconfirmeds are 200" => sub {
+ 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( '&Uuml;berpr&uuml;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 {
ok $report->update( { state => 'hidden' } ), 'hide report';
ok $mech->get("/report/$report_id"), "get '/report/$report_id'";
@@ -169,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',
@@ -196,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'
},
)
{
@@ -283,6 +298,38 @@ for my $test (
fixed => 1
},
{
+ description => 'duplicate report',
+ date => DateTime->now,
+ state => 'duplicate',
+ banner_id => 'closed',
+ banner_text => 'closed',
+ fixed => 0
+ },
+ {
+ description => 'not responsible report',
+ date => DateTime->now,
+ state => 'not responsible',
+ banner_id => 'closed',
+ banner_text => 'closed',
+ fixed => 0
+ },
+ {
+ description => 'unable to fix report',
+ date => DateTime->now,
+ state => 'unable to fix',
+ banner_id => 'closed',
+ banner_text => 'closed',
+ fixed => 0
+ },
+ {
+ description => 'internal referral report',
+ date => DateTime->now,
+ state => 'internal referral',
+ banner_id => 'closed',
+ banner_text => 'closed',
+ fixed => 0
+ },
+ {
description => 'closed report',
date => DateTime->now,
state => 'closed',
@@ -299,6 +346,14 @@ for my $test (
fixed => 0
},
{
+ description => 'action scheduled report',
+ date => DateTime->now,
+ state => 'action scheduled',
+ banner_id => 'progress',
+ banner_text => 'progress',
+ fixed => 0
+ },
+ {
description => 'planned report',
date => DateTime->now,
state => 'planned',
@@ -307,7 +362,7 @@ for my $test (
fixed => 0
},
{
- description => 'in progressreport',
+ description => 'in progress report',
date => DateTime->now,
state => 'in progress',
banner_id => 'progress',
@@ -345,39 +400,112 @@ for my $test (
};
}
+subtest "Zurich banners are displayed correctly" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->host( 'zurich.example.com' );
+
+ for my $test (
+ {
+ description => 'new report',
+ state => 'unconfirmed',
+ banner_id => 'closed',
+ banner_text => 'Erfasst'
+ },
+ {
+ description => 'confirmed report',
+ state => 'confirmed',
+ banner_id => 'closed',
+ banner_text => 'Aufgenommen',
+ },
+ {
+ description => 'fixed report',
+ state => 'fixed - council',
+ banner_id => 'fixed',
+ banner_text => 'Beantwortet',
+ },
+ {
+ description => 'closed report',
+ state => 'closed',
+ banner_id => 'fixed',
+ banner_text => 'Beantwortet',
+ },
+ {
+ description => 'in progress report',
+ state => 'in progress',
+ banner_id => 'progress',
+ banner_text => 'In Bearbeitung',
+ },
+ {
+ description => 'planned report',
+ state => 'planned',
+ banner_id => 'progress',
+ banner_text => 'In Bearbeitung',
+ },
+ ) {
+ subtest "banner for $test->{description}" => sub {
+ $report->state( $test->{state} );
+ $report->update;
+
+ $mech->get_ok("/report/$report_id");
+ is $mech->uri->path, "/report/$report_id", "at /report/$report_id";
+ my $banner = $mech->extract_problem_banner;
+ if ( $banner->{text} ) {
+ $banner->{text} =~ s/^ //g;
+ $banner->{text} =~ s/ $//g;
+ }
+
+ is $banner->{id}, $test->{banner_id}, 'banner id';
+ if ($test->{banner_text}) {
+ like_string( $banner->{text}, qr/$test->{banner_text}/i, 'banner text is ' . $test->{banner_text} );
+ } else {
+ is $banner->{text}, $test->{banner_text}, 'banner text';
+ }
+
+ };
+ }
+
+ $mech->host( 'www.fixmystreet.com' );
+ };
+};
+
+$mech->create_body_ok(2504, 'Westminster City Council');
+$mech->create_body_ok(2505, 'Camden Borough Council');
+
for my $test (
{
desc => 'no state dropdown if user not from authority',
- from_council => 0,
+ from_body => undef,
no_state => 1,
- report_council => '2504',
+ report_body => '2504',
},
{
desc => 'state dropdown if user from authority',
- from_council => 2504,
+ from_body => 2504,
no_state => 0,
- report_council => '2504',
+ report_body => '2504',
},
{
- desc => 'no state dropdown if user not from same council as problem',
- from_council => 2505,
+ desc => 'no state dropdown if user not from same body as problem',
+ from_body => 2505,
no_state => 1,
- report_council => '2504',
+ report_body => '2504',
},
{
- desc => 'state dropdown if user from authority and problem sent to multiple councils',
- from_council => 2504,
+ desc => 'state dropdown if user from authority and problem sent to multiple bodies',
+ from_body => 2504,
no_state => 0,
- report_council => '2504,2506',
+ report_body => '2504,2506',
},
) {
subtest $test->{desc} => sub {
$mech->log_in_ok( $user->email );
- $user->from_council( $test->{from_council} );
+ $user->from_body( $test->{from_body} );
$user->update;
$report->discard_changes;
- $report->council( $test->{report_council} );
+ $report->bodies_str( $test->{report_body} );
$report->update;
$mech->get_ok("/report/$report_id");
@@ -391,7 +519,7 @@ for my $test (
}
$report->discard_changes;
-$report->council( 2504 );
+$report->bodies_str( 2504 );
$report->update;
# tidy up
diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t
index eb686b44e..a6ccc9604 100644
--- a/t/app/controller/report_import.t
+++ b/t/app/controller/report_import.t
@@ -3,6 +3,7 @@ use warnings;
use Test::More;
use FixMyStreet::TestMech;
+use FixMyStreet::App;
use Web::Scraper;
use Path::Class;
@@ -12,6 +13,10 @@ $mech->get_ok('/import');
my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify;
ok -e $sample_file, "sample file $sample_file exists";
+# disable info logs for this test run
+FixMyStreet::App->log->disable('info');
+END { FixMyStreet::App->log->enable('info'); }
+
# submit an empty report to import - check we get all errors
subtest "Test creating bad partial entries" => sub {
@@ -58,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" );
}
@@ -98,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";
@@ -107,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";
@@ -131,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');
@@ -157,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 =
@@ -216,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";
@@ -235,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 =
@@ -263,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 dd44a83d4..3de931c74 100644
--- a/t/app/controller/report_interest_count.t
+++ b/t/app/controller/report_interest_count.t
@@ -16,11 +16,6 @@ my $user =
->find_or_create( { email => 'test@example.com', name => 'Test User' } );
ok $user, "created test user";
-my $user2 =
- FixMyStreet::App->model('DB::User')
- ->find_or_create( { email => 'test2@example.com', name => 'Other User' } );
-ok $user2, "created test user";
-
my $dt = DateTime->new(
year => 2011,
month => 04,
@@ -33,7 +28,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
@@ -56,24 +51,26 @@ 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 (
{
- desc => 'if not from council then no supporter button',
- from_council => 0,
+ desc => 'if not from body then no supporter button',
+ from_body => undef,
support_string => 'No supporters',
},
{
- desc => 'from council user can increment supported count',
- from_council => 2504,
+ desc => 'from body user can increment supported count',
+ from_body => 2504,
support_string => 'No supporters',
updated_support => '1 supporter'
},
{
desc => 'correct grammar for more than one supporter',
- from_council => 2504,
+ from_body => 2504,
support_string => '1 supporter',
updated_support => '2 supporters'
},
@@ -81,17 +78,17 @@ SKIP: {
subtest $test->{desc} => sub {
ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
$mech->log_in_ok( $user->email );
- $user->from_council( $test->{from_council} );
+ $user->from_body( $test->{from_body} );
$user->update;
- $report->discard_changes;
- $report->council( $test->{report_council} );
- $report->update;
+ $report->update( {
+ bodies_str => $test->{report_council}
+ } );
$mech->get_ok("/report/$report_id");
$mech->content_contains( $test->{support_string} );
- if ( $test->{from_council} ) {
+ if ( $test->{from_body} ) {
$mech->content_contains('Add support');
$mech->submit_form_ok( { form_number => 1 } );
@@ -104,18 +101,16 @@ SKIP: {
};
}
- subtest 'check non council user cannot increment support count' => sub {
+ subtest 'check non body user cannot increment support count' => sub {
ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
- $report->discard_changes;
- $report->interest_count(1);
- ok $report->update(), 'updated interest count';
- $report->discard_changes;
+ ok $report->update({ interest_count => 1 }), 'updated interest count';
is $report->interest_count, 1, 'correct interest count';
$mech->get_ok("/report/$report_id");
$mech->content_contains( '1 supporter' );
+ # This doesn't send cookie, so is logged out
$mech->post_ok("/report/support", { id => $report_id } );
is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page';
@@ -135,7 +130,7 @@ subtest 'check support details not shown if not enabled in cobrand' => sub {
};
$report->discard_changes;
-$report->council( 2504 );
+$report->bodies_str( 2504 );
$report->update;
# tidy up
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index d20f15922..98b0175f8 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -5,9 +5,14 @@ use Test::More;
use utf8;
use FixMyStreet::TestMech;
+use FixMyStreet::App;
use Web::Scraper;
use Path::Class;
+# disable info logs for this test run
+FixMyStreet::App->log->disable('info');
+END { FixMyStreet::App->log->enable('info'); }
+
my $mech = FixMyStreet::TestMech->new;
$mech->get_ok('/report/new');
@@ -17,7 +22,7 @@ ok -e $sample_file, "sample file $sample_file exists";
subtest "test that bare requests to /report/new get redirected" => sub {
$mech->get_ok('/report/new');
- is $mech->uri->path, '/around', "went to /around";
+ is $mech->uri->path, '/', "went to /";
is_deeply { $mech->uri->query_form }, {}, "query empty";
$mech->get_ok('/report/new?pc=SW1A%201AA');
@@ -33,49 +38,62 @@ my %contact_params = (
whenedited => \'current_timestamp',
note => 'Created for test',
);
+
+for my $body (
+ { id => 2651, name => 'City of Edinburgh Council' },
+ { id => 2226, name => 'Gloucestershire County Council' },
+ { id => 2326, name => 'Cheltenham Borough Council' },
+ { id => 2482, name => 'Bromley Council' },
+ { id => 2240, name => 'Staffordshire County Council' },
+ { id => 2434, name => 'Lichfield District Council' },
+ { id => 2504, name => 'Westminster City Council' },
+) {
+ $mech->create_body_ok($body->{id}, $body->{name});
+}
+
# Let's make some contacts to send things to!
FixMyStreet::App->model('DB::Contact')->search( {
email => { 'like', '%example.com' },
} )->delete;
my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Street lighting',
email => 'highways@example.com',
} );
my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2226, # Gloucestershire
+ body_id => 2226, # Gloucestershire
category => 'Potholes',
email => 'potholes@example.com',
} );
my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2326, # Cheltenham
+ body_id => 2326, # Cheltenham
category => 'Trees',
email => 'trees@example.com',
} );
my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2482, # Bromley
+ body_id => 2482, # Bromley
category => 'Trees',
email => 'trees@example.com',
} );
my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Trees',
email => 'trees@example.com',
} );
my $contact6 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2434, # Lichfield
+ body_id => 2434, # Lichfield
category => 'Trees',
email => 'trees@example.com',
} );
my $contact7 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2240, # Lichfield
+ body_id => 2240, # Lichfield
category => 'Street lighting',
email => 'highways@example.com',
} );
@@ -92,6 +110,57 @@ ok $contact7, "created test contact 7";
foreach my $test (
{
msg => 'all fields empty',
+ pc => 'OX1 3DH',
+ fields => {
+ title => '',
+ detail => '',
+ photo => '',
+ name => '',
+ may_show_name => '1',
+ email => '',
+ phone => '',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+ },
+ changes => {},
+ errors => [
+ 'Please enter a subject',
+ 'Please enter some details',
+ # No category error, as no categories for Oxon at all, so is skipped
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ },
+ {
+ msg => 'all fields empty, bad category',
+ pc => 'GL50 2PR',
+ fields => {
+ title => '',
+ detail => '',
+ photo => '',
+ name => '',
+ may_show_name => '1',
+ email => '',
+ phone => '',
+ category => 'Something bad',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+ },
+ changes => {
+ category => '-- Pick a category --',
+ },
+ errors => [
+ 'Please enter a subject',
+ 'Please enter some details',
+ 'Please choose a category',
+ 'Please enter your email',
+ 'Please enter your name',
+ ],
+ },
+ {
+ msg => 'all fields empty except category',
pc => 'SW1A 1AA',
fields => {
title => '',
@@ -386,17 +455,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";
@@ -454,30 +528,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";
@@ -503,7 +582,7 @@ foreach my $test (
is $mech->get( '/report/' . $report->id )->code, 404, "report not found";
# Check the report has been assigned appropriately
- is $report->council, 2651;
+ is $report->bodies_str, 2651;
# receive token
my $email = $mech->get_email;
@@ -567,27 +646,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, [
@@ -614,42 +698,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;
@@ -659,7 +748,7 @@ subtest "test report creation for a user who is signing in as they report" => su
is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
# Check the report has been assigned appropriately
- is $report->council, 2651;
+ is $report->bodies_str, 2651;
# check that no emails have been sent
$mech->email_count_is(0);
@@ -708,49 +797,54 @@ 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;
ok $report, "Found the report";
# Check the report has been assigned appropriately
- is $report->council, $test->{council};
+ is $report->bodies_str, $test->{council};
# check that we got redirected to /report/
is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
@@ -802,27 +896,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;
@@ -858,8 +957,24 @@ subtest "test report creation for a category that is non public" => sub {
$contact2->category( "Pothol\xc3\xa9s" );
$contact2->update;
-$mech->get_ok( '/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';
+
+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
@@ -867,18 +982,22 @@ $mech->content_contains( "Pothol\xc3\xa9s" );
#### 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'";
@@ -892,7 +1011,7 @@ subtest "check that a lat/lon off coast leads to /around" => sub {
for my $test (
{
desc => 'user title not set if not bromley problem',
- host => 'http://www.fixmystreet.com',
+ host => 'www.fixmystreet.com',
postcode => 'EH99 1SP',
fms_extra_title => '',
extra => undef,
@@ -900,7 +1019,7 @@ for my $test (
},
{
desc => 'title shown for bromley problem on main site',
- host => 'http://www.fixmystreet.com',
+ host => 'www.fixmystreet.com',
postcode => 'BR1 3UH',
fms_extra_title => 'MR',
extra => [
@@ -915,7 +1034,7 @@ for my $test (
{
desc =>
'title, first and last name shown for bromley problem on cobrand',
- host => 'http://bromley.fixmystreet.com',
+ host => 'bromley.fixmystreet.com',
postcode => 'BR1 3UH',
first_name => 'Test',
last_name => 'User',
@@ -942,9 +1061,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} );
@@ -952,12 +1072,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} ) {
@@ -999,8 +1121,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";
@@ -1030,7 +1154,7 @@ for my $test (
subtest 'user title not reset if no user title in submission' => sub {
$mech->log_out_ok;
- $mech->host( 'http://fixmystreet.com' );
+ $mech->host( 'fixmystreet.com' );
my $user = $mech->log_in_ok( 'userwithtitle@example.com' );
@@ -1055,18 +1179,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;
@@ -1075,86 +1204,157 @@ 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');
-
- my $test_email = 'test-22@example.com';
- $mech->host( 'http://lichfielddc.fixmystreet.com/' );
- $mech->clear_emails_ok;
- $mech->log_out_ok;
-
- $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" );
- $mech->submit_form_ok(
+subtest "test Lichfield" => sub {
+ for my $test (
{
- button => 'submit_register',
- with_fields => {
- title => 'Test Report',
- detail => 'Test report details.',
- photo => '',
- name => 'Joe Bloggs',
- may_show_name => '1',
- email => $test_email,
- phone => '07903 123 456',
- category => 'Street lighting',
- }
+ desc => 'confirm link for cobrand council in two tier cobrand links to cobrand site',
+ category => 'Trees',
+ council => 2434,
+ national => 0,
+ button => 'submit_register',
},
- "submit good details"
- );
- is_deeply $mech->page_errors, [], "check there were no errors";
-
- # check that the user has been created/ not changed
- my $user =
- FixMyStreet::App->model('DB::User')->find( { email => $test_email } );
- ok $user, "user found";
-
- # find the report
- my $report = $user->problems->first;
- ok $report, "Found the report";
-
- # Check the report has been assigned appropriately
- is $report->council, 2240;
+ {
+ desc => 'confirm link for non cobrand council in two tier cobrand links to national site',
+ category => 'Street Lighting',
+ council => 2240,
+ national => 1,
+ button => 'submit_register',
+ },
+ {
+ desc => 'confirm redirect for cobrand council in two tier cobrand redirects to cobrand site',
+ category => 'Trees',
+ council => 2434,
+ national => 0,
+ redirect => 1,
+ },
+ {
+ desc => 'confirm redirect for non cobrand council in two tier cobrand redirect to national site',
+ category => 'Street Lighting',
+ council => 2240,
+ national => 1,
+ redirect => 1,
+ },
+ ) {
+ subtest $test->{ desc } => sub {
+ my $test_email = 'test-22@example.com';
+ $mech->host( 'lichfielddc.fixmystreet.com' );
+ $mech->clear_emails_ok;
+ $mech->log_out_ok;
+
+ my $user = $mech->log_in_ok($test_email) if $test->{redirect};
+
+ 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";
- # receive token
- my $email = $mech->get_email;
- ok $email, "got an email";
- like $email->body, qr/confirm the problem/i, "confirm the problem";
+ # check that the user has been created/ not changed
+ $user =
+ FixMyStreet::App->model('DB::User')->find( { email => $test_email } );
+ ok $user, "user found";
- my ($url) = $email->body =~ m{(http://\S+)};
- ok $url, "extracted confirm url '$url'";
+ # find the report
+ my $report = $user->problems->first;
+ ok $report, "Found the report";
- # confirm token
- $mech->get_ok($url);
- $report->discard_changes;
- is $report->state, 'confirmed', "Report is now confirmed";
+ # Check the report has been assigned appropriately
+ is $report->bodies_str, $test->{council};
- # Shouldn't be found, as it was a county problem
- is $mech->get( '/report/' . $report->id )->code, 404, "report not found";
+ if ( $test->{redirect} ) {
+ is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
+ my $base = 'www.fixmystreet.com';
+ $base = "lichfielddc.fixmystreet.com" unless $test->{national};
+ is $mech->uri->host, $base, 'redirected to correct site';
+ } else {
+ # receive token
+ my $email = $mech->get_email;
+ ok $email, "got an email";
+ like $email->body, qr/confirm the problem/i, "confirm the problem";
+
+ my ($url) = $email->body =~ m{(http://\S+)};
+ ok $url, "extracted confirm url '$url'";
+
+ # confirm token
+ 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
+ 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' );
+ }
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'lichfielddc', 'fixmystreet' ],
+ }, sub {
+ $mech->get_ok( '/report/' . $report->id );
+ };
+ }
- # But should be on the main site
- $mech->host( 'www.fixmystreet.com' );
- $mech->get_ok( '/report/' . $report->id );
- is $report->name, 'Joe Bloggs', 'name updated correctly';
+ $report->discard_changes;
+ is $report->state, 'confirmed', "Report is now confirmed";
- $mech->delete_user($user);
-}
+ is $report->name, 'Joe Bloggs', 'name updated correctly';
-SKIP: {
- skip( "Need 'seesomething' in ALLOWED_COBRANDS config", 100 )
- unless FixMyStreet::Cobrand->exists('seesomething');
+ $mech->delete_user($user);
+ };
+ }
+};
+subtest "test SeeSomething" => sub {
$mech->host('seesomething.fixmystreet.com');
$mech->clear_emails_ok;
$mech->log_out_ok;
my $cobrand = FixMyStreet::Cobrand::SeeSomething->new();
+ $mech->create_body_ok(2535, 'Sandwell Borough Council');
my $bus_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2535,
+ body_id => 2535,
category => 'Bus',
email => 'bus@example.com',
non_public => 1,
@@ -1214,22 +1414,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 =
@@ -1249,11 +1454,147 @@ SKIP: {
is $mech->uri->path, '/report/new', 'stays on report/new page';
$mech->content_contains( 'Your report has been sent', 'use report created template' );
}
+
+ $user->alerts->delete;
+ $user->problems->delete;
+ $user->delete;
};
}
$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 } );
+ };
+};
+
+subtest "extra google analytics code displayed on logged in problem creation" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ BASE_URL => 'http://www.fixmystreet.com',
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ }, sub {
+ # check that the user does not exist
+ my $test_email = 'test-2@example.com';
+
+ $mech->clear_emails_ok;
+ my $user = $mech->log_in_ok($test_email);
+
+ # setup the user.
+ ok $user->update(
+ {
+ name => 'Test User',
+ phone => '01234 567 890',
+ }
+ ),
+ "set users details";
+
+ # 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" );
+
+ $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 => 'Trees',
+ }
+ },
+ "submit good details"
+ );
+
+ # find the report
+ my $report = $user->problems->first;
+ ok $report, "Found the report";
+
+ # check that we got redirected to /report/
+ is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
+
+ $mech->content_contains( "extra = '?created_report", 'extra google code present' );
+
+ # cleanup
+ $mech->delete_user($user);
+ };
+};
+
+subtest "extra google analytics code displayed on email confirmation problem creation" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ BASE_URL => 'http://www.fixmystreet.com',
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ }, sub {
+ $mech->log_out_ok;
+ $mech->clear_emails_ok;
+
+ $mech->get_ok('/');
+ $mech->submit_form_ok( { with_fields => { pc => 'GL50 2PR' } },
+ "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');
+ my $submission_fields = {
+ title => "Test Report",
+ detail => 'Test report details.',
+ photo => '',
+ email => 'firstlast@example.com',
+ name => 'Test User',
+ may_show_name => '1',
+ phone => '07903 123 456',
+ category => 'Trees',
+ password_register => '',
+ };
+
+ $mech->submit_form_ok( { with_fields => $submission_fields },
+ "submit good details" );
+
+ my $email = $mech->get_email;
+ ok $email, "got an email";
+ like $email->body, qr/confirm the problem/i, "confirm the problem";
+
+ my ($url) = $email->body =~ m{(https?://\S+)};
+ ok $url, "extracted confirm url '$url'";
+
+ # confirm token in order to update the user details
+ $mech->get_ok($url);
+
+ $mech->content_contains( "extra = '?created_report", 'extra google code present' );
+
+ my $user =
+ FixMyStreet::App->model('DB::User')
+ ->find( { email => 'firstlast@example.com' } );
+
+ $user->problems->delete;
+ $user->alerts->delete;
+ $user->delete;
+ };
+};
$contact1->delete;
$contact2->delete;
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index 55c5a92e8..4745d92cd 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -3,16 +3,21 @@ use warnings;
use Test::More;
use FixMyStreet::TestMech;
+use FixMyStreet::App;
use Web::Scraper;
+# disable info logs for this test run
+FixMyStreet::App->log->disable('info');
+END { FixMyStreet::App->log->enable('info'); }
+
my $mech = FixMyStreet::TestMech->new;
-my $open311Conf = FixMyStreet::App->model('DB::Open311Conf')->find_or_create( {
- area_id => 2651,
- endpoint => 'http://example.com/open311',
- jurisdiction => 'mySociety',
- api_key => 'apikey',
-} );
+my $body = $mech->create_body_ok(2651, 'City of Edinburgh Council');
+$body->update({
+ endpoint => 'http://example.com/open311',
+ jurisdiction => 'mySociety',
+ api_key => 'apikey',
+});
my %contact_params = (
confirmed => 1,
@@ -24,7 +29,7 @@ my %contact_params = (
# Let's make some contacts to send things to!
my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Street lighting',
email => '100',
extra => [ { description => 'Lamppost number', code => 'number', required => 'True' },
@@ -35,7 +40,7 @@ my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
} );
my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
%contact_params,
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'Graffiti Removal',
email => '101',
} );
@@ -111,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";
@@ -147,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/report_updates.t b/t/app/controller/report_updates.t
index 82670d6cc..e84755650 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -35,7 +35,7 @@ my $dt = DateTime->new(
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'SW1A 1AA',
- council => '2504',
+ bodies_str => '2504',
areas => ',105255,11806,11828,2247,2504,',
category => 'Other',
title => 'Test 2',
@@ -407,9 +407,88 @@ for my $test (
$report->state('confirmed');
$report->update;
+for my $test (
+ {
+ desc => 'overriding email confirmation allows report confirmation with no email sent',
+ initial_values => {
+ name => '',
+ rznvy => '',
+ may_show_name => 1,
+ add_alert => 1,
+ photo => '',
+ update => '',
+ fixed => undef,
+ remember_me => undef,
+ password_register => '',
+ password_sign_in => '',
+ },
+ form_values => {
+ submit_update => 1,
+ rznvy => 'unregistered@example.com',
+ update => "update no email confirm",
+ add_alert => 1,
+ name => 'Unreg User',
+ may_show_name => undef,
+ },
+ changes => {
+ update => "Update no email confirm",
+ },
+ }
+) {
+ subtest $test->{desc} => sub {
+ my $send_confirmation_mail_override = Sub::Override->new(
+ "FixMyStreet::Cobrand::Default::never_confirm_updates",
+ sub { return 1; }
+ );
+ $mech->log_out_ok();
+ $mech->clear_emails_ok();
+
+ $mech->get_ok("/report/$report_id");
+
+ my $values = $mech->visible_form_values('updateForm');
+
+ is_deeply $values, $test->{initial_values}, 'initial form values';
+
+ $mech->submit_form_ok(
+ {
+ with_fields => $test->{form_values}
+ },
+ 'submit update'
+ );
+
+ $mech->content_contains('Test 2');
+ $mech->content_contains('Update no email confirm');
+
+ my $email = $mech->email_count_is(0);
+
+ my $update =
+ FixMyStreet::App->model('DB::Comment')->find( { problem_id => $report_id, text => 'Update no email confirm' } );
+ my $update_id = $update->id;
+
+ $mech->content_contains('name="update_' . $update_id . '"');
+
+ my $details = {
+ %{ $test->{form_values} },
+ %{ $test->{changes} }
+ };
+
+ ok $update, 'found update in database';
+ is $update->state, 'confirmed', 'update confirmed';
+ is $update->user->email, $details->{rznvy}, 'update email';
+ is $update->text, $details->{update}, 'update text';
+
+ my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{rznvy} } );
+
+ ok $unreg_user, 'found user';
+
+ $mech->delete_user( $unreg_user );
+ $send_confirmation_mail_override->restore();
+ };
+}
+
subtest 'check non authority user cannot change set state' => sub {
$mech->log_in_ok( $user->email );
- $user->from_council( 0 );
+ $user->from_body( undef );
$user->update;
$mech->get_ok("/report/$report_id");
@@ -434,10 +513,12 @@ subtest 'check non authority user cannot change set state' => sub {
is $report->state, 'confirmed', 'state unchanged';
};
+$mech->create_body_ok(2504, 'Westminster City Council');
+
for my $state ( qw/unconfirmed hidden partial/ ) {
subtest "check that update cannot set state to $state" => sub {
$mech->log_in_ok( $user->email );
- $user->from_council( 2504 );
+ $user->from_body( 2504 );
$user->update;
$mech->get_ok("/report/$report_id");
@@ -477,64 +558,104 @@ for my $test (
state => 'investigating',
},
{
- desc => 'from authority user marks report as planned',
+ desc => 'from authority user marks report as in progress',
fields => {
name => $user->name,
may_show_name => 1,
add_alert => undef,
photo => '',
- update => 'Set state to planned',
- state => 'planned',
+ update => 'Set state to in progress',
+ state => 'in progress',
},
- state => 'planned',
+ state => 'in progress',
},
{
- desc => 'from authority user marks report as in progress',
+ desc => 'from authority user marks report as fixed',
fields => {
name => $user->name,
may_show_name => 1,
add_alert => undef,
photo => '',
- update => 'Set state to in progress',
- state => 'in progress',
+ update => 'Set state to fixed',
+ state => 'fixed',
},
- state => 'in progress',
+ state => 'fixed - council',
},
{
- desc => 'from authority user marks report as closed',
+ desc => 'from authority user marks report as action scheduled',
fields => {
name => $user->name,
may_show_name => 1,
add_alert => undef,
photo => '',
- update => 'Set state to closed',
- state => 'closed',
+ update => 'Set state to action scheduled',
+ state => 'action scheduled',
},
- state => 'closed',
+ state => 'action scheduled',
},
{
- desc => 'from authority user marks report as fixed',
+ desc => 'from authority user marks report as unable to fix',
fields => {
name => $user->name,
may_show_name => 1,
add_alert => undef,
photo => '',
- update => 'Set state to fixed',
- state => 'fixed',
+ update => 'Set state to unable to fix',
+ state => 'unable to fix',
},
- state => 'fixed - council',
+ state => 'unable to fix',
},
{
- desc => 'from authority user marks report as confirmed',
+ desc => 'from authority user marks report as internal referral',
fields => {
name => $user->name,
may_show_name => 1,
add_alert => undef,
photo => '',
- update => 'Set state to confirmed',
- state => 'confirmed',
+ update => 'Set state to internal referral',
+ state => 'internal referral',
},
- state => 'confirmed',
+ state => 'internal referral',
+ meta => "an internal referral",
+ },
+ {
+ desc => 'from authority user marks report as not responsible',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => undef,
+ photo => '',
+ update => 'Set state to not responsible',
+ state => 'not responsible',
+ },
+ state => 'not responsible',
+ meta => "not the council's responsibility"
+ },
+ {
+ desc => 'from authority user marks report as duplicate',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => undef,
+ photo => '',
+ update => 'Set state to duplicate',
+ state => 'duplicate',
+ },
+ state => 'duplicate',
+ meta => 'a duplicate report',
+ },
+ {
+ desc => 'from authority user marks report as internal referral',
+ fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => undef,
+ photo => '',
+ update => 'Set state to internal referral',
+ state => 'internal referral',
+ },
+ state => 'internal referral',
+ meta => 'an internal referral',
},
{
desc => 'from authority user marks report sent to two councils as fixed',
@@ -547,18 +668,18 @@ for my $test (
state => 'fixed',
},
state => 'fixed - council',
- report_councils => '2504,2505',
+ report_bodies => '2504,2505',
},
) {
subtest $test->{desc} => sub {
$report->comments->delete;
- if ( $test->{ report_councils } ) {
- $report->council( $test->{ report_councils } );
+ if ( $test->{ report_bodies } ) {
+ $report->bodies_str( $test->{ report_bodies } );
$report->update;
}
$mech->log_in_ok( $user->email );
- $user->from_council( 2504 );
+ $user->from_body( 2504 );
$user->update;
$mech->get_ok("/report/$report_id");
@@ -577,11 +698,11 @@ for my $test (
is $update->problem_state, $test->{state}, 'problem state set';
my $update_meta = $mech->extract_update_metas;
- # setting it to confirmed shouldn't say anything
- if ( $test->{fields}->{state} ne 'confirmed' ) {
- like $update_meta->[0], qr/marked as $test->{fields}->{state}$/, 'update meta includes state change';
+ my $meta_state = $test->{meta} || $test->{fields}->{state};
+ if ( $test->{reopened} ) {
+ like $update_meta->[0], qr/reopened$/, 'update meta says reopened';
} else {
- like $update_meta->[0], qr/reopened$/, 'update meta includes state change';
+ like $update_meta->[0], qr/marked as $meta_state$/, 'update meta includes state change';
}
like $update_meta->[0], qr{Test User \(Westminster City Council\)}, 'update meta includes council name';
$mech->content_contains( 'Test User (<strong>Westminster City Council</strong>)', 'council name in bold');
@@ -598,7 +719,7 @@ subtest 'check meta correct for comments marked confirmed but not marked open' =
user => $user,
problem_id => $report->id,
text => 'update text',
- confirmed => DateTime->now,
+ confirmed => DateTime->now( time_zone => 'local' ),
problem_state => 'confirmed',
anonymous => 0,
mark_open => 0,
@@ -609,7 +730,7 @@ subtest 'check meta correct for comments marked confirmed but not marked open' =
$mech->get_ok( "/report/" . $report->id );
my $update_meta = $mech->extract_update_metas;
- like $update_meta->[0], qr/reopened$/,
+ unlike $update_meta->[0], qr/reopened$/,
'update meta does not say reopened';
$comment->update( { mark_open => 1, problem_state => undef } );
@@ -627,13 +748,164 @@ subtest 'check meta correct for comments marked confirmed but not marked open' =
unlike $update_meta->[0], qr/marked as open$/,
'update meta does not says marked as open';
unlike $update_meta->[0], qr/reopened$/, 'update meta does not say reopened';
- };
+};
+
+subtest "check first comment with no status change has no status in meta" => sub {
+ $mech->log_in_ok( $user->email );
+ $user->from_body( undef );
+ $user->update;
+
+ my $comment = $report->comments->first;
+ $comment->update( { mark_fixed => 0, problem_state => 'confirmed' } );
+
+ $mech->get_ok("/report/$report_id");
+
+ my $update_meta = $mech->extract_update_metas;
+ unlike $update_meta->[0], qr/marked as|reopened/, 'update meta does not include state change';
+};
+
+subtest "check comment with no status change has not status in meta" => sub {
+ $mech->log_in_ok( $user->email );
+ $user->from_body( undef );
+ $user->update;
+
+ my $comment = $report->comments->first;
+ $comment->update( { mark_fixed => 1, problem_state => 'fixed - council' } );
+
+ $mech->get_ok("/report/$report_id");
-$user->from_council(0);
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => undef,
+ photo => '',
+ update => 'Comment that does not change state',
+ },
+ },
+ 'submit update'
+ );
+
+ $report->discard_changes;
+ my @updates = $report->comments->all;
+ is scalar @updates, 2, 'correct number of updates';
+
+ my $update = pop @updates;
+
+ is $report->state, 'fixed - council', 'correct report state';
+ is $update->problem_state, 'fixed - council', 'correct update state';
+ my $update_meta = $mech->extract_update_metas;
+ unlike $update_meta->[1], qr/marked as/, 'update meta does not include state change';
+
+ $user->from_body( 2504 );
+ $user->update;
+
+ $mech->get_ok("/report/$report_id");
+
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ name => $user->name,
+ may_show_name => 1,
+ add_alert => undef,
+ photo => '',
+ update => 'Comment that sets state to investigating',
+ state => 'investigating',
+ },
+ },
+ 'submit update'
+ );
+
+ $report->discard_changes;
+ @updates = $report->comments->search(undef, { order_by => 'created' })->all;;
+
+ is scalar @updates, 3, 'correct number of updates';
+
+ $update = pop @updates;
+
+ is $report->state, 'investigating', 'correct report state';
+ is $update->problem_state, 'investigating', 'correct update state';
+ $update_meta = $mech->extract_update_metas;
+ like $update_meta->[0], qr/marked as fixed/, 'first update meta says fixed';
+ unlike $update_meta->[1], qr/marked as/, 'second update meta does not include state change';
+ like $update_meta->[2], qr/marked as investigating/, 'third update meta says investigating';
+
+ my $dt = DateTime->now( time_zone => "local" )->add( seconds => 1 );
+ $comment = FixMyStreet::App->model('DB::Comment')->find_or_create(
+ {
+ problem_id => $report_id,
+ user_id => $user->id,
+ name => 'Other User',
+ mark_fixed => 'false',
+ text => 'This is some update text',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ anonymous => 'f',
+ }
+ );
+
+ $mech->get_ok("/report/$report_id");
+
+ $report->discard_changes;
+ @updates = $report->comments->search(undef, { order_by => 'created' })->all;;
+ is scalar @updates, 4, 'correct number of updates';
+
+ $update = pop @updates;
+
+ is $report->state, 'investigating', 'correct report state';
+ is $update->problem_state, undef, 'no update state';
+ $update_meta = $mech->extract_update_metas;
+ like $update_meta->[0], qr/marked as fixed/, 'first update meta says fixed';
+ unlike $update_meta->[1], qr/marked as/, 'second update meta does not include state change';
+ like $update_meta->[2], qr/marked as investigating/, 'third update meta says investigating';
+ unlike $update_meta->[3], qr/marked as/, 'fourth update meta has no state change';
+};
+
+subtest 'check meta correct for second comment marking as reopened' => sub {
+ $report->comments->delete;
+ my $comment = FixMyStreet::App->model('DB::Comment')->create(
+ {
+ user => $user,
+ problem_id => $report->id,
+ text => 'update text',
+ confirmed => DateTime->now( time_zone => 'local'),
+ problem_state => 'fixed - user',
+ anonymous => 0,
+ mark_open => 0,
+ mark_fixed => 1,
+ state => 'confirmed',
+ }
+ );
+
+ $mech->get_ok( "/report/" . $report->id );
+ my $update_meta = $mech->extract_update_metas;
+ like $update_meta->[0], qr/fixed$/, 'update meta says fixed';
+
+ $comment = FixMyStreet::App->model('DB::Comment')->create(
+ {
+ user => $user,
+ problem_id => $report->id,
+ text => 'update text',
+ confirmed => DateTime->now( time_zone => 'local' ) + DateTime::Duration->new( minutes => 1 ),
+ problem_state => 'confirmed',
+ anonymous => 0,
+ mark_open => 0,
+ mark_fixed => 0,
+ state => 'confirmed',
+ }
+ );
+
+ $mech->get_ok( "/report/" . $report->id );
+ $update_meta = $mech->extract_update_metas;
+ like $update_meta->[1], qr/reopened$/, 'update meta says reopened';
+};
+
+$user->from_body(undef);
$user->update;
$report->state('confirmed');
-$report->council('2504');
+$report->bodies_str('2504');
$report->update;
for my $test (
@@ -1286,6 +1558,254 @@ for my $test (
};
}
+for my $test (
+ {
+ desc => 'update confirmed without marking as fixed leaves state unchanged',
+ initial_state => 'confirmed',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 0,
+ },
+ end_state => 'confirmed',
+ },
+ {
+ desc => 'update investigating without marking as fixed leaves state unchanged',
+ initial_state => 'investigating',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 0,
+ },
+ end_state => 'investigating',
+ },
+ {
+ desc => 'update in progress without marking as fixed leaves state unchanged',
+ initial_state => 'in progress',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 0,
+ },
+ end_state => 'in progress',
+ },
+ {
+ desc => 'update action scheduled without marking as fixed leaves state unchanged',
+ initial_state => 'action scheduled',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 0,
+ },
+ end_state => 'action scheduled',
+ },
+ {
+ desc => 'update fixed without marking as open leaves state unchanged',
+ initial_state => 'fixed',
+ expected_form_fields => {
+ reopen => undef,
+ },
+ submitted_form_fields => {
+ reopen => 0,
+ },
+ end_state => 'fixed',
+ },
+ {
+ desc => 'update unable to fix without marking as fixed leaves state unchanged',
+ initial_state => 'unable to fix',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 0,
+ },
+ end_state => 'unable to fix',
+ },
+ {
+ desc => 'update internal referral without marking as fixed leaves state unchanged',
+ initial_state => 'internal referral',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 0,
+ },
+ end_state => 'internal referral',
+ },
+ {
+ desc => 'update not responsible without marking as fixed leaves state unchanged',
+ initial_state => 'not responsible',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 0,
+ },
+ end_state => 'not responsible',
+ },
+ {
+ desc => 'update duplicate without marking as fixed leaves state unchanged',
+ initial_state => 'duplicate',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 0,
+ },
+ end_state => 'duplicate',
+ },
+ {
+ desc => 'can mark confirmed as fixed',
+ initial_state => 'confirmed',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 1,
+ },
+ end_state => 'fixed - user',
+ },
+ {
+ desc => 'can mark investigating as fixed',
+ initial_state => 'investigating',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 1,
+ },
+ end_state => 'fixed - user',
+ },
+ {
+ desc => 'can mark in progress as fixed',
+ initial_state => 'in progress',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 1,
+ },
+ end_state => 'fixed - user',
+ },
+ {
+ desc => 'can mark action scheduled as fixed',
+ initial_state => 'action scheduled',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 1,
+ },
+ end_state => 'fixed - user',
+ },
+ {
+ desc => 'cannot mark fixed as fixed, can mark as not fixed',
+ initial_state => 'fixed',
+ expected_form_fields => {
+ reopen => undef,
+ },
+ submitted_form_fields => {
+ reopen => 1,
+ },
+ end_state => 'confirmed',
+ },
+ {
+ desc => 'can mark unable to fix as fixed, cannot mark not closed',
+ initial_state => 'unable to fix',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 1,
+ },
+ end_state => 'fixed - user',
+ },
+ {
+ desc => 'can mark internal referral as fixed, cannot mark not closed',
+ initial_state => 'internal referral',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 1,
+ },
+ end_state => 'fixed - user',
+ },
+ {
+ desc => 'can mark not responsible as fixed, cannot mark not closed',
+ initial_state => 'not responsible',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 1,
+ },
+ end_state => 'fixed - user',
+ },
+ {
+ desc => 'can mark duplicate as fixed, cannot mark not closed',
+ initial_state => 'duplicate',
+ expected_form_fields => {
+ fixed => undef,
+ },
+ submitted_form_fields => {
+ fixed => 1,
+ },
+ end_state => 'fixed - user',
+ },
+) {
+ subtest $test->{desc} => sub {
+ $mech->log_in_ok( $report->user->email );
+
+ my %standard_fields = (
+ name => $report->user->name,
+ update => 'update text',
+ photo => '',
+ may_show_name => 1,
+ add_alert => 1,
+ );
+
+ my %expected_fields = (
+ %standard_fields,
+ %{ $test->{expected_form_fields} },
+ update => '',
+ );
+
+ my %submitted_fields = (
+ %standard_fields,
+ %{ $test->{submitted_form_fields} },
+ );
+
+ # clear out comments for this problem to make
+ # checking details easier later
+ ok( $_->delete, 'deleted comment ' . $_->id ) for $report->comments;
+
+ $report->discard_changes;
+ $report->state($test->{initial_state});
+ $report->update;
+
+ $mech->get_ok("/report/$report_id");
+
+ my $values = $mech->visible_form_values('updateForm');
+ is_deeply $values, \%expected_fields, 'correct form fields present';
+
+ if ( $test->{submitted_form_fields} ) {
+ $mech->submit_form_ok( {
+ with_fields => \%submitted_fields
+ },
+ 'submit update'
+ );
+
+ $report->discard_changes;
+ is $report->state, $test->{end_state}, 'update sets correct report state';
+ }
+ };
+}
+
subtest 'check have to be logged in for creator fixed questionnaire' => sub {
$mech->log_out_ok();
diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t
index a4dab6597..42e69fd03 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -8,15 +8,25 @@ use DateTime;
ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
-$mech->delete_problems_for_council( 2504 );
-$mech->delete_problems_for_council( 2651 );
+$mech->create_body_ok(2514, 'Birmingham City Council');
+$mech->create_body_ok(2651, 'City of Edinburgh Council');
+$mech->create_body_ok(2504, 'Westminster City Council');
-my @edinburgh_problems = $mech->create_problems_for_council(3, 2651, 'All reports');
-my @westminster_problems = $mech->create_problems_for_council(5, 2504, 'All reports');
+$mech->delete_problems_for_body( 2504 );
+$mech->delete_problems_for_body( 2651 );
+
+my @edinburgh_problems = $mech->create_problems_for_body(3, 2651, 'All reports');
+my @westminster_problems = $mech->create_problems_for_body(5, 2504, 'All reports');
is scalar @westminster_problems, 5, 'correct number of westminster problems created';
is scalar @edinburgh_problems, 3, 'correct number of edinburgh problems created';
+$edinburgh_problems[1]->update( {
+ state => 'in progress',
+ confirmed => DateTime->now()->subtract( weeks => 6 ),
+ lastupdate => DateTime->now()->subtract( weeks => 5 ),
+} );
+
# Run the cron script that makes the data for /reports so we don't get an error.
system( "bin/cron-wrapper update-all-reports" );
@@ -27,12 +37,18 @@ $mech->content_contains('Birmingham');
my $stats = $mech->extract_report_stats;
-is $stats->{'City of Edinburgh Council'}->[1], 3, 'correct number of reports for Edinburgh';
+is $stats->{'City of Edinburgh Council'}->[1], 2, 'correct number of new reports for Edinburgh';
+is $stats->{'City of Edinburgh Council'}->[2], 1, 'correct number of older reports for Edinburgh';
+
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');
@@ -43,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';
@@ -53,23 +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');
- 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 77e2c7ee1..bafa1ddc0 100644
--- a/t/app/controller/rss.t
+++ b/t/app/controller/rss.t
@@ -3,6 +3,7 @@ use warnings;
use Test::More;
use FixMyStreet::TestMech;
+use FixMyStreet::App;
my $mech = FixMyStreet::TestMech->new;
@@ -13,11 +14,13 @@ my $dt = DateTime->new(
);
my $user1 = FixMyStreet::App->model('DB::User')
- ->find_or_create( { email => 'reporter@example.com', name => 'Reporter User' } );
+ ->find_or_create( { email => 'reporter-rss@example.com', name => 'Reporter User' } );
+
+my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
postcode => 'eh1 1BB',
- council => '2651',
+ bodies_str => '2651',
areas => ',11808,135007,14419,134935,2651,20728,',
category => 'Street lighting',
title => 'Testing',
@@ -26,9 +29,9 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
name => $user1->name,
anonymous => 0,
state => 'confirmed',
- confirmed => $dt,
- lastupdate => $dt,
- whensent => $dt->clone->add( minutes => 5 ),
+ confirmed => $dt_parser->format_datetime($dt),
+ lastupdate => $dt_parser->format_datetime($dt),
+ whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )),
lang => 'en-gb',
service => '',
cobrand => 'default',
@@ -39,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' );
@@ -108,11 +116,84 @@ $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' );
$report->delete();
-$user1->delete();
+
+my $now = DateTime->now();
+my $report_to_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'WS13 6YY',
+ bodies_str => '2434',
+ areas => ',2434,2240,',
+ category => 'Other',
+ title => 'council report',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'closed',
+ confirmed => $now->ymd . ' ' . $now->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '52.727588',
+ longitude => '-1.731322',
+ user_id => $user1->id,
+ }
+);
+
+my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
+ {
+ postcode => 'WS13 6YY',
+ bodies_str => '2240',
+ areas => ',2434,2240,',
+ category => 'Other',
+ title => 'county report',
+ detail => 'Test 2 Detail',
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'closed',
+ confirmed => $now->ymd . ' ' . $now->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '52.727588',
+ longitude => '-1.731322',
+ user_id => $user1->id,
+ }
+);
+
+subtest "check RSS feeds on cobrand have correct URLs for non-cobrand reports" => sub {
+ $mech->host('lichfielddc.fixmystreet.com');
+ my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_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');
+};
+
+$mech->delete_user( $user1 );
done_testing();