aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-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
-rw-r--r--t/app/helpers/send_email.t19
-rw-r--r--t/app/helpers/send_email_sample.txt29
-rw-r--r--t/app/model/alert_type.t61
-rw-r--r--t/app/model/comment.t4
-rw-r--r--t/app/model/problem.t310
-rw-r--r--t/app/model/questionnaire.t18
-rw-r--r--t/app/model/rabx_column.t23
-rw-r--r--t/app/model/token.t46
-rw-r--r--t/app/sendreport/email.t14
-rw-r--r--t/app/uri_for.t75
-rw-r--r--t/cobrand/bromley.t42
-rw-r--r--t/cobrand/closest.t6
-rw-r--r--t/cobrand/councils.t10
-rw-r--r--t/cobrand/fixmybarangay.t140
-rw-r--r--t/cobrand/get_body_sender.t43
-rw-r--r--t/cobrand/get_council_sender.t30
-rw-r--r--t/cobrand/hart.t16
-rw-r--r--t/cobrand/loading.t103
-rw-r--r--t/cobrand/zurich.t685
-rw-r--r--t/i18n.t13
-rw-r--r--t/map/tilma/original.t26
-rw-r--r--t/open311.t160
-rw-r--r--t/open311/getservicerequestupdates.t237
-rw-r--r--t/open311/getupdates.t85
-rw-r--r--t/open311/populate-service-list.t134
44 files changed, 4611 insertions, 1618 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();
diff --git a/t/app/helpers/send_email.t b/t/app/helpers/send_email.t
index 8c043f701..14c7d363b 100644
--- a/t/app/helpers/send_email.t
+++ b/t/app/helpers/send_email.t
@@ -9,23 +9,14 @@ BEGIN {
FixMyStreet->test_mode(1);
}
-use Test::More tests => 6;
+use Test::More tests => 5;
+
+use Catalyst::Test 'FixMyStreet::App';
use Email::Send::Test;
use Path::Class;
-use_ok 'FixMyStreet::App';
-my $c = FixMyStreet::App->new(
- {
- request => Catalyst::Request->new(
- {
- base => URI->new('http://fixmystreet.com/'),
- uri => URI->new('http://fixmystreet.com/')
- }
- ),
- }
-);
-$c->setup_request();
+my $c = ctx_request("/");
# set some values in the stash
$c->stash->{foo} = 'bar';
@@ -49,7 +40,7 @@ ok $email_as_string =~ s{\s+Message-ID:\s+\S.*?$}{}xms, "Found and stripped out
my $expected_email_content = file(__FILE__)->dir->file('send_email_sample.txt')->slurp;
my $name = FixMyStreet->config('CONTACT_NAME');
$name = "\"$name\"" if $name =~ / /;
-my $sender = $name . ' <' . FixMyStreet->config('CONTACT_EMAIL') . '>';
+my $sender = $name . ' <' . FixMyStreet->config('DO_NOT_REPLY_EMAIL') . '>';
$expected_email_content =~ s{CONTACT_EMAIL}{$sender};
is $email_as_string,
diff --git a/t/app/helpers/send_email_sample.txt b/t/app/helpers/send_email_sample.txt
index 2fe5272cb..1ccce6a23 100644
--- a/t/app/helpers/send_email_sample.txt
+++ b/t/app/helpers/send_email_sample.txt
@@ -5,25 +5,24 @@ To: test@recipient.com
Content-Transfer-Encoding: quoted-printable
From: CONTACT_EMAIL
- Hello,
+Hello,
- This is a test email where foo: bar.
+This is a test email where foo: bar.
- utf8: =E6=88=91=E4=BB=AC=E5=BA=94=E8=AF=A5=E8=83=BD=E5=A4=9F=E6=97=A0=
-=E7=BC=9D=E5=A4=84=E7=90=86UTF8=E7=BC=96=E7=A0=81
+utf8: =E6=88=91=E4=BB=AC=E5=BA=94=E8=AF=A5=E8=83=BD=E5=A4=9F=E6=97=A0=E7=BC=
+=9D=E5=A4=84=E7=90=86UTF8=E7=BC=96=E7=A0=81
- indented_text
+ indented_text
- long line: Lorem ipsum dolor sit amet, consectetur adipisicing
- elit, sed do eiusmod tempor incididunt ut labore et dolore
- magna aliqua. Ut enim ad minim veniam, quis nostrud
- exercitation ullamco laboris nisi ut aliquip ex ea commodo
- consequat. Duis aute irure dolor in reprehenderit in voluptate
- velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
- sint occaecat cupidatat non proident, sunt in culpa qui officia
- deserunt mollit anim id est laborum.
+long line: Lorem ipsum dolor sit amet, consectetur adipisicing elit,
+sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
+nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+culpa qui officia deserunt mollit anim id est laborum.
- Yours,=20=20
- FixMyStreet.=20=
+Yours,=20=20
+FixMyStreet.=20=
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index c592e9d3f..ae413978f 100644
--- a/t/app/model/alert_type.t
+++ b/t/app/model/alert_type.t
@@ -39,7 +39,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',
@@ -97,6 +97,7 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
alert_type => 'new_updates',
whensubscribed => $dt->ymd . ' ' . $dt->hms,
confirmed => 1,
+ cobrand => 'default',
}
);
@@ -107,6 +108,7 @@ my $alert3 = FixMyStreet::App->model('DB::Alert')->find_or_create(
alert_type => 'new_updates',
whensubscribed => $dt->ymd . ' ' . $dt->hms,
confirmed => 1,
+ cobrand => 'default',
}
);
@@ -185,7 +187,11 @@ subtest "correct text for title after URL" => sub {
parameter => $report->id,
}
)->delete;
- FixMyStreet::App->model('DB::AlertType')->email_alerts();
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ }, sub {
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+ };
my $email = $mech->get_email;
(my $title = $report->title) =~ s/ /\\s+/;
@@ -318,7 +324,11 @@ foreach my $test (
$report->geocode( $g );
$report->update();
- FixMyStreet::App->model('DB::AlertType')->email_alerts();
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ }, sub {
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+ };
my $email = $mech->get_email;
my $body = $email->body;
@@ -345,7 +355,7 @@ my $ward_alert = FixMyStreet::App->model('DB::Alert')->find_or_create(
my $report_to_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'WS13 6YY',
- council => '2434',
+ bodies_str => '2434',
areas => ',105255,11806,11828,2247,2504,7117,',
category => 'Other',
title => 'council report',
@@ -369,7 +379,7 @@ my $report_to_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'WS13 6YY',
- council => '2240',
+ bodies_str => '2240',
areas => ',105255,11806,11828,2247,2504,7117,',
category => 'Other',
title => 'county report',
@@ -393,7 +403,7 @@ my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_c
my $report_outside_district = FixMyStreet::App->model('DB::Problem')->find_or_create(
{
postcode => 'WS13 6YY',
- council => '2221',
+ bodies_str => '2221',
areas => ',105255,11806,11828,2247,2504,7117,',
category => 'Other',
title => 'outside district report',
@@ -423,7 +433,11 @@ subtest "check alerts from cobrand send main site url for alerts for different c
}
)->delete;
- FixMyStreet::App->model('DB::AlertType')->email_alerts();
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ }, sub {
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+ };
my $email = $mech->get_email;
my $body = $email->body;
@@ -473,7 +487,34 @@ subtest "check local alerts from cobrand send main site url for alerts for diffe
like $body, qr#$expected2#, 'cobrand area report point to cobrand url';
};
-$report->comments->delete();
-$report->delete();
-done_testing();
+# Test that email alerts are sent in the right language.
+subtest "correct i18n-ed summary for state of closed" => sub {
+ $mech->clear_emails_ok;
+
+ $report->update( { state => 'closed' } );
+ $alert->update( { lang => 'nb', cobrand => 'fiksgatami' } );
+ FixMyStreet::App->model('DB::AlertSent')->search( {
+ alert_id => $alert->id,
+ parameter => $comment->id,
+ } )->delete;
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fiksgatami' ],
+ }, sub {
+ FixMyStreet::App->model('DB::AlertType')->email_alerts();
+ };
+
+ $mech->email_count_is( 1 );
+ my $email = $mech->get_email;
+ my $body = $email->body;
+ my $msg = 'Denne rapporten er for tiden markert som lukket';
+ like $body, qr/$msg/, 'email says problem is closed, in Norwegian';
+};
+
+END {
+ $mech->delete_user($user) if $user;
+ $mech->delete_user($user2) if $user2;
+ $mech->delete_user($user3) if $user3;
+ done_testing();
+}
diff --git a/t/app/model/comment.t b/t/app/model/comment.t
index 93104c2e5..3141af828 100644
--- a/t/app/model/comment.t
+++ b/t/app/model/comment.t
@@ -23,5 +23,5 @@ my $comment = $comment_rs->new(
}
);
-is $comment->confirmed_local, undef, 'inflating null confirmed ok';
-is $comment->created_local, undef, 'inflating null confirmed ok';
+is $comment->confirmed, undef, 'inflating null confirmed ok';
+is $comment->created, undef, 'inflating null confirmed ok';
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 63204e05c..24ed959af 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -9,6 +9,7 @@ use FixMyStreet;
use FixMyStreet::App;
use FixMyStreet::TestMech;
use mySociety::Locale;
+use Sub::Override;
mySociety::Locale::gettext_domain('FixMyStreet');
@@ -32,10 +33,10 @@ my $problem = $problem_rs->new(
}
);
-is $problem->confirmed_local, undef, 'inflating null confirmed ok';
-is $problem->whensent_local, undef, 'inflating null confirmed ok';
-is $problem->lastupdate_local, undef, 'inflating null confirmed ok';
-is $problem->created_local, undef, 'inflating null confirmed ok';
+is $problem->confirmed, undef, 'inflating null confirmed ok';
+is $problem->whensent, undef, 'inflating null confirmed ok';
+is $problem->lastupdate, undef, 'inflating null confirmed ok';
+is $problem->created, undef, 'inflating null confirmed ok';
for my $test (
{
@@ -44,7 +45,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
name => 'Please enter your name',
}
},
@@ -56,7 +57,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
name => 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
}
},
@@ -68,7 +69,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
name => 'Please enter your full name, councils need this information – if you do not wish your name to be shown on the site, untick the box below',
}
},
@@ -80,7 +81,7 @@ for my $test (
errors => {
title => 'Please enter a subject',
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
@@ -90,7 +91,7 @@ for my $test (
},
errors => {
detail => 'Please enter some details',
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
@@ -99,22 +100,22 @@ for my $test (
detail => 'Some information about the problem',
},
errors => {
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
- desc => 'incorrectly formatted council',
+ desc => 'incorrectly formatted body',
changed => {
- council => 'my council',
+ bodies_str => 'my body',
},
errors => {
- council => 'No council selected',
+ bodies => 'No council selected',
}
},
{
- desc => 'correctly formatted council',
+ desc => 'correctly formatted body',
changed => {
- council => '1001',
+ bodies_str => '1001',
},
errors => {
}
@@ -167,6 +168,10 @@ $problem->insert;
my $tz_local = DateTime::TimeZone->new( name => 'local' );
+my $body = FixMyStreet::App->model('DB::Body')->new({
+ name => 'Edinburgh City Council'
+});
+
for my $test (
{
desc => 'request older than problem ignored',
@@ -174,9 +179,6 @@ for my $test (
request => {
updated_datetime => DateTime::Format::W3CDTF->new()->format_datetime( DateTime->now()->set_time_zone( $tz_local )->subtract( days => 2 ) ),
},
- council => {
- name => 'Edinburgh City Council',
- },
created => 0,
},
{
@@ -187,9 +189,6 @@ for my $test (
status => 'open',
status_notes => 'this is an update from the council',
},
- council => {
- name => 'Edinburgh City Council',
- },
created => 1,
state => 'confirmed',
mark_fixed => 0,
@@ -203,9 +202,6 @@ for my $test (
status => 'closed',
status_notes => 'the council have fixed this',
},
- council => {
- name => 'Edinburgh City Council',
- },
created => 1,
state => 'fixed',
mark_fixed => 1,
@@ -219,9 +215,6 @@ for my $test (
status => 'open',
status_notes => 'the council do not think this is fixed',
},
- council => {
- name => 'Edinburgh City Council',
- },
created => 1,
start_state => 'fixed',
state => 'fixed',
@@ -238,7 +231,7 @@ for my $test (
$problem->update;
my $w3c = DateTime::Format::W3CDTF->new();
- my $ret = $problem->update_from_open311_service_request( $test->{request}, $test->{council}, $user );
+ my $ret = $problem->update_from_open311_service_request( $test->{request}, $body, $user );
is $ret, $test->{created}, 'return value';
return unless $test->{created};
@@ -302,6 +295,13 @@ for my $test (
is_closed => 0,
},
{
+ state => 'action scheduled',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 1,
+ is_closed => 0,
+ },
+ {
state => 'in progress',
is_visible => 1,
is_fixed => 0,
@@ -309,6 +309,27 @@ for my $test (
is_closed => 0,
},
{
+ state => 'duplicate',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 1,
+ },
+ {
+ state => 'not responsible',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 1,
+ },
+ {
+ state => 'unable to fix',
+ is_visible => 1,
+ is_fixed => 0,
+ is_open => 0,
+ is_closed => 1,
+ },
+ {
state => 'fixed',
is_visible => 1,
is_fixed => 1,
@@ -355,42 +376,53 @@ my %contact_params = (
whenedited => \'ms_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 => 2434, name => 'Lichfield District Council' },
+ { id => 2240, name => 'Staffordshire County Council' },
+ { id => 14279, name => 'Ballymoney Borough Council' },
+ { id => 2636, name => 'Isle of Wight Council' },
+ { id => 2649, name => 'Fife 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 @contacts;
for my $contact ( {
- area_id => 2651, # Edinburgh
+ body_id => 2651, # Edinburgh
category => 'potholes',
email => 'test@example.org',
}, {
- area_id => 2226, # Gloucestershire
+ body_id => 2226, # Gloucestershire
category => 'potholes',
email => '2226@example.org',
}, {
- area_id => 2326, # Cheltenham
+ body_id => 2326, # Cheltenham
category => 'potholes',
email => '2326@example.org',
}, {
- area_id => 2434, # Lichfield
+ body_id => 2434, # Lichfield
category => 'potholes',
email => 'trees@example.com',
}, {
- area_id => 2240, # Staffordshire
+ body_id => 2240, # Staffordshire
category => 'potholes',
email => 'highways@example.com',
}, {
- area_id => 14279, # Ballymoney
+ body_id => 14279, # Ballymoney
category => 'Street lighting',
email => 'roads.western@drdni.example.org',
}, {
- area_id => 14279, # Ballymoney
+ body_id => 14279, # Ballymoney
category => 'Graffiti',
email => 'highways@example.com',
}, {
confirmed => 0,
- area_id => 2636, # Isle of Wight
+ body_id => 2636, # Isle of Wight
category => 'potholes',
email => '2636@example.com',
} ) {
@@ -410,21 +442,21 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear City of Edinburgh Council',
to => qr'City of Edinburgh Council',
- council => 2651,
+ body => 2651,
}, {
%common,
desc => 'no email sent if no unsent problems',
unset_whendef => 0,
email_count => 0,
- council => 2651,
+ body => 2651,
}, {
%common,
desc => 'email to two tier council',
unset_whendef => 1,
email_count => 1,
- to => qr'Gloucestershire County Council.*Cheltenham Borough Council',
- dear => qr'Dear Gloucestershire County Council and Cheltenham Borough',
- council => '2226,2326',
+ to => qr'Cheltenham Borough Council.*Gloucestershire County Council',
+ dear => qr'Dear Cheltenham Borough Council and Gloucestershire County',
+ body => '2226,2326',
multiple => 1,
}, {
%common,
@@ -433,7 +465,7 @@ foreach my $test ( {
email_count => 1,
to => qr'Gloucestershire County Council" <2226@example',
dear => qr'Dear Gloucestershire County Council,',
- council => '2226|2649',
+ body => '2226|2649',
missing => qr'problem might be the responsibility of Fife.*Council'ms,
}, {
%common,
@@ -442,7 +474,7 @@ foreach my $test ( {
email_count => 1,
to => qr'Lichfield District Council',
dear => qr'Dear Lichfield District Council,',
- council => '2434',
+ body => '2434',
cobrand => 'lichfielddc',
url => 'lichfielddc.',
}, {
@@ -452,9 +484,9 @@ foreach my $test ( {
email_count => 1,
to => qr'Staffordshire County Council" <highways@example',
dear => qr'Dear Staffordshire County Council,',
- council => '2240',
+ body => '2240',
cobrand => 'lichfielddc',
- url => '',
+ url => 'www.',
}, {
%common,
desc => 'directs NI correctly, 1',
@@ -462,7 +494,7 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear Ballymoney Borough Council',
to => qr'Ballymoney Borough Council',
- council => 14279,
+ body => 14279,
category => 'Graffiti',
}, {
%common,
@@ -471,7 +503,7 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear Roads Service \(Western\)',
to => qr'Roads Service \(Western\)" <roads',
- council => 14279,
+ body => 14279,
category => 'Street lighting',
}, {
%common,
@@ -479,12 +511,17 @@ foreach my $test ( {
unset_whendef => 1,
stays_unsent => 1,
email_count => 0,
- council => 2636,
+ body => 2636,
},
) {
subtest $test->{ desc } => sub {
- if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ && !FixMyStreet::Cobrand->exists('lichfielddc') ) {
- plan skip_all => 'Skipping Lichfield tests without Lichfield cobrand';
+ my $override = {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ BASE_URL => 'http://www.fixmystreet.com',
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ };
+ if ( $test->{cobrand} && $test->{cobrand} =~ /lichfielddc/ ) {
+ $override->{ALLOWED_COBRANDS} = [ 'lichfielddc' ];
}
$mech->clear_emails_ok;
@@ -497,7 +534,7 @@ foreach my $test ( {
$problem->discard_changes;
$problem->update( {
- council => $test->{ council },
+ bodies_str => $test->{ body },
state => 'confirmed',
confirmed => \'ms_current_timestamp()',
whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()',
@@ -506,7 +543,9 @@ foreach my $test ( {
cobrand => $test->{ cobrand } || 'fixmystreet',
} );
- FixMyStreet::App->model('DB::Problem')->send_reports();
+ FixMyStreet::override_config $override, sub {
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+ };
$mech->email_count_is( $test->{ email_count } );
if ( $test->{ email_count } ) {
@@ -519,15 +558,14 @@ foreach my $test ( {
like $email->body, $test->{ dear }, 'Salutation looks correct';
if ( $test->{multiple} ) {
- like $email->body, qr/This email has been sent to several councils /, 'multiple council text correct';
+ like $email->body, qr/This email has been sent to several councils /, 'multiple body text correct';
} elsif ( $test->{ missing } ) {
- like $email->body, $test->{ missing }, 'missing council information correct';
+ like $email->body, $test->{ missing }, 'missing body information correct';
}
if ( $test->{url} ) {
- (my $base_url = FixMyStreet->config('BASE_URL')) =~ s{http://}{};
my $id = $problem->id;
- like $email->body, qr[$test->{url}$base_url/report/$id], 'URL present is correct';
+ like $email->body, qr[$test->{url}fixmystreet.com/report/$id], 'URL present is correct';
}
$problem->discard_changes;
@@ -540,10 +578,57 @@ foreach my $test ( {
};
}
-subtest 'check can turn on report sent email alerts' => sub {
- eval 'use Test::MockModule; 1' or
- plan skip_all => 'Skipping tests that rely on Test::MockModule';
+subtest 'check can set mutiple emails as a single contact' => sub {
+ my $override = {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ BASE_URL => 'http://www.fixmystreet.com',
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ };
+
+ my $contact = {
+ body_id => 2651, # Edinburgh
+ category => 'trees',
+ email => '2636@example.com,2636-2@example.com',
+ };
+ my $new_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ %$contact } );
+ ok $new_contact, "created multiple email test contact";
+
+ $mech->clear_emails_ok;
+
+ FixMyStreet::App->model('DB::Problem')->search(
+ {
+ whensent => undef
+ }
+ )->update( { whensent => \'ms_current_timestamp()' } );
+ $problem->discard_changes;
+ $problem->update( {
+ bodies_str => $contact->{ body_id },
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => undef,
+ category => 'trees',
+ name => 'Test User',
+ cobrand => 'fixmystreet',
+ send_fail_count => 0,
+ } );
+
+ FixMyStreet::override_config $override, sub {
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+ };
+
+ $mech->email_count_is(1);
+ my $email = $mech->get_email;
+ is $email->header('To'), '"City of Edinburgh Council" <2636@example.com>, "City of Edinburgh Council" <2636-2@example.com>', 'To contains two email addresses';
+};
+
+subtest 'check can turn on report sent email alerts' => sub {
+ my $send_confirmation_mail_override = Sub::Override->new(
+ "FixMyStreet::Cobrand::Default::report_sent_confirmation_email",
+ sub { return 1; }
+ );
$mech->clear_emails_ok;
FixMyStreet::App->model('DB::Problem')->search(
@@ -554,18 +639,16 @@ subtest 'check can turn on report sent email alerts' => sub {
$problem->discard_changes;
$problem->update( {
- council => 2651,
+ bodies_str => 2651,
state => 'confirmed',
confirmed => \'ms_current_timestamp()',
whensent => undef,
category => 'potholes',
name => 'Test User',
cobrand => 'fixmystreet',
+ send_fail_count => 0,
} );
- my $m = new Test::MockModule(
- 'FixMyStreet::Cobrand::FixMyStreet' );
- $m->mock( report_sent_confirmation_email => 1 );
FixMyStreet::App->model('DB::Problem')->send_reports();
$mech->email_count_is( 2 );
@@ -585,14 +668,95 @@ subtest 'check can turn on report sent email alerts' => sub {
$email = $emails[1];
like $email->header('Subject'), qr/Problem Report Sent/, 'report sent email title correct';
like $email->body, qr/Your report about/, 'report sent body correct';
+
+ $send_confirmation_mail_override->restore();
};
-$problem->comments->delete;
-$problem->delete;
-$user->delete;
-foreach (@contacts) {
- $_->delete;
-}
+subtest 'check iOS app store test reports not sent' => sub {
+ $mech->clear_emails_ok;
+
+ FixMyStreet::App->model('DB::Problem')->search(
+ {
+ whensent => undef
+ }
+ )->update( { whensent => \'ms_current_timestamp()' } );
+
+ $problem->discard_changes;
+ $problem->update( {
+ bodies_str => 2651,
+ title => 'App store test',
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => undef,
+ category => 'potholes',
+ send_fail_count => 0,
+ } );
+
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+
+ $mech->email_count_is( 0 );
+
+ $problem->discard_changes();
+ is $problem->state, 'hidden', 'iOS test reports are hidden automatically';
+ is $problem->whensent, undef, 'iOS test reports are not sent';
+};
+
+subtest 'check reports from abuser not sent' => sub {
+ $mech->clear_emails_ok;
+
+ FixMyStreet::App->model('DB::Problem')->search(
+ {
+ whensent => undef
+ }
+ )->update( { whensent => \'ms_current_timestamp()' } );
-done_testing();
+ $problem->discard_changes;
+ $problem->update( {
+ bodies_str => 2651,
+ title => 'Report',
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => undef,
+ category => 'potholes',
+ send_fail_count => 0,
+ } );
+
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+
+ $mech->email_count_is( 1 );
+
+ $problem->discard_changes();
+ ok $problem->whensent, 'Report has been sent';
+
+ $problem->update( {
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => undef,
+ } );
+
+ my $abuse = FixMyStreet::App->model('DB::Abuse')->create( { email => $problem->user->email } );
+
+ $mech->clear_emails_ok;
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+
+ $mech->email_count_is( 0 );
+
+ $problem->discard_changes();
+ is $problem->state, 'hidden', 'reports from abuse user are hidden automatically';
+ is $problem->whensent, undef, 'reports from abuse user are not sent';
+
+ ok $abuse->delete(), 'user removed from abuse table';
+};
+
+END {
+ $problem->comments->delete if $problem;
+ $problem->delete if $problem;
+ $mech->delete_user( $user ) if $user;
+
+ foreach (@contacts) {
+ $_->delete;
+ }
+
+ done_testing();
+}
diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t
index 60b52043a..be5b433c1 100644
--- a/t/app/model/questionnaire.t
+++ b/t/app/model/questionnaire.t
@@ -32,8 +32,6 @@ my $problem = FixMyStreet::App->model('DB::Problem')->create(
}
);
-diag $problem->id;
-
my $mech = FixMyStreet::TestMech->new;
for my $test (
@@ -62,6 +60,10 @@ for my $test (
send_email => 1,
},
{
+ state => 'action scheduled',
+ send_email => 1,
+ },
+ {
state => 'in progress',
send_email => 1,
},
@@ -78,6 +80,18 @@ for my $test (
send_email => 1,
},
{
+ state => 'duplicate',
+ send_email => 1,
+ },
+ {
+ state => 'unable to fix',
+ send_email => 1,
+ },
+ {
+ state => 'not responsible',
+ send_email => 1,
+ },
+ {
state => 'closed',
send_email => 1,
},
diff --git a/t/app/model/rabx_column.t b/t/app/model/rabx_column.t
new file mode 100644
index 000000000..607d578ce
--- /dev/null
+++ b/t/app/model/rabx_column.t
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use_ok "FixMyStreet::DB::RABXColumn";
+
+# Test that the class names are correctly normalised
+my @tests = (
+ ["FixMyStreet::DB::Result::Token", "Token"],
+ ["FixMyStreet::App::Model::DB::Token", "Token"],
+);
+
+foreach my $test (@tests) {
+ my ($input, $expected) = @$test;
+ is(
+ FixMyStreet::DB::RABXColumn::_get_class_identifier($input),
+ $expected,
+ "$input -> $expected"
+ );
+}
+
+done_testing();
diff --git a/t/app/model/token.t b/t/app/model/token.t
index 12945975e..637477fa3 100644
--- a/t/app/model/token.t
+++ b/t/app/model/token.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 45;
+use Test::More;
use FixMyStreet;
use FixMyStreet::App;
@@ -94,3 +94,47 @@ foreach my $test_data_name ( sort keys %tests ) {
undef, "token gone with m::AT";
}
+
+
+
+# Test that the inflation and deflation works as expected
+{
+ my $token =
+ $token_rs->create( { scope => 'testing', data => {} } );
+ END { $token->delete() };
+
+ # Add in temporary check to test that the data is updated as expected.
+ is_deeply($token->data, {}, "data is empty");
+
+ # store something in it
+ $token->update({ data => { foo => 'bar' } });
+ $token->discard_changes();
+ is_deeply($token->data, { foo => 'bar' }, "data has content");
+
+ # change the hash stored
+ $token->update({ data => { baz => 'bundy' } });
+ $token->discard_changes();
+ is_deeply($token->data, { baz => 'bundy' }, "data has new content");
+
+ # change the hashref in place
+ {
+ my $data = $token->data;
+ $data->{baz} = 'new';
+ $token->data( $data );
+ $token->update();
+ $token->discard_changes();
+ is_deeply($token->data, { baz => 'new' }, "data has been updated");
+ }
+
+ # change the hashref in place
+ {
+ my $data = $token->data;
+ $data->{baz} = 'new';
+ $token->update({ data => $data });
+ $token->discard_changes();
+ is_deeply($token->data, { baz => 'new' }, "data has been updated");
+ }
+
+}
+
+done_testing();
diff --git a/t/app/sendreport/email.t b/t/app/sendreport/email.t
index f0e1f153a..8063c928f 100644
--- a/t/app/sendreport/email.t
+++ b/t/app/sendreport/email.t
@@ -14,9 +14,14 @@ use mySociety::Locale;
my $e = FixMyStreet::SendReport::Email->new();
+# area id 1000
+my $params = { id => 1000, name => 'Council of the Thousand' };
+my $body = FixMyStreet::App->model('DB::Body')->find_or_create($params);
+ok $body, "found/created body";
+
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
email => 'council@example.com',
- area_id => 1000,
+ body_id => 1000,
category => 'category',
confirmed => 1,
deleted => 0,
@@ -26,8 +31,9 @@ my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
);
my $row = FixMyStreet::App->model('DB::Problem')->new( {
- council => '1000',
+ bodies_str => '1000',
category => 'category',
+ cobrand => '',
} );
ok $e;
@@ -47,7 +53,7 @@ foreach my $test ( {
count => undef,
add_council => 1,
unconfirmed => 1,
- expected_note => 'Council 1000 deleted',
+ expected_note => 'Body 1000 deleted',
},
{
desc => 'unconfirmed contact note uses note from contact table',
@@ -62,7 +68,7 @@ foreach my $test ( {
my $e = FixMyStreet::SendReport::Email->new;
$contact->update( { confirmed => 0 } ) if $test->{unconfirmed};
$contact->update( { note => $test->{note} } ) if $test->{note};
- $e->add_council( 1000, { name => 'test council' } ) if $test->{add_council};
+ $e->add_body( $body ) if $test->{add_council};
is $e->build_recipient_list( $row, {} ), $test->{count}, 'correct recipient list count';
if ( $test->{unconfirmed} ) {
diff --git a/t/app/uri_for.t b/t/app/uri_for.t
index eecf30e32..810aade62 100644
--- a/t/app/uri_for.t
+++ b/t/app/uri_for.t
@@ -4,7 +4,7 @@ use warnings;
use Test::More;
# FIXME Should this be here? A better way? uri_for varies by map.
-use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App';
+use Catalyst::Test 'FixMyStreet::App';
FixMyStreet::Map::set_map_class();
# structure of these tests borrowed from '/t/aggregate/unit_core_uri_for.t'
@@ -15,43 +15,9 @@ use URI;
use_ok('FixMyStreet::App');
-my $fms_c = FixMyStreet::App->new(
- {
- request => Catalyst::Request->new(
- {
- base => URI->new('http://www.fixmystreet.com/'),
- uri => URI->new('http://www.fixmystreet.com/test_namespace')
- }
- ),
- namespace => 'test_namespace',
- }
-);
-
-my $fgm_c = FixMyStreet::App->new(
- {
- request => Catalyst::Request->new(
- {
- base => URI->new('http://www.fiksgatami.no/'),
- uri => URI->new('http://www.fiksgatami.no/test_namespace')
- }
- ),
- namespace => 'test_namespace',
- }
-);
-
-my $reh_en_c = FixMyStreet::App->new(
- {
- request => Catalyst::Request->new(
- {
- base => URI->new('http://reportemptyhomes.com/'),
- uri => URI->new('http://reportemptyhomes.com/test_namespace')
- }
- ),
- namespace => 'test_namespace',
- }
-);
-$reh_en_c->setup_request();
-
+my $fms_c = ctx_request('http://www.fixmystreet.com/');
+my $fgm_c = ctx_request('http://www.fiksgatami.no/');
+my $reh_en_c = ctx_request('http://reportemptyhomes.com/');
is(
$fms_c->uri_for('/bar/baz') . "",
@@ -61,7 +27,7 @@ is(
is(
$fms_c->uri_for('') . "",
- 'http://www.fixmystreet.com/test_namespace',
+ 'http://www.fixmystreet.com/',
'URI for namespace'
);
@@ -78,36 +44,29 @@ is(
'FiksGataMi url with lat not zoom'
);
-SKIP: {
- skip( "Need 'emptyhomes' in ALLOWED_COBRANDS config", 2 )
- unless FixMyStreet::Cobrand->exists('emptyhomes');
-
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'emptyhomes' ],
+}, sub {
like(
$reh_en_c->uri_for_email( '/foo' ),
qr{^http://en.},
'adds en to retain language'
);
+};
- # instantiate this here otherwise sets locale to cy and breaks test
- # above
- my $reh_cy_c = FixMyStreet::App->new(
- {
- request => Catalyst::Request->new(
- {
- base => URI->new('http://cy.reportemptyhomes.com/'),
- uri => URI->new('http://cy.reportemptyhomes.com/test_namespace')
- }
- ),
- namespace => 'test_namespace',
- }
- );
- $reh_cy_c->setup_request();
+# instantiate this here otherwise sets locale to cy and breaks test
+# above
+my $reh_cy_c;
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'emptyhomes' ],
+}, sub {
+ $reh_cy_c = ctx_request('http://cy.reportemptyhomes.com/');
like(
$reh_cy_c->uri_for_email( '/foo' ),
qr{^http://cy.},
'retains language'
);
-}
+};
done_testing();
diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t
new file mode 100644
index 000000000..91a7038ec
--- /dev/null
+++ b/t/cobrand/bromley.t
@@ -0,0 +1,42 @@
+use strict;
+use warnings;
+use Test::More;
+
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
+
+# Create test data
+my $user = $mech->create_user_ok( 'bromley@example.com' );
+my $body = $mech->create_body_ok( 2482, 'Bromley' );
+
+my @reports = $mech->create_problems_for_body( 1, 2482, 'Test', {
+ cobrand => 'bromley',
+ user => $user,
+});
+my $report = $reports[0];
+
+for my $update ('in progress', 'unable to fix') {
+ FixMyStreet::App->model('DB::Comment')->find_or_create( {
+ problem_state => $update,
+ problem_id => $report->id,
+ user_id => $user->id,
+ name => 'User',
+ mark_fixed => 'f',
+ text => "This update marks it as $update",
+ state => 'confirmed',
+ confirmed => 'now()',
+ anonymous => 'f',
+ } );
+}
+
+# Test Bromley special casing of 'unable to fix'
+$mech->get_ok( '/report/' . $report->id );
+$mech->content_contains( 'marks it as in progress' );
+$mech->content_contains( 'marked as in progress' );
+$mech->content_contains( 'marks it as unable to fix' );
+$mech->content_contains( 'marked as no further action' );
+
+# Clean up
+$mech->delete_user($user);
+$mech->delete_problems_for_body( 2482 );
+done_testing();
diff --git a/t/cobrand/closest.t b/t/cobrand/closest.t
index 464c95e67..d06f7e9a0 100644
--- a/t/cobrand/closest.t
+++ b/t/cobrand/closest.t
@@ -5,6 +5,9 @@ use Test::More;
use mySociety::Locale;
use FixMyStreet::App;
+use FixMyStreet::TestMech;
+
+my $mech = FixMyStreet::TestMech->new;
use_ok 'FixMyStreet::Cobrand';
@@ -29,7 +32,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',
@@ -81,4 +84,5 @@ SKIP: {
}
# all done
+$mech->delete_user( $user );
done_testing();
diff --git a/t/cobrand/councils.t b/t/cobrand/councils.t
index 8fb10cfbe..0cf25ebdf 100644
--- a/t/cobrand/councils.t
+++ b/t/cobrand/councils.t
@@ -6,13 +6,13 @@ use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
foreach my $council (qw/southampton reading bromley/) {
- SKIP: {
- skip( "Need '$council' in ALLOWED_COBRANDS config", 3 )
- unless FixMyStreet::Cobrand->exists($council);
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ $council ],
+ }, sub {
ok $mech->host("$council.fixmystreet.com"), "change host to $council";
$mech->get_ok('/');
- $mech->content_like( qr/$council/i );
- }
+ $mech->content_like( qr/\u$council/ );
+ };
}
done_testing();
diff --git a/t/cobrand/fixmybarangay.t b/t/cobrand/fixmybarangay.t
new file mode 100644
index 000000000..b996fa0a6
--- /dev/null
+++ b/t/cobrand/fixmybarangay.t
@@ -0,0 +1,140 @@
+use strict;
+use warnings;
+use Test::More;
+
+BEGIN {
+ use FixMyStreet;
+ FixMyStreet->test_mode(1);
+}
+
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
+
+# Front page test
+
+ok $mech->host("www.fixmybarangay.com"), "change host to FixMyBarangay";
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmybarangay' ],
+}, sub {
+ $mech->get_ok('/');
+};
+$mech->content_like( qr/FixMyBarangay/ );
+
+# Set up bodies
+
+my $luz = $mech->create_body_ok( 1, 'Bgy Luz' );
+$luz->update( { send_method => 'Email' } );
+
+my $bsn = $mech->create_body_ok( 2, 'Bgy BSN' );
+$bsn->update( { send_method => 'Email' } );
+
+my $dps = $mech->create_body_ok( 3, 'DPS' );
+$dps->update( { send_method => 'Open311', endpoint => 'http://dps.endpoint.example.com', jurisdiction => 'FMB', api_key => 'test' } );
+FixMyStreet::App->model('DB::BodyArea')->find_or_create({ area_id => 1, body_id => 3 });
+FixMyStreet::App->model('DB::BodyArea')->find_or_create({ area_id => 2, body_id => 3 });
+
+# Create contacts for these bodies
+# TODO: log in as a Bgy user, and create a report using the front end,
+# testing that the drop-down has the right things in it, and so on.
+
+my %contact_params = (
+ confirmed => 1,
+ deleted => 0,
+ editor => 'Test',
+ whenedited => \'current_timestamp',
+ note => 'Created for test',
+);
+FixMyStreet::App->model('DB::Contact')->search( {
+ email => { 'like', '%example.com' },
+} )->delete;
+my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ body_id => 1,
+ category => 'Streetlight (BGY)',
+ email => 'bgy@example.com',
+} );
+my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ body_id => 3,
+ category => 'Streetlight (DPS)',
+ email => 'LIGHT',
+} );
+
+# Create a couple of reports
+
+my @reports = $mech->create_problems_for_body( 1, 1, 'Test', {
+ cobrand => 'fixmybarangay',
+ category => 'Streetlight (BGY)',
+});
+my $luz_report = $reports[0];
+
+@reports = $mech->create_problems_for_body( 1, 3, 'Test', {
+ cobrand => 'fixmybarangay',
+ category => 'Streetlight (DPS)',
+});
+my $dps_report = $reports[0];
+
+$mech->get_ok( '/report/' . $luz_report->id );
+$mech->get_ok( '/report/' . $dps_report->id );
+
+# Send the reports
+
+$mech->email_count_is(0);
+
+FixMyStreet::override_config {
+ SEND_REPORTS_ON_STAGING => 1,
+}, sub {
+ FixMyStreet::App->model('DB::Problem')->send_reports('fixmybarangay');
+};
+
+# Check BGY one sent by email
+my $email = $mech->get_email;
+like $email->header('Subject'), qr/Problem Report: Test Test/, 'subject looks okay';
+like $email->header('To'), qr/bgy\@example.com/, 'to line looks correct';
+$mech->clear_emails_ok;
+
+$luz_report->discard_changes;
+$dps_report->discard_changes;
+ok $luz_report->whensent, 'Luz report marked as sent';
+ok $dps_report->whensent, 'DPS report marked as sent';
+is $dps_report->send_method_used, 'Open311', 'DPS report sent via Open311';
+is $dps_report->external_id, 248, 'DPS report has right external ID';
+
+my $fmb_test_email = 'luz_test_user@example.com';
+my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => $fmb_test_email, from_body => 1, password => 'fmbsecret' } );
+ok $user, "test user does exist";
+
+$mech->log_out_ok;
+$mech->get_ok( '/report/' . $luz_report->id );
+$mech->content_lacks( "Remove from site" );
+$mech->content_contains( "Report abuse" );
+
+$mech->post_ok('/report/delete/' . $luz_report->id);
+is $mech->uri->path, '/report/' . $luz_report->id, "should redirect to report page, deletion ignored";
+$luz_report->discard_changes;
+is $luz_report->state, 'confirmed', 'should be confirmed';
+
+$user = $mech->log_in_ok($fmb_test_email);
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmybarangay' ],
+}, sub {
+ $mech->get_ok( '/report/' . $luz_report->id );
+};
+$mech->content_contains( "Remove from site" );
+$mech->content_lacks( "Report abuse" );
+
+$mech->form_id('remove-from-site-form');
+$mech->submit_form();
+is $mech->uri->path, '/report/' . $luz_report->id, "should redirect to report page, deletion successful";
+$luz_report->discard_changes;
+is $luz_report->state, 'hidden', 'should be hidden';
+
+$mech->delete_user($fmb_test_email);
+
+$mech->delete_problems_for_body( 1 );
+$mech->delete_problems_for_body( 3 );
+
+ok $mech->host("www.fixmystreet.com"), "change host back";
+
+done_testing();
diff --git a/t/cobrand/get_body_sender.t b/t/cobrand/get_body_sender.t
new file mode 100644
index 000000000..964f5c0e4
--- /dev/null
+++ b/t/cobrand/get_body_sender.t
@@ -0,0 +1,43 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use mySociety::Locale;
+use FixMyStreet::App;
+
+use_ok 'FixMyStreet::Cobrand';
+
+mySociety::Locale::gettext_domain( 'FixMyStreet' );
+
+my $c = FixMyStreet::Cobrand::FixMyStreet->new();
+
+FixMyStreet::App->model('DB::BodyArea')->search( { body_id => 1000 } )->delete;
+FixMyStreet::App->model('DB::Body')->search( { name => 'Body of a Thousand' } )->delete;
+
+my $body = FixMyStreet::App->model('DB::Body')->find_or_create({
+ id => 1000,
+ name => 'Body of a Thousand',
+});
+my $body_area = $body->body_areas->find_or_create({ area_id => 1000 });
+
+FixMyStreet::override_config {
+ MAPIT_TYPES => [ 'LBO' ],
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+}, sub {
+ is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'defaults to email';
+
+ $body_area->update({ area_id => 2481 }); # Croydon LBO
+ is_deeply $c->get_body_sender( $body ), { method => 'London' }, 'returns london report it if London borough';
+};
+
+$body->send_method( 'TestMethod' );
+is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to London';
+
+$body_area->update({ area_id => 1000 }); # Nothing
+is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to Email';
+
+$body_area->delete;
+$body->delete;
+
+done_testing();
diff --git a/t/cobrand/get_council_sender.t b/t/cobrand/get_council_sender.t
deleted file mode 100644
index e61f36370..000000000
--- a/t/cobrand/get_council_sender.t
+++ /dev/null
@@ -1,30 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More;
-
-use mySociety::Locale;
-use FixMyStreet::App;
-
-use_ok 'FixMyStreet::Cobrand';
-
-mySociety::Locale::gettext_domain( 'FixMyStreet' );
-
-my $c = FixMyStreet::Cobrand::FixMyStreet->new();
-
-
-is_deeply $c->get_council_sender( '1000', { type => 'DIS' } ), { method => 'Email' }, 'defaults to email';
-is_deeply $c->get_council_sender( '1000', { type => 'LBO' } ), { method=> 'London' }, 'returns london report it if London borough';
-
-my $conf = FixMyStreet::App->model('DB::Open311Conf')->find_or_create(
- area_id => 1000,
- endpoint => '',
- send_method => 'TestMethod'
-);
-
-is $c->get_council_sender( '1000', { type => 'LBO' } )->{ method }, 'TestMethod', 'uses send_method in preference to London';
-is $c->get_council_sender( '1000', { type => 'DIS' } )->{ method }, 'TestMethod', 'uses send_method in preference to Email';
-
-$conf->delete;
-
-done_testing();
diff --git a/t/cobrand/hart.t b/t/cobrand/hart.t
new file mode 100644
index 000000000..f4a2473eb
--- /dev/null
+++ b/t/cobrand/hart.t
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use Test::More;
+
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'hart' ],
+}, sub {
+ ok $mech->host("hart.fixmystreet.com"), "change host to hart";
+ $mech->get_ok('/');
+ $mech->content_like( qr/Hart\b/ );
+};
+
+done_testing();
diff --git a/t/cobrand/loading.t b/t/cobrand/loading.t
index bd83da07f..48a10293e 100644
--- a/t/cobrand/loading.t
+++ b/t/cobrand/loading.t
@@ -9,51 +9,92 @@ use FixMyStreet;
use_ok 'FixMyStreet::Cobrand';
# check that the allowed cobrands is correctly loaded from config
-{
+sub check_allowed_cobrands {
+ my $should = shift;
+ $should = [ map { { moniker => $_, host => $_ } } @$should ];
my $allowed = FixMyStreet::Cobrand->get_allowed_cobrands;
- ok $allowed, "got the allowed_cobrands";
+ ok $allowed, "got the allowed_cobrands";
isa_ok $allowed, "ARRAY";
- cmp_ok scalar @$allowed, '>', 1, "got more than one";
+ is_deeply $allowed, $should, "allowed_cobrands matched";
}
-# fake the allowed cobrands for testing
-my $override = Sub::Override->new( #
- 'FixMyStreet::Cobrand::_get_allowed_cobrands' =>
- sub { return ['emptyhomes'] }
-);
-is_deeply FixMyStreet::Cobrand->get_allowed_cobrands, [ { moniker => 'emptyhomes', host => 'emptyhomes' } ],
- 'overidden get_allowed_cobrands';
+FixMyStreet::override_config { ALLOWED_COBRANDS => 'fixmyhouse' },
+ sub { check_allowed_cobrands([ 'fixmyhouse' ]); };
+FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixmyhouse' ] },
+ sub { check_allowed_cobrands([ 'fixmyhouse' ]); };
+FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixmyhouse', 'fixmyshed' ] },
+ sub { check_allowed_cobrands([ 'fixmyhouse', 'fixmyshed' ]); };
sub run_host_tests {
my %host_tests = @_;
for my $host ( sort keys %host_tests ) {
- is FixMyStreet::Cobrand->get_class_for_host($host),
- "FixMyStreet::Cobrand::$host_tests{$host}",
- "does $host -> F::C::$host_tests{$host}";
+ # get the cobrand class by host
+ my $cobrand = FixMyStreet::Cobrand->get_class_for_host($host);
+ my $test_class = $host_tests{$host};
+ my $test_moniker = lc $test_class;
+ is $cobrand, "FixMyStreet::Cobrand::$test_class", "does $host -> F::C::$test_class";
+ my $c = $cobrand->new();
+ is $c->moniker, $test_moniker;
}
}
-# get the cobrand class by host
-run_host_tests(
- 'www.fixmystreet.com' => 'Default',
- 'reportemptyhomes.com' => 'EmptyHomes',
- 'barnet.fixmystreet.com' => 'Default', # not in the allowed_cobrands list
- 'some.odd.site.com' => 'Default',
-);
+# Only one cobrand, always use it
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+}, sub {
+ run_host_tests(
+ 'www.fixmystreet.com' => 'FixMyStreet',
+ 'reportemptyhomes.com' => 'FixMyStreet',
+ 'barnet.fixmystreet.com' => 'FixMyStreet',
+ 'some.odd.site.com' => 'FixMyStreet',
+ );
+};
+
+# Only one cobrand, no .pm file, should still work
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'nopmfile' ],
+}, sub {
+ run_host_tests(
+ 'www.fixmystreet.com' => 'nopmfile',
+ 'some.odd.site.com' => 'nopmfile',
+ );
+};
+
+# Couple of cobrands, hostname checking and default fallback
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'emptyhomes', 'fixmystreet' ],
+}, sub {
+ run_host_tests(
+ 'www.fixmystreet.com' => 'FixMyStreet',
+ 'reportemptyhomes.com' => 'EmptyHomes',
+ 'barnet.fixmystreet.com' => 'FixMyStreet', # not in the allowed_cobrands list
+ 'some.odd.site.com' => 'Default',
+ );
+};
# now enable barnet too and check that it works
-$override->replace( #
- 'FixMyStreet::Cobrand::_get_allowed_cobrands' =>
- sub { return [ 'emptyhomes', 'barnet' ] }
-);
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'emptyhomes', 'barnet', 'fixmystreet' ],
+}, sub {
+ run_host_tests(
+ 'www.fixmystreet.com' => 'FixMyStreet',
+ 'reportemptyhomes.com' => 'EmptyHomes',
+ 'barnet.fixmystreet.com' => 'Barnet', # found now it is in allowed_cobrands
+ 'some.odd.site.com' => 'Default',
+ );
+};
-# get the cobrand class by host
-run_host_tests(
- 'www.fixmystreet.com' => 'Default',
- 'reportemptyhomes.com' => 'EmptyHomes',
- 'barnet.fixmystreet.com' => 'Barnet', # found now it is in allowed_cobrands
- 'some.odd.site.com' => 'Default',
-);
+# And a check with some regex matching
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => 'empty' }, 'barnet', { 'testing' => 'fixmystreet' } ],
+}, sub {
+ run_host_tests(
+ 'www.fixmystreet.com' => 'testing',
+ 'reportemptyhomes.com' => 'FixMyStreet',
+ 'barnet.fixmystreet.com' => 'Barnet',
+ 'some.odd.site.com' => 'Default',
+ );
+};
# check that the moniker works as expected both on class and object.
is FixMyStreet::Cobrand::EmptyHomes->moniker, 'emptyhomes',
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
new file mode 100644
index 000000000..e97891b91
--- /dev/null
+++ b/t/cobrand/zurich.t
@@ -0,0 +1,685 @@
+# TODO
+# Overdue alerts
+
+use strict;
+use warnings;
+use DateTime;
+use Test::More;
+use JSON;
+
+# Check that you have the required locale installed - the following
+# should return a line with de_CH.utf8 in. If not install that locale.
+#
+# locale -a | grep de_CH
+#
+# To generate the translations use:
+#
+# commonlib/bin/gettext-makemo FixMyStreet
+
+use FixMyStreet;
+
+# This is a helper method that will send the reports but with the config
+# correctly set - notably SEND_REPORTS_ON_STAGING needs to be true.
+sub send_reports_for_zurich {
+ FixMyStreet::override_config { SEND_REPORTS_ON_STAGING => 1 }, sub {
+ # Actually send the report
+ FixMyStreet::App->model('DB::Problem')->send_reports('zurich');
+ };
+}
+sub reset_report_state {
+ my ($report, $created) = @_;
+ $report->discard_changes;
+ my $extra = $report->extra;
+ delete $extra->{moderated_overdue};
+ delete $extra->{subdiv_overdue};
+ delete $extra->{closed_overdue};
+ $report->update({
+ extra => { %$extra },
+ state => 'unconfirmed',
+ $created ? ( created => $created ) : (),
+ });
+}
+
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
+
+# Front page test
+ok $mech->host("zurich.example.com"), "change host to Zurich";
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok('/');
+};
+$mech->content_like( qr/zurich/i );
+
+# Set up bodies
+my $zurich = $mech->create_body_ok( 1, 'Zurich' );
+$zurich->parent( undef );
+$zurich->update;
+my $division = $mech->create_body_ok( 2, 'Division 1' );
+$division->parent( $zurich->id );
+$division->send_method( 'Zurich' );
+$division->endpoint( 'division@example.org' );
+$division->update;
+my $subdivision = $mech->create_body_ok( 3, 'Subdivision A' );
+$subdivision->parent( $division->id );
+$subdivision->send_method( 'Zurich' );
+$subdivision->endpoint( 'subdivision@example.org' );
+$subdivision->update;
+my $external_body = $mech->create_body_ok( 4, 'External Body' );
+$external_body->send_method( 'Zurich' );
+$external_body->endpoint( 'external_body@example.org' );
+$external_body->update;
+
+sub cleanup {
+ $mech->delete_problems_for_body( $division->id );
+ $mech->delete_problems_for_body( $subdivision->id );
+ $mech->delete_user( 'dm1@example.org' );
+ $mech->delete_user( 'sdm1@example.org' );
+}
+
+sub get_export_rows_count {
+ my $mech = shift;
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/stats?export=1' );
+ };
+ is $mech->res->code, 200, 'csv retrieved ok';
+ is $mech->content_type, 'text/csv', 'content_type correct' and do {
+ my @lines = split /\n/, $mech->content;
+ return @lines - 1;
+ };
+ return;
+}
+
+cleanup();
+
+my $EXISTING_REPORT_COUNT = 0;
+
+subtest "set up superuser" => sub {
+ my $superuser = $mech->log_in_ok( 'super@example.org' );
+ # a user from body $zurich is a superuser, as $zurich has no parent id!
+ $superuser->update({ from_body => $zurich->id });
+ $EXISTING_REPORT_COUNT = get_export_rows_count($mech);
+ $mech->log_out_ok;
+};
+
+my @reports = $mech->create_problems_for_body( 1, 2, 'Test', {
+ state => 'unconfirmed',
+ confirmed => undef,
+ cobrand => 'zurich',
+});
+my $report = $reports[0];
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/report/' . $report->id );
+};
+$mech->content_contains('&Uuml;berpr&uuml;fung ausstehend');
+
+# Check logging in to deal with this report
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/admin' );
+ is $mech->uri->path, '/auth', "got sent to the sign in page";
+
+ my $user = $mech->log_in_ok( 'dm1@example.org') ;
+ $user->from_body( undef );
+ $user->update;
+ $mech->get_ok( '/admin' );
+ is $mech->uri->path, '/my', "got sent to /my";
+ $user->from_body( 2 );
+ $user->update;
+
+ $mech->get_ok( '/admin' );
+};
+is $mech->uri->path, '/admin', "am logged in";
+
+$mech->content_contains( 'report_edit/' . $report->id );
+$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+$mech->content_contains( 'Erfasst' );
+
+
+subtest "changing of categories" => sub {
+ # create a few categories (which are actually contacts)
+ foreach my $name ( qw/Cat1 Cat2/ ) {
+ FixMyStreet::App->model('DB::Contact')->find_or_create({
+ body => $division,
+ category => $name,
+ email => "$name\@example.org",
+ confirmed => 1,
+ deleted => 0,
+ editor => "editor",
+ whenedited => DateTime->now(),
+ note => "note for $name",
+ });
+ }
+
+ # put report into known category
+ my $original_category = $report->category;
+ $report->update({ category => 'Cat1' });
+ is( $report->category, "Cat1", "Category set to Cat1" );
+
+ # get the latest comment
+ my $comments_rs = $report->comments->search({},{ order_by => { -desc => "created" } });
+ ok ( !$comments_rs->first, "There are no comments yet" );
+
+ # change the category via the web interface
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { category => 'Cat2' } } );
+ };
+
+ # check changes correctly saved
+ $report->discard_changes();
+ is( $report->category, "Cat2", "Category changed to Cat2 as expected" );
+
+ # Check that a new comment has been created.
+ my $new_comment = $comments_rs->first();
+ is( $new_comment->text, "Weitergeleitet von Cat1 an Cat2", "category change comment created" );
+
+ # restore report to original category.
+ $report->update({category => $original_category });
+};
+
+sub get_moderated_count {
+ # my %date_params = ( );
+ # my $moderated = FixMyStreet::App->model('DB::Problem')->search({
+ # extra => { like => '%moderated_overdue,I1:0%' }, %date_params } )->count;
+ # return $moderated;
+
+ # use a separate mech to avoid stomping on test state
+ my $mech = FixMyStreet::TestMech->new;
+ my $user = $mech->log_in_ok( 'super@example.org' );
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get( '/admin/stats' );
+ };
+ if ($mech->content =~/Innerhalb eines Arbeitstages moderiert: (\d+)/) {
+ return $1;
+ }
+ else {
+ fail sprintf "Could not get moderation results (%d)", $mech->status;
+ return undef;
+ }
+}
+
+subtest "report_edit" => sub {
+
+ ok ( ! exists ${$report->extra}{moderated_overdue}, 'Report currently unmoderated' );
+
+ is get_moderated_count(), 0;
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains( 'Unbest&auml;tigt' ); # Unconfirmed email
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+ $mech->get_ok( '/report/' . $report->id );
+ };
+
+ $mech->content_contains('Aufgenommen');
+ $mech->content_contains('Test Test');
+ $mech->content_lacks('photo/' . $report->id . '.jpeg');
+ $mech->email_count_is(0);
+
+ $report->discard_changes;
+
+ is ( $report->extra->{moderated_overdue}, 0, 'Report now marked moderated' );
+ is get_moderated_count(), 1;
+
+
+ # Set state back to 10 days ago so that report is overdue
+ my $created = $report->created;
+ reset_report_state($report, $created->clone->subtract(days => 10));
+
+ is get_moderated_count(), 0;
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+ $mech->get_ok( '/report/' . $report->id );
+ };
+ $report->discard_changes;
+ is ( $report->extra->{moderated_overdue}, 1, 'moderated_overdue set correctly when overdue' );
+ is get_moderated_count(), 0, 'Moderated count not increased when overdue';
+
+ reset_report_state($report, $created);
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );
+ $mech->get_ok( '/report/' . $report->id );
+ };
+ $report->discard_changes;
+ is ( $report->extra->{moderated_overdue}, 0, 'Marking confirmed sets moderated_overdue' );
+ is ( $report->extra->{closed_overdue}, undef, 'Marking confirmed does NOT set closed_overdue' );
+ is get_moderated_count(), 1;
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'hidden' } } );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ };
+ $report->discard_changes;
+ is ( $report->extra->{moderated_overdue}, 0, 'Still marked moderated_overdue' );
+ is ( $report->extra->{closed_overdue}, 0, 'Marking hidden also set closed_overdue' );
+ is get_moderated_count(), 1, 'Check still counted moderated'
+ or diag $report->get_column('extra');
+
+ reset_report_state($report);
+
+ is ( $report->extra->{moderated_overdue}, undef, 'Sanity check' );
+ is get_moderated_count(), 0;
+
+ # Check that setting to 'hidden' also triggers moderation
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'hidden' } } );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ };
+ $report->discard_changes;
+ is ( $report->extra->{moderated_overdue}, 0, 'Marking hidden from scratch sets moderated_overdue' );
+ is ( $report->extra->{closed_overdue}, 0, 'Marking hidden from scratch also set closed_overdue' );
+ is get_moderated_count(), 1;
+
+ is (FixMyStreet::Cobrand::Zurich->new->get_or_check_overdue($report), 0, 'sanity check');
+ $report->update({ created => $created->clone->subtract(days => 10) });
+ is (FixMyStreet::Cobrand::Zurich->new->get_or_check_overdue($report), 0, 'overdue call not increased');
+
+ reset_report_state($report, $created);
+};
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ # Photo publishing
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'confirmed', publish_photo => 1 } } );
+ $mech->get_ok( '/report/' . $report->id );
+ $mech->content_contains('photo/' . $report->id . '.jpeg');
+
+ # Internal notes
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { new_internal_note => 'Initial internal note.' } } );
+ $mech->submit_form_ok( { with_fields => { new_internal_note => 'Another internal note.' } } );
+ $mech->content_contains( 'Initial internal note.' );
+ $mech->content_contains( 'Another internal note.' );
+
+ # Original description
+ $mech->submit_form_ok( { with_fields => { detail => 'Edited details text.' } } );
+ $mech->content_contains( 'Edited details text.' );
+ $mech->content_contains( 'Originaltext: &ldquo;Test Test 1 for 2 Detail&rdquo;' );
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { body_subdivision => 3, send_rejected_email => 1 } } );
+
+ $mech->get_ok( '/report/' . $report->id );
+ $mech->content_contains('In Bearbeitung');
+ $mech->content_contains('Test Test');
+};
+
+send_reports_for_zurich();
+my $email = $mech->get_email;
+like $email->header('Subject'), qr/Neue Meldung/, 'subject looks okay';
+like $email->header('To'), qr/subdivision\@example.org/, 'to line looks correct';
+$mech->clear_emails_ok;
+
+$mech->log_out_ok;
+
+my $user = $mech->log_in_ok( 'sdm1@example.org') ;
+$user->update({ from_body => undef });
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/admin' );
+};
+is $mech->uri->path, '/my', "got sent to /my";
+$user->from_body( 3 );
+$user->update;
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/admin' );
+};
+is $mech->uri->path, '/admin', "am logged in";
+
+$mech->content_contains( 'report_edit/' . $report->id );
+$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+$mech->content_contains( 'In Bearbeitung' );
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains( 'Initial internal note' );
+
+ $mech->submit_form_ok( { with_fields => { status_update => 'This is an update.' } } );
+ is $mech->uri->path, '/admin/report_edit/' . $report->id, "still on edit page";
+ $mech->content_contains('This is an update');
+ ok $mech->form_with_fields( 'status_update' );
+ $mech->submit_form_ok( { button => 'no_more_updates' } );
+ is $mech->uri->path, '/admin/summary', "redirected now finished with report.";
+
+ $mech->get_ok( '/report/' . $report->id );
+ $mech->content_contains('In Bearbeitung');
+ $mech->content_contains('Test Test');
+};
+
+send_reports_for_zurich();
+$email = $mech->get_email;
+like $email->header('Subject'), qr/Feedback/, 'subject looks okay';
+like $email->header('To'), qr/division\@example.org/, 'to line looks correct';
+$mech->clear_emails_ok;
+
+$report->discard_changes;
+is $report->state, 'planned', 'Report now in planned state';
+
+$mech->log_out_ok;
+$user = $mech->log_in_ok( 'dm1@example.org') ;
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/admin' );
+};
+
+$mech->content_contains( 'report_edit/' . $report->id );
+$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
+
+# User confirms their email address
+my $extra = $report->extra;
+$extra->{email_confirmed} = 1;
+$report->extra ( { %$extra } );
+$report->update;
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_lacks( 'Unbest&auml;tigt' ); # Confirmed email
+ $mech->submit_form_ok( { with_fields => { status_update => 'FINAL UPDATE' } } );
+ $mech->form_with_fields( 'status_update' );
+ $mech->submit_form_ok( { button => 'publish_response' } );
+
+ $mech->get_ok( '/report/' . $report->id );
+};
+$mech->content_contains('Beantwortet');
+$mech->content_contains('Test Test');
+$mech->content_contains('FINAL UPDATE');
+
+$email = $mech->get_email;
+like $email->header('To'), qr/test\@example.com/, 'to line looks correct';
+like $email->header('From'), qr/division\@example.org/, 'from line looks correct';
+like $email->body, qr/FINAL UPDATE/, 'body looks correct';
+$mech->clear_emails_ok;
+
+# Assign directly to planned, don't confirm email
+@reports = $mech->create_problems_for_body( 1, 2, 'Second', {
+ state => 'unconfirmed',
+ confirmed => undef,
+ cobrand => 'zurich',
+});
+$report = $reports[0];
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'planned' } } );
+ $mech->get_ok( '/report/' . $report->id );
+};
+$mech->content_contains('In Bearbeitung');
+$mech->content_contains('Second Test');
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains( 'Unbest&auml;tigt' );
+ $mech->submit_form_ok( { button => 'publish_response', with_fields => { status_update => 'FINAL UPDATE' } } );
+
+ $mech->get_ok( '/report/' . $report->id );
+};
+$mech->content_contains('Beantwortet');
+$mech->content_contains('Second Test');
+$mech->content_contains('FINAL UPDATE');
+
+$mech->email_count_is(0);
+
+# Report assigned to third party
+
+@reports = $mech->create_problems_for_body( 1, 2, 'Third', {
+ state => 'unconfirmed',
+ confirmed => undef,
+ cobrand => 'zurich',
+});
+$report = $reports[0];
+
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { body_external => 4 } } );
+ $mech->get_ok( '/report/' . $report->id );
+};
+$mech->content_contains('Beantwortet');
+$mech->content_contains('Third Test');
+$mech->content_contains('Wir haben Ihr Anliegen an External Body weitergeleitet');
+send_reports_for_zurich();
+$email = $mech->get_email;
+like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay';
+like $email->header('To'), qr/external_body\@example.org/, 'to line looks correct';
+like $email->body, qr/External Body/, 'body has right name';
+unlike $email->body, qr/test\@example.com/, 'body does not contain email address';
+$mech->clear_emails_ok;
+
+# Test calling back, and third_personal boolean setting
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+}, sub {
+ $mech->get_ok( '/admin' );
+ is $mech->uri->path, '/admin', "am logged in";
+ $mech->content_contains( 'report_edit/' . $report->id );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'unconfirmed' } } );
+ $mech->submit_form_ok( { with_fields => { body_external => 4, third_personal => 1 } } );
+ $mech->get_ok( '/report/' . $report->id );
+};
+$mech->content_contains('Beantwortet');
+$mech->content_contains('Third Test');
+$mech->content_contains('Wir haben Ihr Anliegen an External Body weitergeleitet');
+send_reports_for_zurich();
+$email = $mech->get_email;
+like $email->header('Subject'), qr/Weitergeleitete Meldung/, 'subject looks okay';
+like $email->header('To'), qr/external_body\@example.org/, 'to line looks correct';
+like $email->body, qr/External Body/, 'body has right name';
+like $email->body, qr/test\@example.com/, 'body does contain email address';
+$mech->clear_emails_ok;
+$mech->log_out_ok;
+
+subtest "only superuser can see stats" => sub {
+ $user = $mech->log_in_ok( 'super@example.org' );
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get( '/admin/stats' );
+ };
+ is $mech->res->code, 200, "superuser should be able to see stats page";
+ $mech->log_out_ok;
+
+ $user = $mech->log_in_ok( 'dm1@example.org' );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get( '/admin/stats' );
+ };
+ is $mech->res->code, 404, "only superuser should be able to see stats page";
+ $mech->log_out_ok;
+};
+
+subtest "only superuser can edit bodies" => sub {
+ $user = $mech->log_in_ok( 'dm1@example.org' );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get( '/admin/body/' . $zurich->id );
+ };
+ is $mech->res->code, 404, "only superuser should be able to edit bodies";
+ $mech->log_out_ok;
+};
+
+subtest "only superuser can see 'Add body' form" => sub {
+ $user = $mech->log_in_ok( 'dm1@example.org' );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ MAPIT_URL => 'http://global.mapit.mysociety.org/',
+ MAPIT_TYPES => [ 'O08' ],
+ MAPIT_ID_WHITELIST => [ 423017 ],
+ }, sub {
+ $mech->get_ok( '/admin/bodies' );
+ };
+ $mech->content_lacks( '<form method="post" action="bodies"' );
+ $mech->log_out_ok;
+};
+
+subtest "phone number is mandatory" => sub {
+ FixMyStreet::override_config {
+ MAPIT_TYPES => [ 'O08' ],
+ MAPIT_URL => 'http://global.mapit.mysociety.org/',
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ MAPIT_ID_WHITELIST => [ 423017 ],
+ }, sub {
+ $user = $mech->log_in_ok( 'dm1@example.org' );
+ $mech->get_ok( '/report/new?lat=47.381817&lon=8.529156' );
+ $mech->submit_form( with_fields => { phone => "" } );
+ $mech->content_contains( 'Diese Information wird ben&ouml;tigt' );
+ $mech->log_out_ok;
+ };
+};
+
+subtest "phone number is not mandatory for reports from mobile apps" => sub {
+ FixMyStreet::override_config {
+ MAPIT_TYPES => [ 'O08' ],
+ MAPIT_URL => 'http://global.mapit.mysociety.org/',
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ MAPIT_ID_WHITELIST => [ 423017 ],
+ }, sub {
+ $mech->post_ok( '/report/new/mobile?lat=47.381817&lon=8.529156' , {
+ service => 'iPhone',
+ detail => 'Problem-Bericht',
+ lat => 47.381817,
+ lon => 8.529156,
+ email => 'user@example.org',
+ pc => '',
+ name => '',
+ category => 'bad category',
+ });
+ my $res = $mech->response;
+ ok $res->header('Content-Type') =~ m{^application/json\b}, 'response should be json';
+ unlike $res->content, qr/Diese Information wird ben&ouml;tigt/, 'response should not contain phone error';
+ # Clear out the mailq
+ $mech->clear_emails_ok;
+ };
+};
+
+subtest "problems can't be assigned to deleted bodies" => sub {
+ $user = $mech->log_in_ok( 'dm1@example.org' );
+ $user->from_body( 1 );
+ $user->update;
+ $report->state( 'confirmed' );
+ $report->update;
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ MAPIT_URL => 'http://global.mapit.mysociety.org/',
+ MAPIT_TYPES => [ 'O08' ],
+ MAPIT_ID_WHITELIST => [ 423017 ],
+ }, sub {
+ $mech->get_ok( '/admin/body/' . $external_body->id );
+ $mech->submit_form_ok( { with_fields => { deleted => 1 } } );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_lacks( $external_body->name );
+ };
+ $user->from_body( 2 );
+ $user->update;
+ $mech->log_out_ok;
+};
+
+subtest "hidden report email are only sent when requested" => sub {
+ $user = $mech->log_in_ok( 'dm1@example.org') ;
+ $extra = $report->extra;
+ $extra->{email_confirmed} = 1;
+ $report->extra ( { %$extra } );
+ $report->update;
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'hidden', send_rejected_email => 1 } } );
+ $mech->email_count_is(1);
+ $mech->clear_emails_ok;
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { state => 'hidden', send_rejected_email => undef } } );
+ $mech->email_count_is(0);
+ $mech->clear_emails_ok;
+ $mech->log_out_ok;
+ };
+};
+
+subtest "test stats" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ }, sub {
+ $user = $mech->log_in_ok( 'super@example.org' );
+
+ $mech->get_ok( '/admin/stats' );
+ is $mech->res->code, 200, "superuser should be able to see stats page";
+
+ $mech->content_contains('Innerhalb eines Arbeitstages moderiert: 2'); # now including hidden
+ $mech->content_contains('Innerhalb von f&uuml;nf Arbeitstagen abgeschlossen: 3');
+ # my @data = $mech->content =~ /(?:moderiert|abgeschlossen): \d+/g;
+ # diag Dumper(\@data); use Data::Dumper;
+
+ my $export_count = get_export_rows_count($mech);
+ if (defined $export_count) {
+ is $export_count - $EXISTING_REPORT_COUNT, 3, 'Correct number of reports';
+ $mech->content_contains(',fixed - council,');
+ $mech->content_contains(',hidden,');
+ }
+
+ $mech->log_out_ok;
+ };
+};
+
+subtest "test admin_log" => sub {
+ diag $report->id;
+ my @entries = FixMyStreet::App->model('DB::AdminLog')->search({
+ object_type => 'problem',
+ object_id => $report->id,
+ });
+ is scalar @entries, 4, 'State changes logged';
+ is $entries[-1]->action, 'state change to hidden', 'State change logged as expected';
+};
+
+cleanup();
+
+ok $mech->host("www.fixmystreet.com"), "change host back";
+
+done_testing();
diff --git a/t/i18n.t b/t/i18n.t
index f1cc86985..3337f1a7f 100644
--- a/t/i18n.t
+++ b/t/i18n.t
@@ -3,15 +3,12 @@ use warnings;
use Test::More;
-use FixMyStreet;
-use mySociety::Locale;
-use Encode;
-use Data::Dumper;
use HTTP::Headers;
use Sort::Key qw(keysort);
use POSIX 'strcoll';
-local $Data::Dumper::Sortkeys = 1;
-use utf8;
+
+use FixMyStreet;
+use mySociety::Locale;
# check that the mo files have been generated
die "You need to run 'commonlib/bin/gettext-makemo --quiet FixMyStreet' "
@@ -59,10 +56,6 @@ my @EN_sorted = qw( A Å Ø Z );
my @NO_sorted = qw( A Z Ø Å );
my @default_sorted = qw( A Z Å Ø );
-sub utf8_diag {
- diag encode_utf8( Dumper(@_) );
-}
-
{
mySociety::Locale::negotiate_language( #
diff --git a/t/map/tilma/original.t b/t/map/tilma/original.t
index 04c4d578c..9e296686d 100644
--- a/t/map/tilma/original.t
+++ b/t/map/tilma/original.t
@@ -9,16 +9,14 @@ use FixMyStreet::TestMech;
use DateTime;
use mySociety::Locale;
+use Catalyst::Test 'FixMyStreet::App';
+
my $mech = FixMyStreet::TestMech->new;
mySociety::Locale::gettext_domain('FixMyStreet');
FixMyStreet::Map::set_map_class();
-my $r = Catalyst::Request->new( { base => URI->new('/'), uri => URI->new('http://fixmystreet.com/test'), parameters => { bbox => '-7.6,49.7,-7.5,49.8' } } );
-
-my $c = FixMyStreet::App->new( {
- request => $r,
-});
+my $c = ctx_request('http://fixmystreet.com/test?bbox=-7.6,49.7,-7.5,49.8');
$mech->delete_user('test@example.com');
my $user =
@@ -32,7 +30,7 @@ my $dt = DateTime->now();
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',
@@ -71,10 +69,26 @@ for my $test (
colour => 'yellow',
},
{
+ state => 'duplicate',
+ colour => 'yellow',
+ },
+ {
+ state => 'unable to fix',
+ colour => 'yellow',
+ },
+ {
+ state => 'not responsible',
+ colour => 'yellow',
+ },
+ {
state => 'investigating',
colour => 'yellow',
},
{
+ state => 'action scheduled',
+ colour => 'yellow',
+ },
+ {
state => 'planned',
colour => 'yellow',
},
diff --git a/t/open311.t b/t/open311.t
index 2371c53bc..f23198ea5 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -38,6 +38,8 @@ my $p = FixMyStreet::App->model('DB::Problem')->new( {
detail => 'detail',
user => $u,
id => 1,
+ name => 'A User',
+ cobrand => 'fixmystreet',
} );
my $expected_error = qr{Failed to submit problem 1 over Open311}ism;
@@ -61,11 +63,14 @@ my $problem = FixMyStreet::App->model('DB::Problem')->new( {
latitude => 1,
longitude => 2,
user => $user,
+ name => 'Test User',
+ cobrand => 'fixmystreet',
} );
subtest 'posting service request' => sub {
my $extra = {
url => 'http://example.com/report/1',
+ easting_northing => 'SET',
};
my $results = make_service_req( $problem, $extra, $problem->category, '<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>' );
@@ -86,13 +91,14 @@ EOT
;
my $c = CGI::Simple->new( $results->{ req }->content );
+ (my $c_description = $c->param('description')) =~ s/\r\n/\n/g;
is $c->param('email'), $user->email, 'correct email';
is $c->param('first_name'), 'Test', 'correct first name';
is $c->param('last_name'), 'User', 'correct last name';
is $c->param('lat'), 1, 'latitide correct';
is $c->param('long'), 2, 'longitude correct';
- is $c->param('description'), $description, 'description correct';
+ is $c_description, $description, 'description correct';
is $c->param('service_code'), 'pothole', 'service code correct';
};
@@ -106,7 +112,7 @@ subtest 'posting service request with basic_description' => sub {
$extra,
$problem->category,
'<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>',
- { basic_description => 1 },
+ { extended_description => 0 },
);
is $results->{ res }, 248, 'got request id';
@@ -151,7 +157,7 @@ for my $test (
],
},
{
- title => 'magic fms_extra parameters handled correctly',
+ desc => 'magic fms_extra parameters handled correctly',
extra => [
{
name => 'fms_extra_title',
@@ -185,6 +191,31 @@ for my $test (
};
}
+for my $test (
+ {
+ desc => 'Check uses report name over user name',
+ name => 'Nom de Report',
+ first_name => 'Nom',
+ last_name => 'de Report',
+ },
+) {
+ subtest $test->{desc} => sub {
+ $problem->extra( undef );
+ $problem->name( $test->{name} );
+ my $extra = { url => 'http://example.com/report/1', };
+
+ my $results = make_service_req( $problem, $extra, $problem->category,
+'<?xml version="1.0" encoding="utf-8"?><service_requests><request><service_request_id>248</service_request_id></request></service_requests>'
+ );
+ my $req = $o->test_req_used;
+ my $c = CGI::Simple->new( $results->{req}->content );
+
+ is $c->param( 'first_name' ), $test->{first_name}, 'correct first name';
+ is $c->param( 'last_name' ), $test->{last_name}, 'correct last name';
+ };
+}
+
+
my $comment = FixMyStreet::App->model('DB::Comment')->new( {
id => 38362,
user => $user,
@@ -192,6 +223,7 @@ my $comment = FixMyStreet::App->model('DB::Comment')->new( {
anonymous => 0,
text => 'this is a comment',
confirmed => $dt,
+ problem_state => 'confirmed',
extra => { title => 'Mr', email_alerts_requested => 0 },
} );
@@ -216,7 +248,7 @@ subtest 'basic request update post parameters' => sub {
};
subtest 'extended request update post parameters' => sub {
- my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', 1 );
+ my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', { use_extended_updates => 1 } );
is $results->{ res }, 248, 'got update id';
@@ -258,16 +290,47 @@ foreach my $test (
desc => 'comment with fixed state sends status of CLOSED',
state => 'fixed',
status => 'CLOSED',
+ extended => 'FIXED',
},
{
desc => 'comment with fixed - user state sends status of CLOSED',
state => 'fixed - user',
status => 'CLOSED',
+ extended => 'FIXED',
},
{
desc => 'comment with fixed - council state sends status of CLOSED',
state => 'fixed - council',
status => 'CLOSED',
+ extended => 'FIXED',
+ },
+ {
+ desc => 'comment with duplicate state sends status of CLOSED',
+ state => 'duplicate',
+ anon => 0,
+ status => 'CLOSED',
+ extended => 'DUPLICATE',
+ },
+ {
+ desc => 'comment with not reponsible state sends status of CLOSED',
+ state => 'not responsible',
+ anon => 0,
+ status => 'CLOSED',
+ extended => 'NOT_COUNCILS_RESPONSIBILITY',
+ },
+ {
+ desc => 'comment with unable to fix state sends status of CLOSED',
+ state => 'unable to fix',
+ anon => 0,
+ status => 'CLOSED',
+ extended => 'NO_FURTHER_ACTION',
+ },
+ {
+ desc => 'comment with internal referral state sends status of CLOSED',
+ state => 'internal referral',
+ anon => 0,
+ status => 'CLOSED',
+ extended => 'INTERNAL_REFERRAL',
},
{
desc => 'comment with closed state sends status of CLOSED',
@@ -278,29 +341,42 @@ foreach my $test (
desc => 'comment with investigating state sends status of OPEN',
state => 'investigating',
status => 'OPEN',
+ extended => 'INVESTIGATING',
},
{
desc => 'comment with planned state sends status of OPEN',
state => 'planned',
status => 'OPEN',
+ extended => 'ACTION_SCHEDULED',
},
{
- desc => 'comment with in progress state sends status of OPEN',
- state => 'in progress',
+ desc => 'comment with action scheduled state sends status of OPEN',
+ state => 'action scheduled',
+ anon => 0,
status => 'OPEN',
+ extended => 'ACTION_SCHEDULED',
},
{
- state => 'confirmed',
+ desc => 'comment with in progress state sends status of OPEN',
+ state => 'in progress',
status => 'OPEN',
+ extended => 'IN_PROGRESS',
},
) {
subtest $test->{desc} => sub {
+ $comment->problem_state( $test->{state} );
$comment->problem->state( $test->{state} );
my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' );
my $c = CGI::Simple->new( $results->{ req }->content );
is $c->param('status'), $test->{status}, 'correct status';
+
+ if ( $test->{extended} ) {
+ my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', { extended_statuses => 1 } );
+ my $c = CGI::Simple->new( $results->{ req }->content );
+ is $c->param('status'), $test->{extended}, 'correct extended status';
+ }
};
}
@@ -319,16 +395,70 @@ for my $test (
},
) {
subtest $test->{desc} => sub {
+ $comment->problem_state( $test->{state} );
$comment->problem->state( $test->{state} );
$comment->anonymous( $test->{anon} );
- my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', 1 );
+ my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', { use_extended_updates => 1 } );
my $c = CGI::Simple->new( $results->{ req }->content );
is $c->param('public_anonymity_required'), $test->{anon} ? 'TRUE' : 'FALSE', 'correct anonymity';
};
}
+my $dt2 = $dt->clone;
+$dt2->add( 'minutes' => 1 );
+
+my $comment2 = FixMyStreet::App->model('DB::Comment')->new( {
+ id => 38363,
+ user => $user,
+ problem => $problem,
+ anonymous => 0,
+ text => 'this is a comment',
+ confirmed => $dt,
+ problem_state => 'confirmed',
+ extra => { title => 'Mr', email_alerts_requested => 0 },
+} );
+
+for my $test (
+ {
+ desc => 'comment with fixed - council state sends status of CLOSED even if problem is open',
+ state => 'fixed - council',
+ problem_state => 'confirmed',
+ status => 'CLOSED',
+ extended => 'FIXED',
+ },
+ {
+ desc => 'comment marked open sends status of OPEN even if problem is closed',
+ state => 'confirmed',
+ problem_state => 'fixed - council',
+ status => 'OPEN',
+ extended => 'OPEN',
+ },
+ {
+ desc => 'comment with no problem state falls back to report state',
+ state => '',
+ problem_state => 'fixed - council',
+ status => 'CLOSED',
+ extended => 'FIXED',
+ },
+) {
+ subtest $test->{desc} => sub {
+ $comment->problem_state( $test->{state} );
+ $comment->problem->state( $test->{problem_state} );
+ my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' );
+
+ my $c = CGI::Simple->new( $results->{ req }->content );
+ is $c->param('status'), $test->{status}, 'correct status';
+
+ if ( $test->{extended} ) {
+ my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>', { extended_statuses => 1 } );
+ my $c = CGI::Simple->new( $results->{ req }->content );
+ is $c->param('status'), $test->{extended}, 'correct extended status';
+ }
+ };
+}
+
for my $test (
{
@@ -539,18 +669,16 @@ done_testing();
sub make_update_req {
my $comment = shift;
my $xml = shift;
- my $extended = shift;
+ my $open311_args = shift || {};
my $params = {
- object => $comment,
- xml => $xml,
- method => 'post_service_request_update',
- path => 'servicerequestupdates.xml',
+ object => $comment,
+ xml => $xml,
+ method => 'post_service_request_update',
+ path => 'servicerequestupdates.xml',
+ open311_conf => $open311_args,
};
- if ( $extended ) {
- $params->{ open311_conf } = { use_extended_updates => 1 };
- }
return make_req( $params );
}
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index aba811e58..00c25a83e 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -13,6 +13,7 @@ use_ok( 'Open311' );
use_ok( 'Open311::GetServiceRequestUpdates' );
use DateTime;
+use DateTime::Format::W3CDTF;
use FixMyStreet::App;
my $user = FixMyStreet::App->model('DB::User')->find_or_create(
@@ -123,7 +124,7 @@ my $problem = $problem_rs->new(
lastupdate => DateTime->now()->subtract( days => 1 ),
anonymous => 1,
external_id => time(),
- council => 2482,
+ bodies_str => 2482,
}
);
@@ -131,71 +132,212 @@ $problem->insert;
for my $test (
{
- desc => 'element with content',
- updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ),
+ desc => 'OPEN status for confirmed problem does not change state',
description => 'This is a note',
external_id => 638344,
start_state => 'confirmed',
- close_comment => 0,
+ comment_status => 'OPEN',
mark_fixed=> 0,
mark_open => 0,
problem_state => undef,
end_state => 'confirmed',
},
{
- desc => 'comment closes report',
- updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ),
+ desc => 'bad state does not update states but does create update',
description => 'This is a note',
external_id => 638344,
start_state => 'confirmed',
- close_comment => 1,
+ comment_status => 'INVALID_STATE',
+ mark_fixed=> 0,
+ mark_open => 0,
+ problem_state => undef,
+ end_state => 'confirmed',
+ },
+
+ {
+ desc => 'investigating status changes problem status',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'confirmed',
+ comment_status => 'INVESTIGATING',
+ mark_fixed=> 0,
+ mark_open => 0,
+ problem_state => 'investigating',
+ end_state => 'investigating',
+ },
+ {
+ desc => 'in progress status changes problem status',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'confirmed',
+ comment_status => 'IN_PROGRESS',
+ mark_fixed=> 0,
+ mark_open => 0,
+ problem_state => 'in progress',
+ end_state => 'in progress',
+ },
+ {
+ desc => 'action scheduled status changes problem status',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'confirmed',
+ comment_status => 'ACTION_SCHEDULED',
+ mark_fixed=> 0,
+ mark_open => 0,
+ problem_state => 'action scheduled',
+ end_state => 'action scheduled',
+ },
+ {
+ desc => 'not responsible status changes problem status',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'confirmed',
+ comment_status => 'NOT_COUNCILS_RESPONSIBILITY',
+ mark_fixed=> 0,
+ mark_open => 0,
+ problem_state => 'not responsible',
+ end_state => 'not responsible',
+ },
+ {
+ desc => 'internal referral status changes problem status',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'confirmed',
+ comment_status => 'INTERNAL_REFERRAL',
+ mark_fixed=> 0,
+ mark_open => 0,
+ problem_state => 'internal referral',
+ end_state => 'internal referral',
+ },
+ {
+ desc => 'duplicate status changes problem status',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'confirmed',
+ comment_status => 'DUPLICATE',
+ mark_fixed=> 0,
+ mark_open => 0,
+ problem_state => 'duplicate',
+ end_state => 'duplicate',
+ },
+ {
+ desc => 'fixed status marks report as fixed - council',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'confirmed',
+ comment_status => 'FIXED',
mark_fixed=> 0,
mark_open => 0,
problem_state => 'fixed - council',
end_state => 'fixed - council',
},
{
- desc => 'comment re-opens fixed report',
- updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ),
+ desc => 'status of CLOSED marks report as fixed - council',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'confirmed',
+ comment_status => 'CLOSED',
+ mark_fixed=> 0,
+ mark_open => 0,
+ problem_state => 'fixed - council',
+ end_state => 'fixed - council',
+ },
+ {
+ desc => 'status of OPEN re-opens fixed report',
description => 'This is a note',
external_id => 638344,
start_state => 'fixed - user',
- close_comment => 0,
+ comment_status => 'OPEN',
mark_fixed => 0,
mark_open => 0,
problem_state => 'confirmed',
end_state => 'confirmed',
},
{
- desc => 'comment re-opens closed report',
- updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ),
+ desc => 'action sheduled re-opens fixed report as action scheduled',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'fixed - user',
+ comment_status => 'ACTION_SCHEDULED',
+ mark_fixed => 0,
+ mark_open => 0,
+ problem_state => 'action scheduled',
+ end_state => 'action scheduled',
+ },
+ {
+ desc => 'open status re-opens closed report',
description => 'This is a note',
external_id => 638344,
- start_state => 'closed',
- close_comment => 0,
+ start_state => 'not responsible',
+ comment_status => 'OPEN',
mark_fixed => 0,
mark_open => 0,
problem_state => 'confirmed',
end_state => 'confirmed',
},
{
- desc => 'comment leaves report closed',
- updated_datetime => sprintf( '<updated_datetime>%s</updated_datetime>', $dt ),
+ desc => 'fixed status leaves fixed - user report as fixed - user',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'fixed - user',
+ comment_status => 'FIXED',
+ mark_fixed => 0,
+ mark_open => 0,
+ problem_state => undef,
+ end_state => 'fixed - user',
+ },
+ {
+ desc => 'closed status updates fixed report',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'fixed - user',
+ comment_status => 'NO_FURTHER_ACTION',
+ mark_fixed => 0,
+ mark_open => 0,
+ problem_state => 'unable to fix',
+ end_state => 'unable to fix',
+ },
+ {
+ desc => 'no futher action status closes report',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'confirmed',
+ comment_status => 'NO_FURTHER_ACTION',
+ mark_fixed => 0,
+ mark_open => 0,
+ problem_state => 'unable to fix',
+ end_state => 'unable to fix',
+ },
+ {
+ desc => 'fixed status sets closed report as fixed',
+ description => 'This is a note',
+ external_id => 638344,
+ start_state => 'unable to fix',
+ comment_status => 'FIXED',
+ mark_fixed => 0,
+ mark_open => 0,
+ problem_state => 'fixed - council',
+ end_state => 'fixed - council',
+ },
+ {
+ desc => 'open status does not re-open hidden report',
description => 'This is a note',
external_id => 638344,
- start_state => 'closed',
- close_comment => 1,
+ start_state => 'hidden',
+ comment_status => 'OPEN',
mark_fixed => 0,
mark_open => 0,
- end_state => 'closed',
+ problem_state => 'confirmed',
+ end_state => 'hidden',
},
) {
subtest $test->{desc} => sub {
my $local_requests_xml = $requests_xml;
- $local_requests_xml =~ s/UPDATED_DATETIME/$test->{updated_datetime}/;
+ my $updated_datetime = sprintf( '<updated_datetime>%s</updated_datetime>', $dt );
+ $local_requests_xml =~ s/UPDATED_DATETIME/$updated_datetime/;
$local_requests_xml =~ s#<service_request_id>\d+</service_request_id>#<service_request_id>@{[$problem->external_id]}</service_request_id>#;
$local_requests_xml =~ s#<service_request_id_ext>\d+</service_request_id_ext>#<service_request_id_ext>@{[$problem->id]}</service_request_id_ext>#;
- $local_requests_xml =~ s#<status>\w+</status>#<status>closed</status># if $test->{close_comment};
+ $local_requests_xml =~ s#<status>\w+</status>#<status>$test->{comment_status}</status># if $test->{comment_status};
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );
@@ -204,7 +346,7 @@ for my $test (
$problem->state( $test->{start_state} );
$problem->update;
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
$update->update_comments( $o, $council_details );
@@ -234,7 +376,8 @@ foreach my $test (
$dt->subtract( minutes => 10 );
my $local_requests_xml = $requests_xml;
- my $updated = sprintf( '<updated_datetime>%s</updated_datetime>', $dt );
+ my $updated = sprintf( '<updated_datetime>%s</updated_datetime>', DateTime::Format::W3CDTF->format_datetime( $dt ) );
+
$local_requests_xml =~ s/UPDATED_DATETIME/$updated/;
$local_requests_xml =~ s#<service_request_id>\d+</service_request_id>#<service_request_id>@{[$problem->external_id]}</service_request_id>#;
$local_requests_xml =~ s#<service_request_id_ext>\d+</service_request_id_ext>#<service_request_id_ext>@{[$problem->id]}</service_request_id_ext>#;
@@ -243,7 +386,7 @@ foreach my $test (
$problem->comments->delete;
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
$update->update_comments( $o, $council_details );
@@ -273,7 +416,7 @@ my $problem2 = $problem_rs->new(
lastupdate => DateTime->now(),
anonymous => 1,
external_id => $problem->external_id,
- council => 2651,
+ bodies_str => 2651,
}
);
@@ -312,7 +455,7 @@ for my $test (
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );
- my $council_details = { areaid => $test->{area_id} };
+ my $council_details = { areas => { $test->{area_id} => 1 } };
my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
$update->update_comments( $o, $council_details );
@@ -352,7 +495,7 @@ subtest 'using start and end date' => sub {
end_date => $end_dt,
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
my $start = $start_dt . '';
@@ -412,7 +555,7 @@ subtest 'check that existing comments are not duplicated' => sub {
system_user => $user,
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
$problem->discard_changes;
@@ -473,7 +616,7 @@ foreach my $test ( {
system_user => $user,
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
$problem->discard_changes;
@@ -484,10 +627,22 @@ foreach my $test ( {
foreach my $test ( {
desc => 'normally alerts are not suppressed',
+ num_alerts => 1,
suppress_alerts => 0,
},
{
desc => 'alerts suppressed if suppress_alerts set',
+ num_alerts => 1,
+ suppress_alerts => 1,
+ },
+ {
+ desc => 'alert suppression ok even if no alerts',
+ num_alerts => 0,
+ suppress_alerts => 1,
+ },
+ {
+ desc => 'alert suppression ok even if 2x alerts',
+ num_alerts => 2,
suppress_alerts => 1,
}
) {
@@ -509,12 +664,14 @@ foreach my $test ( {
$problem->lastupdate( $dt->subtract( hours => 3 ) );
$problem->update;
- my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( {
- alert_type => 'new_updates',
- parameter => $problem->id,
- confirmed => 1,
- user_id => $problem->user->id,
- } );
+ my @alerts = map {
+ my $alert = FixMyStreet::App->model('DB::Alert')->create( {
+ alert_type => 'new_updates',
+ parameter => $problem->id,
+ confirmed => 1,
+ user_id => $problem->user->id,
+ } )
+ } (1..$test->{num_alerts});
$requests_xml =~ s/UPDATED_DATETIME/$dt/;
@@ -525,25 +682,27 @@ foreach my $test ( {
suppress_alerts => $test->{suppress_alerts},
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
$problem->discard_changes;
my $alerts_sent = FixMyStreet::App->model('DB::AlertSent')->search(
{
- alert_id => $alert->id,
+ alert_id => [ map $_->id, @alerts ],
parameter => $problem->comments->first->id,
}
);
if ( $test->{suppress_alerts} ) {
- ok $alerts_sent->count(), 'alerts suppressed';
+ is $alerts_sent->count(), $test->{num_alerts}, 'alerts suppressed';
} else {
is $alerts_sent->count(), 0, 'alerts not suppressed';
}
$alerts_sent->delete;
- $alert->delete;
+ for my $alert (@alerts) {
+ $alert->delete;
+ }
}
}
diff --git a/t/open311/getupdates.t b/t/open311/getupdates.t
index 500ac97d2..7dc7ff164 100644
--- a/t/open311/getupdates.t
+++ b/t/open311/getupdates.t
@@ -4,9 +4,7 @@ use strict;
use warnings;
use Test::More;
-use FindBin;
-use lib "$FindBin::Bin/../perllib";
-use lib "$FindBin::Bin/../commonlib/perllib";
+use FixMyStreet;
use_ok( 'Open311::GetUpdates' );
use_ok( 'Open311' );
@@ -17,6 +15,9 @@ my $user = FixMyStreet::App->model('DB::User')->find_or_create(
}
);
+my $body = FixMyStreet::App->model('DB::Body')->new( {
+ name => 'Test Body',
+} );
my $updates = Open311::GetUpdates->new( system_user => $user );
ok $updates, 'created object';
@@ -51,12 +52,9 @@ my $problem = $problem_rs->new(
title => '',
detail => '',
used_map => 1,
- user_id => 1,
name => '',
state => 'confirmed',
- service => '',
cobrand => 'default',
- cobrand_data => '',
user => $user,
created => DateTime->now()->subtract( days => 1 ),
lastupdate => DateTime->now()->subtract( days => 1 ),
@@ -104,7 +102,7 @@ for my $test (
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $local_requests_xml } );
- ok $updates->update_reports( [ 638344 ], $o, { name => 'Test Council' } );
+ ok $updates->update_reports( [ 638344 ], $o, $body );
is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638344', 'get url';
is $problem->comments->count, $test->{comment_count}, 'added a comment';
@@ -155,12 +153,9 @@ my $problem2 = $problem_rs->create(
title => '',
detail => '',
used_map => 1,
- user_id => 1,
name => '',
state => 'confirmed',
- service => '',
cobrand => 'default',
- cobrand_data => '',
user => $user,
created => DateTime->now()->subtract( days => 1 ),
lastupdate => DateTime->now()->subtract( days => 1 ),
@@ -182,17 +177,73 @@ subtest 'update with two requests' => sub {
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $local_requests_xml } );
- ok $updates->update_reports( [ 638344,638345 ], $o, { name => 'Test Council' } );
+ ok $updates->update_reports( [ 638344,638345 ], $o, $body );
is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638344%2C638345', 'get url';
is $problem->comments->count, 1, 'added a comment to first problem';
is $problem2->comments->count, 1, 'added a comment to second problem';
};
-$problem->comments->delete;
-$problem->delete;
-$user->comments->delete;
-$user->problems->delete;
-$user->delete;
+# No status_notes field now, so that static string in code is used.
+$requests_xml = qq{<?xml version="1.0" encoding="utf-8"?>
+<service_requests>
+<request>
+<service_request_id>638346</service_request_id>
+<status>closed</status>
+<service_name>Sidewalk and Curb Issues</service_name>
+<service_code>006</service_code>
+<description></description>
+<agency_responsible></agency_responsible>
+<service_notice></service_notice>
+<requested_datetime>2010-04-14T06:37:38-08:00</requested_datetime>
+UPDATED_DATETIME
+<expected_datetime>2010-04-15T06:37:38-08:00</expected_datetime>
+<lat>37.762221815</lat>
+<long>-122.4651145</long>
+</request>
+</service_requests>
+};
-done_testing();
+my $problem3 = $problem_rs->create( {
+ postcode => 'EH99 1SP',
+ latitude => 1,
+ longitude => 1,
+ areas => 1,
+ title => 'Title',
+ detail => 'Details',
+ used_map => 1,
+ name => '',
+ state => 'confirmed',
+ cobrand => 'fixamingata',
+ user => $user,
+ created => DateTime->now()->subtract( days => 1 ),
+ lastupdate => DateTime->now()->subtract( days => 1 ),
+ anonymous => 1,
+ external_id => 638346,
+} );
+
+subtest 'test translation of auto-added comment from old-style Open311 update' => sub {
+ my $dt = sprintf( '<updated_datetime>%s</updated_datetime>', DateTime->now );
+ $requests_xml =~ s/UPDATED_DATETIME/$dt/;
+
+ my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $requests_xml } );
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'fixamingata' ],
+ }, sub {
+ ok $updates->update_reports( [ 638346 ], $o, $body );
+ };
+ is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638346', 'get url';
+
+ is $problem3->comments->count, 1, 'added a comment';
+ is $problem3->comments->first->text, "St\xe4ngd av kommunen", 'correct comment text';
+};
+
+END {
+ if ($user) {
+ $user->comments->delete;
+ $user->problems->delete;
+ $user->delete;
+ }
+ done_testing();
+}
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 00026cd9f..9fd18b607 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -14,34 +14,44 @@ use_ok( 'Open311::PopulateServiceList' );
use_ok( 'Open311' );
-my $processor = Open311::PopulateServiceList->new( council_list => [] );
+my $processor = Open311::PopulateServiceList->new();
ok $processor, 'created object';
-
+my $body = FixMyStreet::App->model('DB::Body')->find_or_create( {
+ id => 1,
+ name => 'Body Numero Uno',
+} );
+$body->body_areas->find_or_create({
+ area_id => 1
+} );
+
+my $bromley = FixMyStreet::App->model('DB::Body')->find_or_create( {
+ id => 2482,
+ name => 'Bromley Council',
+} );
+$bromley->body_areas->find_or_create({
+ area_id => 2482
+} );
subtest 'check basic functionality' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
- area_id => 1
- } );
-
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
};
subtest 'check non open311 contacts marked as deleted' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => 'contact@example.com',
category => 'An old category',
confirmed => 1,
@@ -54,27 +64,23 @@ subtest 'check non open311 contacts marked as deleted' => sub {
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
- area_id => 1
- } );
-
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 4, 'correct number of contacts';
- $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1, deleted => 1 } )->count();
+ $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1, deleted => 1 } )->count();
is $contact_count, 1, 'correct number of deleted contacts';
};
subtest 'check email changed if matching category' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => '009',
category => 'Cans left out 24x7',
confirmed => 1,
@@ -89,12 +95,8 @@ subtest 'check email changed if matching category' => sub {
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
- area_id => 1
- } );
-
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
$contact->discard_changes;
@@ -102,16 +104,16 @@ subtest 'check email changed if matching category' => sub {
is $contact->confirmed, 1, 'contact still confirmed';
is $contact->deleted, 0, 'contact still not deleted';
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
};
subtest 'check category name changed if updated' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -126,12 +128,8 @@ subtest 'check category name changed if updated' => sub {
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
- area_id => 1
- } );
-
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
$contact->discard_changes;
@@ -140,16 +138,16 @@ subtest 'check category name changed if updated' => sub {
is $contact->confirmed, 1, 'contact still confirmed';
is $contact->deleted, 0, 'contact still not deleted';
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 3, 'correct number of contacts';
};
subtest 'check conflicting contacts not changed' => sub {
- FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->delete();
+ FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete();
my $contact = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => 'existing@example.com',
category => 'Cans left out 24x7',
confirmed => 1,
@@ -164,7 +162,7 @@ subtest 'check conflicting contacts not changed' => sub {
my $contact2 = FixMyStreet::App->model('DB::Contact')->create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -179,12 +177,8 @@ subtest 'check conflicting contacts not changed' => sub {
my $service_list = get_xml_simple_object( get_standard_xml() );
- my $council = FixMyStreet::App->model('DB::Open311Conf')->new( {
- area_id => 1
- } );
-
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
- $processor->_current_council( $council );
+ my $processor = Open311::PopulateServiceList->new();
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
$contact->discard_changes;
@@ -199,12 +193,12 @@ subtest 'check conflicting contacts not changed' => sub {
is $contact2->confirmed, 1, 'second contact contact still confirmed';
is $contact2->deleted, 0, 'second contact contact still not deleted';
- my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { area_id => 1 } )->count();
+ my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count();
is $contact_count, 4, 'correct number of contacts';
};
subtest 'check meta data population' => sub {
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
+ my $processor = Open311::PopulateServiceList->new();
my $meta_xml = '<?xml version="1.0" encoding="utf-8"?>
<service_definition>
@@ -225,7 +219,7 @@ subtest 'check meta data population' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -243,12 +237,8 @@ subtest 'check meta data population' => sub {
test_get_returns => { 'services/100.xml' => $meta_xml }
);
- my $council = FixMyStreet::App->model('DB::Open311conf')->new( {
- area_id => 2482
- } );
-
$processor->_current_open311( $o );
- $processor->_current_council( $council );
+ $processor->_current_body( $bromley );
$processor->_current_service( { service_code => 100 } );
$processor->_add_meta_to_contact( $contact );
@@ -387,7 +377,7 @@ for my $test (
},
) {
subtest $test->{desc} => sub {
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
+ my $processor = Open311::PopulateServiceList->new();
my $services_xml = '<?xml version="1.0" encoding="utf-8"?>
<services>
@@ -409,7 +399,7 @@ for my $test (
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '100',
category => 'Cans left out 24x7',
confirmed => 1,
@@ -432,12 +422,8 @@ for my $test (
my $service_list = get_xml_simple_object( $services_xml );
$service_list = { service => [ $service_list->{ service } ] };
- my $council = FixMyStreet::App->model('DB::Open311conf')->new( {
- area_id => 1
- } );
-
$processor->_current_open311( $o );
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->process_services( $service_list );
@@ -448,7 +434,7 @@ for my $test (
}
subtest 'check attribute ordering' => sub {
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
+ my $processor = Open311::PopulateServiceList->new();
my $meta_xml = '<?xml version="1.0" encoding="utf-8"?>
<service_definition>
@@ -487,7 +473,7 @@ subtest 'check attribute ordering' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -505,12 +491,8 @@ subtest 'check attribute ordering' => sub {
test_get_returns => { 'services/100.xml' => $meta_xml }
);
- my $council = FixMyStreet::App->model('DB::Open311conf')->new( {
- area_id => 1
- } );
-
$processor->_current_open311( $o );
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->_current_service( { service_code => 100 } );
$processor->_add_meta_to_contact( $contact );
@@ -554,7 +536,7 @@ subtest 'check attribute ordering' => sub {
};
subtest 'check bromely skip code' => sub {
- my $processor = Open311::PopulateServiceList->new( council_list => [] );
+ my $processor = Open311::PopulateServiceList->new();
my $meta_xml = '<?xml version="1.0" encoding="utf-8"?>
<service_definition>
@@ -593,7 +575,7 @@ subtest 'check bromely skip code' => sub {
my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create(
{
- area_id => 1,
+ body_id => 1,
email => '001',
category => 'Bins left out 24x7',
confirmed => 1,
@@ -611,12 +593,8 @@ subtest 'check bromely skip code' => sub {
test_get_returns => { 'services/100.xml' => $meta_xml }
);
- my $council = FixMyStreet::App->model('DB::Open311conf')->new( {
- area_id => 2482
- } );
-
$processor->_current_open311( $o );
- $processor->_current_council( $council );
+ $processor->_current_body( $bromley );
$processor->_current_service( { service_code => 100 } );
$processor->_add_meta_to_contact( $contact );
@@ -636,9 +614,7 @@ subtest 'check bromely skip code' => sub {
is_deeply $contact->extra, $extra, 'only non std bromley meta data saved';
- $council->area_id(1);
-
- $processor->_current_council( $council );
+ $processor->_current_body( $body );
$processor->_add_meta_to_contact( $contact );
$extra = [