aboutsummaryrefslogtreecommitdiffstats
path: root/t/app
diff options
context:
space:
mode:
Diffstat (limited to 't/app')
-rw-r--r--t/app/controller/admin.t4
-rw-r--r--t/app/controller/alert.t10
-rw-r--r--t/app/controller/alert_new.t18
-rw-r--r--t/app/controller/around.t39
-rw-r--r--t/app/controller/contact.t4
-rw-r--r--t/app/controller/my.t3
-rw-r--r--t/app/controller/questionnaire.t8
-rw-r--r--t/app/controller/report_import.t16
-rw-r--r--t/app/controller/report_new.t219
-rw-r--r--t/app/controller/report_new_open311.t30
-rw-r--r--t/app/controller/report_updates.t24
-rw-r--r--t/app/controller/token.t37
-rw-r--r--t/app/model/alert_type.t2
-rw-r--r--t/app/model/extra.t111
-rw-r--r--t/app/model/problem.t97
-rw-r--r--t/app/sendreport/email.t15
16 files changed, 450 insertions, 187 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index f63a72117..498f1cedc 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -568,7 +568,7 @@ foreach my $test (
$report->discard_changes;
- if ( $report->state eq 'confirmed' ) {
+ if ($report->state eq 'confirmed' && $report->whensent) {
$mech->content_contains( 'type="submit" name="resend"', 'resend button' );
} else {
$mech->content_lacks( 'type="submit" name="resend"', 'no resend button' );
@@ -1083,7 +1083,7 @@ subtest 'report search' => sub {
subtest 'search abuse' => sub {
$mech->get_ok( '/admin/users?search=example' );
- $mech->content_like(qr{test4\@example.com.*</td>\s*<td>.*?</td>\s*<td>\(Email in abuse table});
+ $mech->content_like(qr{test4\@example.com.*</td>\s*<td>.*?</td>\s*<td>\(Email in abuse table}s);
};
subtest 'show flagged entries' => sub {
diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t
index 9189f5e97..5bf2af428 100644
--- a/t/app/controller/alert.t
+++ b/t/app/controller/alert.t
@@ -1,10 +1,13 @@
use strict;
use warnings;
use Test::More;
+use LWP::Protocol::PSGI;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
+use t::Nominatim;
+
# check that we can get the page
$mech->get_ok('/alert');
$mech->title_like(qr/^Local RSS feeds and email alerts/);
@@ -38,8 +41,11 @@ FixMyStreet::override_config {
$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');
+ subtest "Test Nominatim lookup" => sub {
+ LWP::Protocol::PSGI->register(t::Nominatim->run_if_script, host => 'nominatim.openstreetmap.org');
+ $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');
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 115bb181a..ac2ec20ac 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -132,7 +132,7 @@ foreach my $test (
ok $token->data->{id} == $existing_id, 'subscribed to existing alert';
$mech->get_ok("/A/$url_token");
- $mech->content_contains('successfully confirmed');
+ $mech->content_contains('alert created');
$alert =
FixMyStreet::App->model('DB::Alert')->find( { id => $existing_id, } );
@@ -370,9 +370,9 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
my ( $url, $url_token ) = $email->body =~ m{http://\S+(/A/(\S+))};
my $token = FixMyStreet::App->model('DB::Token')->find( { token => $url_token, scope => 'alert' } );
$mech->get_ok( $url );
- $mech->content_contains('successfully confirmed');
+ $mech->content_contains('alert created');
} else {
- $mech->content_contains('successfully created');
+ $mech->content_contains('alert created');
}
}
@@ -451,7 +451,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
my $count;
for (@emails) {
$count++ if $_->body =~ /The following updates have been left on this report:/;
- $count++ if $_->body =~ /The following new FixMyStreet reports have been added in City of\s+Edinburgh\s+Council:/;
+ $count++ if $_->body =~ /The following new FixMyStreet reports have been added in the City of\s+Edinburgh\s+Council area:/;
$count++ if $_->body =~ /The following FixMyStreet reports have been made within the area you\s+specified:/;
$count++ if $_->body =~ /\s+-\s+Testing/;
}
@@ -461,19 +461,21 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
like $email->body, qr/Other User/, 'Update name given';
unlike $email->body, qr/Anonymous User/, 'Update name not given';
- # The update alert was to the problem reporter, so has a login update URL
+ # The update alert was to the problem reporter, so has a special update URL
+ $mech->log_out_ok;
$mech->get_ok( "/report/$report_id" );
$mech->content_lacks( 'has not been fixed' );
- my ($url) = $email->body =~ m{(http://\S+/M/\S+)};
+ my ($url) = $email->body =~ m{(http://\S+/R/\S+)};
ok $url, "extracted update url '$url'";
$mech->get_ok( $url );
is $mech->uri->path, "/report/" . $report_id, "redirected to report page";
$mech->content_contains( 'has not been fixed' );
- $mech->logged_in_ok;
+ $mech->not_logged_in_ok;
($url) = $emails[0]->body =~ m{http://\S+(/A/\S+)};
$mech->get_ok( $url );
- $mech->content_contains('successfully deleted');
+ $mech->content_contains('alert deleted');
+ $mech->not_logged_in_ok;
$mech->delete_user($user1);
$mech->delete_user($user2);
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index df4f18660..03bcebf96 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -127,4 +127,43 @@ subtest 'check non public reports are not displayed on around page' => sub {
};
+subtest 'check category and status filtering works on /ajax' => sub {
+ my $categories = [ 'Pothole', 'Vegetation', 'Flytipping' ];
+ my $params = {
+ postcode => 'OX1 1ND',
+ latitude => 51.7435918829363,
+ longitude => -1.23201966270446,
+ };
+ my $bbox = ($params->{longitude} - 0.01) . ',' . ($params->{latitude} - 0.01)
+ . ',' . ($params->{longitude} + 0.01) . ',' . ($params->{latitude} + 0.01);
+
+ # Create one open and one fixed report in each category
+ foreach my $category ( @$categories ) {
+ foreach my $state ( 'confirmed', 'fixed' ) {
+ my %report_params = (
+ %$params,
+ category => $category,
+ state => $state,
+ );
+ $mech->create_problems_for_body( 1, 2237, 'Around page', \%report_params );
+ }
+ }
+
+ my $json = $mech->get_ok_json( '/ajax?bbox=' . $bbox );
+ my $pins = $json->{pins};
+ is scalar @$pins, 6, 'correct number of reports when no filters';
+
+ $json = $mech->get_ok_json( '/ajax?filter_category=Pothole&bbox=' . $bbox );
+ $pins = $json->{pins};
+ is scalar @$pins, 2, 'correct number of Pothole reports';
+
+ $json = $mech->get_ok_json( '/ajax?status=open&bbox=' . $bbox );
+ $pins = $json->{pins};
+ is scalar @$pins, 3, 'correct number of open reports';
+
+ $json = $mech->get_ok_json( '/ajax?status=fixed&filter_category=Vegetation&bbox=' . $bbox );
+ $pins = $json->{pins};
+ is scalar @$pins, 1, 'correct number of fixed Vegetation reports';
+};
+
done_testing();
diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t
index 89a1db5b2..cf8a3161b 100644
--- a/t/app/controller/contact.t
+++ b/t/app/controller/contact.t
@@ -259,7 +259,7 @@ for my $test (
$mech->get_ok('/contact');
}
$mech->submit_form_ok( { with_fields => $test->{fields} } );
- $mech->content_contains('Thanks for your feedback');
+ $mech->content_contains('Thank you for your feedback');
$mech->email_count_is(1);
my $email = $mech->get_email;
@@ -385,7 +385,7 @@ for my $test (
$mech->clear_emails_ok;
$mech->get_ok('/contact');
$mech->submit_form_ok( { with_fields => $test->{fields} } );
- $mech->content_contains('Thanks for your feedback');
+ $mech->content_contains('Thank you for your feedback');
$mech->email_count_is(1);
}
};
diff --git a/t/app/controller/my.t b/t/app/controller/my.t
index da509e8ed..b723e537e 100644
--- a/t/app/controller/my.t
+++ b/t/app/controller/my.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use Test::More tests => 11;
+use Test::More;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -17,3 +17,4 @@ is $mech->uri->path, '/my', "stayed on '/my/' page";
# cleanup
$mech->delete_user( $user );
+done_testing();
diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t
index 752dbb4cb..5938acc79 100644
--- a/t/app/controller/questionnaire.t
+++ b/t/app/controller/questionnaire.t
@@ -252,13 +252,13 @@ foreach my $test (
# Check the right HTML page has been returned
$mech->content_like( qr/<title>[^<]*Questionnaire/m );
- $mech->content_contains( 'glad to hear it&rsquo;s been fixed' )
+ $mech->content_contains( 'Glad to hear' )
if $result =~ /fixed/;
- $mech->content_lacks( 'glad to hear it&rsquo;s been fixed' )
+ $mech->content_lacks( 'Glad to hear' )
if $result !~ /fixed/;
$mech->content_contains( 'get some more information about the status of your problem' )
if $result eq 'unknown';
- $mech->content_contains( "sorry to hear that" )
+ $mech->content_contains( "sorry to hear" )
if $result eq 'confirmed' || $result eq 'closed';
# Check the database has the right information
@@ -319,7 +319,7 @@ subtest 'Check updates are shown correctly on questionnaire page' => sub {
$mech->content_contains( 'This is some update text' );
};
-for my $test (
+for my $test (
{
state => 'confirmed',
fixed => 0
diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t
index e5e9e2899..ff6508149 100644
--- a/t/app/controller/report_import.t
+++ b/t/app/controller/report_import.t
@@ -17,7 +17,17 @@ ok -e $sample_file, "sample file $sample_file exists";
FixMyStreet::App->log->disable('info');
END { FixMyStreet::App->log->enable('info'); }
-$mech->create_body_ok(2504, 'Westminster City Council');
+my $body = $mech->create_body_ok(2504, 'Westminster City Council');
+$mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Street lighting',
+ email => 'streetlighting@example.com',
+);
+$mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Potholes',
+ email => 'highways@example.com',
+);
# submit an empty report to import - check we get all errors
subtest "Test creating bad partial entries" => sub {
@@ -372,3 +382,7 @@ subtest "Submit a correct entry (with location) to cobrand" => sub {
};
done_testing();
+
+END {
+ $mech->delete_body($body);
+}
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 67e899102..bd0001be8 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -2,7 +2,6 @@ use strict;
use utf8; # sign in error message has &ndash; in it
use warnings;
use Test::More;
-use utf8;
use FixMyStreet::TestMech;
use FixMyStreet::App;
@@ -35,15 +34,8 @@ subtest "test that bare requests to /report/new get redirected" => sub {
"pc correctly transferred";
};
-my %contact_params = (
- confirmed => 1,
- deleted => 0,
- editor => 'Test',
- whenedited => \'current_timestamp',
- note => 'Created for test',
-);
-
my %body_ids;
+my @bodies;
for my $body (
{ area_id => 2651, name => 'City of Edinburgh Council' },
{ area_id => 2226, name => 'Gloucestershire County Council' },
@@ -56,62 +48,51 @@ for my $body (
{ area_id => 2333, name => 'Hart Council', id => 2333 },
) {
my $body_obj = $mech->create_body_ok($body->{area_id}, $body->{name}, id => $body->{id});
+ push @bodies, $body_obj;
$body_ids{$body->{area_id}} = $body_obj->id;
}
# 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,
+my $contact1 = $mech->create_contact_ok(
body_id => $body_ids{2651}, # Edinburgh
category => 'Street lighting',
email => 'highways@example.com',
-} );
-my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
- %contact_params,
+);
+my $contact2 = $mech->create_contact_ok(
body_id => $body_ids{2226}, # Gloucestershire
category => 'Potholes',
email => 'potholes@example.com',
-} );
-my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
- %contact_params,
+);
+my $contact3 = $mech->create_contact_ok(
body_id => $body_ids{2326}, # Cheltenham
category => 'Trees',
email => 'trees@example.com',
-} );
-my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
- %contact_params,
+);
+my $contact4 = $mech->create_contact_ok(
body_id => $body_ids{2482}, # Bromley
category => 'Trees',
email => 'trees@example.com',
-} );
-my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
- %contact_params,
+);
+my $contact5 = $mech->create_contact_ok(
body_id => $body_ids{2651}, # Edinburgh
category => 'Trees',
email => 'trees@example.com',
-} );
-my $contact6 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
- %contact_params,
+);
+my $contact6 = $mech->create_contact_ok(
body_id => $body_ids{2333}, # Hart
category => 'Trees',
email => 'trees@example.com',
-} );
-my $contact7 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
- %contact_params,
+);
+my $contact7 = $mech->create_contact_ok(
body_id => $body_ids{2227}, # Hampshire
category => 'Street lighting',
email => 'highways@example.com',
-} );
-ok $contact1, "created test contact 1";
-ok $contact2, "created test contact 2";
-ok $contact3, "created test contact 3";
-ok $contact4, "created test contact 4";
-ok $contact5, "created test contact 5";
-ok $contact6, "created test contact 6";
-ok $contact7, "created test contact 7";
+);
+my $contact8 = $mech->create_contact_ok(
+ body_id => $body_ids{2504},
+ category => 'Street lighting',
+ email => 'highways@example.com'
+);
# test that the various bit of form get filled in and errors correctly
# generated.
@@ -481,7 +462,7 @@ foreach my $test (
};
# check that we got the errors expected
- is_deeply $mech->page_errors, $test->{errors}, "check errors";
+ is_deeply [ sort @{$mech->page_errors} ], [ sort @{$test->{errors}} ], "check errors";
# check that fields have changed as expected
my $new_values = {
@@ -750,8 +731,7 @@ subtest "test report creation for a user who is signing in as they report" => su
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('Thank you for reporting this issue');
# Check the report has been assigned appropriately
is $report->bodies_str, $body_ids{2651};
@@ -852,8 +832,7 @@ foreach my $test (
# Check the report has been assigned appropriately
is $report->bodies_str, $body_ids{$test->{council}};
- # check that we got redirected to /report/
- is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
+ $mech->content_contains('Thank you for reporting this issue');
# check that no emails have been sent
$mech->email_count_is(0);
@@ -1020,7 +999,7 @@ for my $test (
host => 'www.fixmystreet.com',
postcode => 'EH99 1SP',
fms_extra_title => '',
- extra => undef,
+ extra => [],
user_title => undef,
},
{
@@ -1148,7 +1127,7 @@ for my $test (
my $report = $user->problems->first;
ok $report, "Found the report";
- my $extras = $report->extra;
+ my $extras = $report->get_extra_fields;
is $user->title, $test->{'user_title'}, 'user title correct';
is_deeply $extras, $test->{extra}, 'extra contains correct values';
@@ -1227,18 +1206,18 @@ subtest "test Hart" => sub {
button => 'submit_register',
},
{
- desc => 'confirm redirect for cobrand council in two tier cobrand redirects to cobrand site',
+ desc => 'confirmation page for cobrand council in two tier cobrand links to cobrand site',
category => 'Trees',
council => 2333,
national => 0,
- redirect => 1,
+ confirm => 1,
},
{
- desc => 'confirm redirect for non cobrand council in two tier cobrand redirect to national site',
+ desc => 'confirmation page for non cobrand council in two tier cobrand links to national site',
category => 'Street Lighting',
council => 2227,
national => 1,
- redirect => 1,
+ confirm => 1,
},
) {
subtest $test->{ desc } => sub {
@@ -1247,7 +1226,7 @@ subtest "test Hart" => sub {
$mech->clear_emails_ok;
$mech->log_out_ok;
- my $user = $mech->log_in_ok($test_email) if $test->{redirect};
+ my $user = $mech->log_in_ok($test_email) if $test->{confirm};
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'hart', 'fixmystreet' ],
@@ -1258,13 +1237,13 @@ subtest "test Hart" => sub {
$mech->content_contains( "Hart Council" );
$mech->submit_form_ok( { with_fields => { pc => 'GU51 4AE' } }, "submit location" );
$mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
- my %optional_fields = $test->{redirect} ? () :
+ my %optional_fields = $test->{confirm} ? () :
( 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->clear_host if $test->{confirm} && $test->{national};
$mech->submit_form_ok(
{
button => $test->{button},
@@ -1295,11 +1274,11 @@ subtest "test Hart" => sub {
# Check the report has been assigned appropriately
is $report->bodies_str, $body_ids{$test->{council}};
- if ( $test->{redirect} ) {
- is $mech->uri->path, "/report/" . $report->id, "redirected to report page";
+ if ( $test->{confirm} ) {
+ is $mech->uri->path, "/report/new";
my $base = 'www.fixmystreet.com';
$base = "hart.fixmystreet.com" unless $test->{national};
- is $mech->uri->host, $base, 'redirected to correct site';
+ $mech->content_contains("$base/report/" . $report->id, "links to correct site");
} else {
# receive token
my $email = $mech->get_email;
@@ -1358,13 +1337,12 @@ subtest "test SeeSomething" => sub {
my $cobrand = FixMyStreet::Cobrand::SeeSomething->new();
my $body_ss = $mech->create_body_ok(2535, 'Sandwell Borough Council', id => 2535);
- my $bus_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( {
- %contact_params,
+ my $bus_contact = $mech->create_contact_ok(
body_id => $body_ss->id,
category => 'Bus',
email => 'bus@example.com',
non_public => 1,
- } );
+ );
for my $test ( {
desc => 'report with no user details works',
@@ -1454,12 +1432,8 @@ subtest "test SeeSomething" => sub {
ok $report->confirmed, 'Report is confirmed automatically';
- if ( $test->{public} ) {
- is $mech->uri->path, '/report/' . $report->id, 'redirects to report page';
- } else {
- is $mech->uri->path, '/report/new', 'stays on report/new page';
- $mech->content_contains( 'Your report has been sent', 'use report created template' );
- }
+ 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;
@@ -1488,6 +1462,104 @@ subtest "categories from deleted bodies shouldn't be visible for new reports" =>
};
};
+subtest "unresponsive body handling works" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ }, sub {
+ # Test body-level send method
+ my $old_send = $contact1->body->send_method;
+ $contact1->body->update( { send_method => 'Refused' } );
+ $mech->get_ok('/report/new/ajax?latitude=55.9&longitude=-3.2'); # Edinburgh
+ my $body_id = $contact1->body->id;
+ ok $mech->content_like( qr{Edinburgh.*accept reports.*/unresponsive\?body=$body_id} );
+
+ my $test_email = 'test-2@example.com';
+ my $user = $mech->log_in_ok($test_email);
+ $mech->get_ok('/around');
+ $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" );
+ $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"
+ );
+
+ my $report = $user->problems->first;
+ ok $report, "Found the report";
+ is $report->bodies_str, undef, "Report not going anywhere";
+
+ $user->problems->delete;
+ $contact1->body->update( { send_method => $old_send } );
+
+ # And test per-category refusing
+ my $old_email = $contact3->email;
+ $contact3->update( { email => 'REFUSED' } );
+ $mech->get_ok('/report/new/category_extras?category=Trees&latitude=51.89&longitude=-2.09');
+ ok $mech->content_like( qr/Cheltenham.*Trees.*unresponsive.*category=Trees/ );
+
+ $mech->get_ok('/around');
+ $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" );
+ $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"
+ );
+
+ $report = $user->problems->first;
+ ok $report, "Found the report";
+ is $report->bodies_str, undef, "Report not going anywhere";
+
+ $contact3->update( { email => $old_email } );
+ $mech->delete_user($user);
+ };
+};
+
+subtest "unresponsive body page works" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ }, sub {
+ my $old_send = $contact1->body->send_method;
+ my $body_id = $contact1->body->id;
+ my $url = "/unresponsive?body=$body_id";
+ is $mech->get($url)->code, 404, "page not found";
+ $contact1->body->update( { send_method => 'Refused' } );
+ $mech->get_ok($url);
+ $mech->content_contains('Edinburgh');
+ $contact1->body->update( { send_method => $old_send } );
+
+ my $old_email = $contact3->email;
+ $body_id = $contact3->body->id;
+ $url = "/unresponsive?body=$body_id;category=Trees";
+ is $mech->get($url)->code, 404, "page not found";
+ $contact3->update( { email => 'REFUSED' } );
+ $mech->get_ok($url);
+ $mech->content_contains('Cheltenham');
+ $mech->content_contains('Trees');
+ $contact3->update( { email => $old_email } );
+ };
+};
+
subtest "extra google analytics code displayed on logged in problem creation" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
@@ -1537,9 +1609,6 @@ subtest "extra google analytics code displayed on logged in problem creation" =>
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( "'id': 'report/" . $report->id . "'", 'extra google code present' );
# cleanup
@@ -1606,12 +1675,8 @@ subtest "extra google analytics code displayed on email confirmation problem cre
};
};
-$contact1->delete;
-$contact2->delete;
-$contact3->delete;
-$contact4->delete;
-$contact5->delete;
-$contact6->delete;
-$contact7->delete;
-
done_testing();
+
+END {
+ $mech->delete_body($_) foreach @bodies;
+}
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index a274d918b..d3ca93f0e 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -19,16 +19,8 @@ $body->update({
api_key => 'apikey',
});
-my %contact_params = (
- confirmed => 1,
- deleted => 0,
- editor => 'Test',
- whenedited => \'current_timestamp',
- note => 'Created for test',
-);
# Let's make some contacts to send things to!
-my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
- %contact_params,
+my $contact1 = $mech->create_contact_ok(
body_id => $body->id, # Edinburgh
category => 'Street lighting',
email => '100',
@@ -37,15 +29,12 @@ my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
{ value => [ { name => ['Gas'], key => ['old'] }, { name => [ 'Yellow' ], key => [ 'modern' ] } ] }
}
],
-} );
-my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
- %contact_params,
+);
+my $contact2 = $mech->create_contact_ok(
body_id => $body->id, # Edinburgh
category => 'Graffiti Removal',
email => '101',
-} );
-ok $contact1, "created test contact 1";
-ok $contact2, "created test contact 2";
+);
# test that the various bit of form get filled in and errors correctly
# generated.
@@ -71,9 +60,9 @@ foreach my $test (
type => 'old',
},
errors => [
+ 'This information is required',
'Please enter a subject',
'Please enter some details',
- 'This information is required',
'Please enter your email',
'Please enter your name',
],
@@ -169,14 +158,15 @@ foreach my $test (
my $prob = $user->problems->first;
ok $prob, 'problem created';
- is_deeply $prob->extra, $test->{extra}, 'extra open311 data added to problem';
+ is_deeply $prob->get_extra_fields, $test->{extra}, 'extra open311 data added to problem';
$user->problems->delete;
$user->delete;
};
}
-$contact1->delete;
-$contact2->delete;
-
done_testing();
+
+END {
+ $mech->delete_body($body);
+}
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index 64ed91ac0..fa6c44292 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -457,6 +457,8 @@ for my $test (
},
'submit update'
);
+ $mech->content_contains("/report/$report_id");
+ $mech->get_ok("/report/$report_id");
$mech->content_contains('Test 2');
$mech->content_contains('Update no email confirm');
@@ -690,6 +692,7 @@ for my $test (
},
'submit update'
);
+ $mech->get_ok("/report/$report_id");
$report->discard_changes;
my $update = $report->comments->first;
@@ -786,6 +789,7 @@ subtest "check comment with no status change has not status in meta" => sub {
},
'submit update'
);
+ $mech->get_ok("/report/$report_id");
$report->discard_changes;
my @updates = $report->comments->all;
@@ -816,6 +820,7 @@ subtest "check comment with no status change has not status in meta" => sub {
},
'submit update'
);
+ $mech->get_ok("/report/$report_id");
$report->discard_changes;
@updates = $report->comments->search(undef, { order_by => 'created' })->all;;
@@ -971,7 +976,7 @@ for my $test (
"submit good details"
);
- is $mech->uri->path, "/report/" . $report_id, "redirected to report page";
+ $mech->content_contains('Thank you for updating this issue');
$mech->email_count_is(0);
my $update = $report->comments->first;
@@ -1201,7 +1206,9 @@ for my $test (
'submit update'
);
- is $mech->uri->path, "/report/" . $report_id, "redirected to report page";
+ $mech->content_contains('Thank you for updating this issue');
+ $mech->content_contains("/report/" . $report_id);
+ $mech->get_ok("/report/" . $report_id);
if ( !defined( $test->{endstate_banner} ) ) {
is $mech->extract_problem_banner->{text}, undef, 'endstate banner';
@@ -1255,7 +1262,6 @@ foreach my $test (
alert => 1, # we signed up for alerts before, do not unsign us
anonymous => 0,
answered => 0,
- path => '/report/update',
content =>
"Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?",
},
@@ -1282,7 +1288,6 @@ foreach my $test (
alert => 1, # we signed up for alerts before, do not unsign us
anonymous => 0,
answered => 0,
- path => '/report/update',
content =>
"Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?",
},
@@ -1310,7 +1315,6 @@ foreach my $test (
alert => 1, # we signed up for alerts before, do not unsign us
anonymous => 0,
answered => 1,
- path => '/report/' . $report->id,
content => $report->title,
},
)
@@ -1363,7 +1367,7 @@ foreach my $test (
$mech->submit_form_ok( { with_fields => $test->{fields}, },
'submit update' );
- is $mech->uri->path, $test->{path}, "page after submission";
+ is $mech->uri->path, '/report/update', "page after submission";
$mech->content_contains( $test->{content} );
@@ -1393,7 +1397,8 @@ foreach my $test (
$mech->submit_form_ok( { with_fields => { reported => 'Yes' } } );
- $mech->content_contains( 'Thank you &mdash; you can' );
+ $mech->content_contains( $report->title );
+ $mech->content_contains( 'Thank you for updating this issue' );
$questionnaire = FixMyStreet::App->model( 'DB::Questionnaire' )->find(
{ problem_id => $report_id }
@@ -1452,7 +1457,7 @@ for my $test (
anonymous => 0,
answered => 1,
path => '/report/update',
- content => "You have successfully confirmed your update",
+ content => "Thank you for updating this issue",
},
)
{
@@ -1542,7 +1547,8 @@ for my $test (
$mech->submit_form_ok( { with_fields => { reported => 'Yes' } } );
- $mech->content_contains( 'Thank you &mdash; you can' );
+ $mech->content_contains( $report->title );
+ $mech->content_contains( 'Thank you for updating this issue' );
$questionnaire = FixMyStreet::App->model( 'DB::Questionnaire' )->find(
{ problem_id => $report_id }
diff --git a/t/app/controller/token.t b/t/app/controller/token.t
new file mode 100644
index 000000000..9ca8b905d
--- /dev/null
+++ b/t/app/controller/token.t
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+use Test::More;
+use utf8;
+
+use FixMyStreet::TestMech;
+use FixMyStreet::App;
+
+my $user = FixMyStreet::App->model('DB::User')->find_or_create({
+ name => 'Bob', email => 'bob@example.com',
+ });
+my $mech = FixMyStreet::TestMech->new;
+
+subtest 'Zurich special case for C::Tokens->problem_confirm' => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => ['zurich'],
+ }, sub {
+ my $c = FixMyStreet::App->new;
+ my $zurich = $mech->create_body_ok( 1, 'Zurich' );
+ my ($report) = $mech->create_problems_for_body(
+ 1, $zurich->id,
+ {
+ state => 'unconfirmed',
+ confirmed => undef,
+ cobrand => 'zurich',
+ });
+
+ is $report->get_extra_metadata('email_confirmed'), undef, 'email_confirmed not yet set (sanity)';
+ my $token = $c->model('DB::Token')->create({ scope => 'problem', data => $report->id });
+
+ $mech->get_ok('/P/' . $token->token);
+ $report->discard_changes;
+ is $report->get_extra_metadata('email_confirmed'), 1, 'email_confirmed set by Zurich special case';
+ };
+};
+
+done_testing;
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index 5b7494a04..528c4d354 100644
--- a/t/app/model/alert_type.t
+++ b/t/app/model/alert_type.t
@@ -150,7 +150,7 @@ for my $test (
like $body, qr/$msg/, 'email says problem is ' . $test->{state};
if ($to eq $user->email) {
- like $body, qr{/M/}, 'contains problem login url';
+ like $body, qr{/R/}, 'contains problem login url';
} elsif ($to eq $user3->email) {
like $body, qr{/report/$report_id}, 'contains problem url';
}
diff --git a/t/app/model/extra.t b/t/app/model/extra.t
new file mode 100644
index 000000000..21c37336e
--- /dev/null
+++ b/t/app/model/extra.t
@@ -0,0 +1,111 @@
+use strict;
+use warnings;
+use Test::More;
+use utf8;
+
+use FixMyStreet::App;
+use Data::Dumper;
+use DateTime;
+
+my $c = FixMyStreet::App->new;
+
+my $db = FixMyStreet::App->model('DB')->schema;
+$db->txn_begin;
+
+my $body = $db->resultset('Body')->create({ name => 'ExtraTestingBody' });
+
+my $serial = 1;
+sub get_test_contact {
+ my $extra = shift;
+ my $contact = $db->resultset('Contact')->create({
+ category => "Testing ${serial}",
+ body => $body,
+ email => 'test@example.com',
+ confirmed => 1,
+ deleted => 0,
+ editor => 'test script',
+ note => 'test script',
+ whenedited => DateTime->now(),
+ $extra ? ( extra => $extra ) : (),
+ });
+ $serial++;
+ return $contact;
+}
+
+subtest 'Old list layout transparently upgraded' => sub {
+
+ subtest 'layout' => sub {
+ my $contact = get_test_contact([]);
+
+ is_deeply $contact->get_extra(), { _fields => [] }, 'transparently upgraded to a hash';
+ };
+
+ subtest 'extra fields' => sub {
+ my $contact = get_test_contact([]);
+
+ is_deeply $contact->get_extra_fields(), [], 'No extra fields';
+
+ my @fields = ( { a => 1 }, { b => 2 } );
+ $contact->set_extra_fields(@fields);
+ is_deeply $contact->extra, { _fields => \@fields }, 'extra fields set...';
+ $contact->update;
+ $contact->discard_changes;
+ is_deeply $contact->extra, { _fields => \@fields }, '...and retrieved';
+ is_deeply $contact->get_extra_fields(), \@fields, 'extra fields returned';
+ };
+
+ subtest 'metadata' => sub {
+ my $contact = get_test_contact([]);
+ is_deeply $contact->get_extra_metadata_as_hashref(), {}, 'No extra metadata';
+
+ $contact->set_extra_metadata('foo' => 'bar');
+ is $contact->get_extra_metadata('foo'), 'bar', 'extra metadata set...';
+ $contact->update;
+ $contact->discard_changes;
+ is $contact->get_extra_metadata('foo'), 'bar', '... and retrieved';
+ is_deeply $contact->get_extra_metadata_as_hashref(), { foo => 'bar' }, 'No extra metadata';
+ };
+};
+
+subtest 'Default hash layout' => sub {
+ subtest 'layout' => sub {
+ my $contact = get_test_contact();
+
+ is_deeply $contact->get_extra(), {}, 'default layout is hash';
+ };
+
+ subtest 'extra fields' => sub {
+ my $contact = get_test_contact();
+
+ is_deeply $contact->get_extra_fields(), [], 'No extra fields';
+
+ my @fields = ( { a => 1 }, { b => 2 } );
+ $contact->set_extra_fields(@fields);
+ is_deeply $contact->get_extra_fields, \@fields, 'extra fields set...';
+ $contact->update;
+ $contact->discard_changes;
+ is_deeply $contact->get_extra_fields(), \@fields, '... and returned';
+ is_deeply $contact->extra, { _fields => \@fields }, '(sanity check layout)';
+ };
+
+ subtest 'metadata' => sub {
+ my $contact = get_test_contact();
+ is_deeply $contact->get_extra_metadata_as_hashref(), {}, 'No extra metadata';
+
+ $contact->set_extra_metadata('foo' => 'bar');
+ is $contact->get_extra_metadata('foo'), 'bar', 'extra metadata set...';
+ $contact->update;
+ $contact->discard_changes;
+ is $contact->get_extra_metadata( 'foo'), 'bar', '... and retrieved';
+ is_deeply $contact->get_extra_metadata_as_hashref(), { foo => 'bar' }, 'No extra metadata';
+
+ $contact->unset_extra_metadata('foo');
+ is $contact->get_extra_metadata('foo'), undef, 'extra metadata now unset';
+ $contact->update;
+ $contact->discard_changes;
+ is $contact->get_extra_metadata('foo'), undef, '... after retrieval';
+ };
+};
+
+$db->txn_rollback;
+done_testing();
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index c40e9e022..ad82a62a5 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -18,8 +18,8 @@ my $problem_rs = FixMyStreet::App->model('DB::Problem');
my $problem = $problem_rs->new(
{
postcode => 'EH99 1SP',
- latitude => '51.5016605453401',
- longitude => '-0.142497580865087',
+ latitude => '51.5',
+ longitude => '-0.1',
areas => 1,
title => '',
detail => '',
@@ -33,6 +33,23 @@ my $problem = $problem_rs->new(
}
);
+my $visible_states = $problem->visible_states;
+is_deeply $visible_states, {
+ 'confirmed' => 1,
+ 'investigating' => 1,
+ 'in progress' => 1,
+ 'planned' => 1,
+ 'action scheduled' => 1,
+ 'fixed' => 1,
+ 'fixed - council' => 1,
+ 'fixed - user' => 1,
+ 'unable to fix' => 1,
+ 'not responsible' => 1,
+ 'duplicate' => 1,
+ 'closed' => 1,
+ 'internal referral' => 1,
+ }, 'visible_states is correct';
+
is $problem->confirmed, undef, 'inflating null confirmed ok';
is $problem->whensent, undef, 'inflating null confirmed ok';
is $problem->lastupdate, undef, 'inflating null confirmed ok';
@@ -50,30 +67,6 @@ for my $test (
}
},
{
- desc => 'name too short',
- changed => {
- name => 'xx',
- },
- errors => {
- title => 'Please enter a subject',
- detail => 'Please enter some details',
- 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',
- }
- },
- {
- desc => 'name is anonymous',
- changed => {
- name => 'anonymous',
- },
- errors => {
- title => 'Please enter a subject',
- detail => 'Please enter some details',
- 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',
- }
- },
- {
desc => 'correct name',
changed => {
name => 'A User',
@@ -369,15 +362,8 @@ for my $test (
my $mech = FixMyStreet::TestMech->new();
-my %contact_params = (
- confirmed => 1,
- deleted => 0,
- editor => 'Test',
- whenedited => \'ms_current_timestamp()',
- note => 'Created for test',
-);
-
my %body_ids;
+my @bodies;
for my $body (
{ area_id => 2651, name => 'City of Edinburgh Council' },
{ area_id => 2226, name => 'Gloucestershire County Council' },
@@ -387,13 +373,19 @@ for my $body (
{ area_id => 14279, name => 'Ballymoney Borough Council' },
{ area_id => 2636, name => 'Isle of Wight Council' },
{ area_id => 2649, name => 'Fife Council' },
+ { area_id => 14279, name => 'TransportNI (Western)' },
) {
my $aid = $body->{area_id};
- $body_ids{$aid} = $mech->create_body_ok($aid, $body->{name}, id => $body->{id})->id;
+ my $body = $mech->create_body_ok($aid, $body->{name});
+ if ($body_ids{$aid}) {
+ $body_ids{$aid} = [ $body_ids{$aid}, $body->id ];
+ } else {
+ $body_ids{$aid} = $body->id;
+ }
+ push @bodies, $body;
}
# Let's make some contacts to send things to!
-my @contacts;
for my $contact ( {
body_id => $body_ids{2651}, # Edinburgh
category => 'potholes',
@@ -415,11 +407,11 @@ for my $contact ( {
category => 'potholes',
email => 'highways@example.com',
}, {
- body_id => $body_ids{14279}, # Ballymoney
+ body_id => $body_ids{14279}[1], # TransportNI
category => 'Street lighting',
email => 'roads.western@drdni.example.org',
}, {
- body_id => $body_ids{14279}, # Ballymoney
+ body_id => $body_ids{14279}[0], # Ballymoney
category => 'Graffiti',
email => 'highways@example.com',
}, {
@@ -428,9 +420,7 @@ for my $contact ( {
category => 'potholes',
email => '2636@example.com',
} ) {
- my $new_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, %$contact } );
- ok $new_contact, "created test contact";
- push @contacts, $new_contact;
+ $mech->create_contact_ok( %$contact );
}
my %common = (
@@ -496,17 +486,19 @@ foreach my $test ( {
email_count => 1,
dear => qr'Dear Ballymoney Borough Council',
to => qr'Ballymoney Borough Council',
- body => $body_ids{14279},
+ body => $body_ids{14279}[0],
category => 'Graffiti',
+ longitude => -9.5,
}, {
%common,
desc => 'directs NI correctly, 2',
unset_whendef => 1,
email_count => 1,
- dear => qr'Dear Roads Service \(Western\)',
- to => qr'Roads Service \(Western\)" <roads',
- body => $body_ids{14279},
+ dear => qr'Dear TransportNI \(Western\)',
+ to => qr'TransportNI \(Western\)" <roads',
+ body => $body_ids{14279}[1],
category => 'Street lighting',
+ longitude => -9.5,
}, {
%common,
desc => 'does not send to unconfirmed contact',
@@ -543,6 +535,7 @@ foreach my $test ( {
category => $test->{ category } || 'potholes',
name => $test->{ name },
cobrand => $test->{ cobrand } || 'fixmystreet',
+ longitude => $test->{longitude} || '-0.1',
} );
FixMyStreet::override_config $override, sub {
@@ -558,6 +551,11 @@ foreach my $test ( {
like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
like $email->body, qr/Subject: A Title/, 'more email body checking';
like $email->body, $test->{ dear }, 'Salutation looks correct';
+ if ($test->{longitude}) {
+ like $email->body, qr{Easting/Northing \(IE\): 95938/28531};
+ } else {
+ like $email->body, qr{Easting/Northing: };
+ }
if ( $test->{multiple} ) {
like $email->body, qr/This email has been sent to several councils /, 'multiple body text correct';
@@ -592,10 +590,7 @@ subtest 'check can set mutiple emails as a single contact' => sub {
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->create_contact_ok( %$contact );
$mech->clear_emails_ok;
@@ -756,9 +751,7 @@ END {
$problem->delete if $problem;
$mech->delete_user( $user ) if $user;
- foreach (@contacts) {
- $_->delete;
- }
+ $mech->delete_body($_) for @bodies;
done_testing();
}
diff --git a/t/app/sendreport/email.t b/t/app/sendreport/email.t
index b2cab42ed..65cd7bfa8 100644
--- a/t/app/sendreport/email.t
+++ b/t/app/sendreport/email.t
@@ -7,11 +7,12 @@ use Test::More;
use FixMyStreet;
use FixMyStreet::App;
-use FixMyStreet::DB::Result::Contact;
use FixMyStreet::SendReport::Email;
use FixMyStreet::TestMech;
use mySociety::Locale;
+ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' );
+
my $e = FixMyStreet::SendReport::Email->new();
# area id 1000
@@ -19,14 +20,10 @@ 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(
+my $contact = $mech->create_contact_ok(
email => 'council@example.com',
body_id => 1000,
category => 'category',
- confirmed => 1,
- deleted => 0,
- editor => 'test suite',
- whenedited => DateTime->now,
note => '',
);
@@ -78,6 +75,8 @@ foreach my $test ( {
};
}
-$contact->delete;
-
done_testing();
+
+END {
+ $mech->delete_body($body);
+}