aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller
diff options
context:
space:
mode:
Diffstat (limited to 't/app/controller')
-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
12 files changed, 286 insertions, 126 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;