aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm7
-rw-r--r--t/app/controller/admin.t73
2 files changed, 78 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 1a9aef81f..b8ef97a2f 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -293,7 +293,7 @@ sub display_contacts : Private {
$c->stash->{contacts} = $contacts;
- if ( $c->req->param('text') == 1 ) {
+ if ( $c->req->param('text') && $c->req->param('text') == 1 ) {
$c->stash->{template} = 'admin/council_contacts.txt';
$c->res->content_encoding('text/plain');
return 1;
@@ -371,7 +371,10 @@ sub get_token : Private {
my $secret = $c->model('DB::Secret')->search()->first;
- my $token = md5_hex(($c->req->remote_user() . $secret->secret));
+ my $user = $c->req->remote_user();
+ $user ||= '';
+
+ my $token = md5_hex(($user . $secret->secret));
$c->stash->{token} = $token;
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
new file mode 100644
index 000000000..ea3e8a656
--- /dev/null
+++ b/t/app/controller/admin.t
@@ -0,0 +1,73 @@
+use strict;
+use warnings;
+use Test::More;
+
+use FixMyStreet::TestMech;
+
+my $mech = FixMyStreet::TestMech->new;
+
+$mech->get_ok('/admin');
+$mech->title_like(qr/Summary/);
+
+$mech->get_ok('/admin/council_contacts/2650');
+$mech->content_contains('Aberdeen City Council');
+$mech->content_contains('AB15 8RN');
+
+subtest 'check contact creation' => sub {
+ my $contact = FixMyStreet::App->model('DB::Contact')->find(
+ { area_id => 2650, category => 'test category' }
+ );
+
+ $contact->delete if $contact;
+
+ my $history = FixMyStreet::App->model('DB::ContactsHistory')->search(
+ { area_id => 2650, category => 'test category' }
+ );
+
+ $history->delete_all;
+
+ $mech->get_ok('/admin/council_contacts/2650');
+
+ $mech->submit_form_ok( { with_fields => {
+ category => 'test category',
+ email => 'test@example.com',
+ note => 'test note',
+ } } );
+
+ $mech->content_contains( 'test category' );
+ $mech->content_contains( '<td>test@example.com' );
+ $mech->content_contains( '<td>test note' );
+};
+
+subtest 'check contact editing' => sub {
+ $mech->get_ok('/admin/council_edit/2650/test%20category');
+
+ $mech->submit_form_ok( { with_fields => {
+ email => 'test2@example.com',
+ note => 'test2 note',
+ } } );
+
+ $mech->content_contains( 'test category' );
+ $mech->content_contains( '<td>test2@example.com' );
+ $mech->content_contains( '<td>test2 note' );
+
+ $mech->get_ok('/admin/council_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->content_like(qr{test2\@example.com</strong>[^<]*</td>[^<]*<td>No}s);
+
+ $mech->get_ok('/admin/council_contacts/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->content_like(qr{test2\@example.com[^<]*</td>[^<]*<td><strong>Yes}s);
+};
+
+done_testing();