aboutsummaryrefslogtreecommitdiffstats
path: root/t/app
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-08-17 22:56:37 +0100
committerStruan Donald <struan@exo.org.uk>2011-08-17 22:56:37 +0100
commit3b5d561700b184c20e63111d4cbc1daab78e16c6 (patch)
treef0c53c6bf8d4ebf12e5388053ad856fb0d0e7b86 /t/app
parent390f8e8ad1e10f832c4323c39bed2c883744a03f (diff)
parentf38b8e985697c35a62374a2f02dce2d681ef58cd (diff)
Merge branch 'master' of ssh://git.mysociety.org/data/git/public/fixmystreet into new_statuses
Conflicts: db/schema.sql perllib/FixMyStreet/App/Controller/Admin.pm perllib/FixMyStreet/DB/Result/User.pm t/app/controller/admin.t templates/web/default/admin/update_edit.html web/css/core.css
Diffstat (limited to 't/app')
-rw-r--r--t/app/controller/admin.t203
-rw-r--r--t/app/controller/contact.t11
-rw-r--r--t/app/controller/report_import.t2
-rw-r--r--t/app/controller/report_new.t6
-rw-r--r--t/app/controller/report_updates.t4
-rw-r--r--t/app/helpers/send_email.t3
6 files changed, 205 insertions, 24 deletions
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 25b79dc44..08cb4fb0d 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -139,7 +139,7 @@ subtest 'check summary counts' => sub {
my $host = FixMyStreet->config('BASE_URL');
$mech->get_ok('/admin/council_contacts/2650');
$mech->content_contains('Aberdeen City Council');
-$mech->content_contains('AB15 8RN');
+$mech->content_like(qr{AB\d\d});
$mech->content_contains("$host/around");
subtest 'check contact creation' => sub {
@@ -236,6 +236,7 @@ foreach my $test (
name => 'Test User',
email => $user->email,
anonymous => 0,
+ flagged => undef,
},
changes => {
title => 'Edited Report',
@@ -253,6 +254,7 @@ foreach my $test (
name => 'Test User',
email => $user->email,
anonymous => 0,
+ flagged => undef,
},
changes => {
detail => 'Edited Detail',
@@ -270,6 +272,7 @@ foreach my $test (
name => 'Test User',
email => $user->email,
anonymous => 0,
+ flagged => undef,
},
changes => {
name => 'Edited User',
@@ -280,7 +283,7 @@ foreach my $test (
user => $user,
},
{
- description => 'edit report user email',
+ description => 'edit report set flagged true',
fields => {
title => 'Edited Report',
detail => 'Edited Detail',
@@ -288,13 +291,33 @@ foreach my $test (
name => 'Edited User',
email => $user->email,
anonymous => 0,
+ flagged => undef,
},
changes => {
- email => $user2->email,
+ flagged => 'on',
},
log_count => 4,
log_entries => [ qw/edit edit edit edit/ ],
resend => 0,
+ user => $user,
+ },
+ {
+ description => 'edit report user email',
+ fields => {
+ title => 'Edited Report',
+ detail => 'Edited Detail',
+ state => 'confirmed',
+ name => 'Edited User',
+ email => $user->email,
+ anonymous => 0,
+ flagged => 'on',
+ },
+ changes => {
+ email => $user2->email,
+ },
+ log_count => 5,
+ log_entries => [ qw/edit edit edit edit edit/ ],
+ resend => 0,
user => $user2,
},
{
@@ -306,12 +329,13 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 0,
+ flagged => 'on',
},
changes => {
state => 'unconfirmed'
},
- log_count => 5,
- log_entries => [ qw/state_change edit edit edit edit/ ],
+ log_count => 6,
+ log_entries => [ qw/state_change edit edit edit edit edit/ ],
resend => 0,
},
{
@@ -323,12 +347,13 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 0,
+ flagged => 'on',
},
changes => {
state => 'confirmed'
},
- log_count => 6,
- log_entries => [ qw/state_change state_change edit edit edit edit/ ],
+ log_count => 7,
+ log_entries => [ qw/state_change state_change edit edit edit edit edit/ ],
resend => 0,
},
{
@@ -340,12 +365,13 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 0,
+ flagged => 'on',
},
changes => {
state => 'fixed'
},
- log_count => 7,
- log_entries => [ qw/state_change state_change state_change edit edit edit edit/ ],
+ log_count => 8,
+ log_entries => [ qw/state_change state_change state_change edit edit edit edit edit/ ],
resend => 0,
},
{
@@ -357,12 +383,13 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 0,
+ flagged => 'on',
},
changes => {
state => 'hidden'
},
- log_count => 8,
- log_entries => [ qw/state_change state_change state_change state_change edit edit edit edit/ ],
+ log_count => 9,
+ log_entries => [ qw/state_change state_change state_change state_change edit edit edit edit edit/ ],
resend => 0,
},
{
@@ -374,13 +401,14 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 0,
+ flagged => 'on',
},
changes => {
state => 'confirmed',
anonymous => 1,
},
- log_count => 10,
- log_entries => [ qw/edit state_change state_change state_change state_change state_change edit edit edit edit/ ],
+ log_count => 11,
+ log_entries => [ qw/edit state_change state_change state_change state_change state_change edit edit edit edit edit/ ],
resend => 0,
},
{
@@ -392,11 +420,12 @@ foreach my $test (
name => 'Edited User',
email => $user2->email,
anonymous => 1,
+ flagged => 'on',
},
changes => {
},
- log_count => 11,
- log_entries => [ qw/resend edit state_change state_change state_change state_change state_change edit edit edit edit/ ],
+ log_count => 12,
+ log_entries => [ qw/resend edit state_change state_change state_change state_change state_change edit edit edit edit edit/ ],
resend => 1,
},
) {
@@ -429,6 +458,7 @@ foreach my $test (
$mech->content_lacks( 'type="submit" name="resend"', 'no resend button' );
}
+ $test->{changes}->{flagged} = 1 if $test->{changes}->{flagged};
is $report->$_, $test->{changes}->{$_}, "$_ updated" for grep { $_ ne 'email' } keys %{ $test->{changes} };
if ( $test->{user} ) {
@@ -452,6 +482,7 @@ subtest 'change email to new user' => sub {
name => $report->name,
email => $report->user->email,
anonymous => 1,
+ flagged => 'on',
};
is_deeply( $mech->visible_form_values(), $fields, 'initial form values' );
@@ -491,6 +522,65 @@ subtest 'change email to new user' => sub {
is $report->user_id, $user3->id, 'user changed to new user';
};
+subtest 'adding email to abuse list from report page' => sub {
+ my $email = $report->user->email;
+
+ my $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ $abuse->delete if $abuse;
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Ban email address');
+
+ $mech->click_ok('banuser');
+
+ $mech->content_contains('Email added to abuse list');
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+
+ $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ ok $abuse, 'entry created in abuse table';
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+};
+
+subtest 'flagging user from report page' => sub {
+ $report->user->flagged(0);
+ $report->user->update;
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Flag user');
+
+ $mech->click_ok('flaguser');
+
+ $mech->content_contains('User flagged');
+ $mech->content_contains('Remove flag');
+
+ $report->discard_changes;
+ ok $report->user->flagged, 'user flagged';
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Remove flag');
+};
+
+subtest 'unflagging user from report page' => sub {
+ $report->user->flagged(1);
+ $report->user->update;
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Remove flag');
+
+ $mech->click_ok('removeuserflag');
+
+ $mech->content_contains('User flag removed');
+ $mech->content_contains('Flag user');
+
+ $report->discard_changes;
+ ok !$report->user->flagged, 'user not flagged';
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Flag user');
+};
+
$log_entries->delete;
my $update = FixMyStreet::App->model('DB::Comment')->create(
@@ -605,7 +695,7 @@ for my $test (
},
changes => {
text => 'this is a twice changed update',
- state => 'hidden',
+ state => 'confirmed',
},
log_count => 7,
log_entries => [qw/edit state_change state_change edit edit edit edit/],
@@ -632,6 +722,9 @@ for my $test (
$update->discard_changes;
is $update->$_, $test->{changes}->{$_} for grep { $_ ne 'email' } keys %{ $test->{changes} };
+ if ( $test->{changes}{state} && $test->{changes}{state} eq 'confirmed' ) {
+ isnt $update->confirmed, undef;
+ }
if ( $test->{user} ) {
is $update->user->id, $test->{user}->id, 'update user';
@@ -738,6 +831,65 @@ subtest 'editing update email creates new user if required' => sub {
is $update->user->id, $user->id, 'update set to new user';
};
+subtest 'adding email to abuse list from update page' => sub {
+ my $email = $update->user->email;
+
+ my $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ $abuse->delete if $abuse;
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Ban email address');
+
+ $mech->click_ok('banuser');
+
+ $mech->content_contains('Email added to abuse list');
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+
+ $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ ok $abuse, 'entry created in abuse table';
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+};
+
+subtest 'flagging user from update page' => sub {
+ $update->user->flagged(0);
+ $update->user->update;
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Flag user');
+
+ $mech->click_ok('flaguser');
+
+ $mech->content_contains('User flagged');
+ $mech->content_contains('Remove flag');
+
+ $update->discard_changes;
+ ok $update->user->flagged, 'user flagged';
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Remove flag');
+};
+
+subtest 'unflagging user from update page' => sub {
+ $update->user->flagged(1);
+ $update->user->update;
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Remove flag');
+
+ $mech->click_ok('removeuserflag');
+
+ $mech->content_contains('User flag removed');
+ $mech->content_contains('Flag user');
+
+ $update->discard_changes;
+ ok !$update->user->flagged, 'user not flagged';
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Flag user');
+};
+
subtest 'hiding comment marked as fixed reopens report' => sub {
$update->mark_fixed( 1 );
$update->update;
@@ -794,6 +946,24 @@ subtest 'report search' => sub {
$mech->content_like( qr{<tr [^>]*hidden[^>]*> \s* <td> \s* $r_id \s* </td>}xs );
};
+subtest 'search abuse' => sub {
+ $mech->get_ok( '/admin/search_abuse?search=example' );
+
+ $mech->content_contains('test4@example.com');
+};
+
+subtest 'show flagged entries' => sub {
+ $report->flagged( 1 );
+ $report->update;
+
+ $user->flagged( 1 );
+ $user->update;
+
+ $mech->get_ok('/admin/list_flagged');
+ $mech->content_contains( $report->title );
+ $mech->content_contains( $user->email );
+};
+
subtest 'user search' => sub {
$mech->get_ok('/admin/search_users');
$mech->get_ok('/admin/search_users?search=' . $user->name);
@@ -885,7 +1055,6 @@ for my $test (
};
}
-
$mech->delete_user( $user );
$mech->delete_user( $user2 );
$mech->delete_user( $user3 );
diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t
index bbb3a0f83..86b845eb3 100644
--- a/t/app/controller/contact.t
+++ b/t/app/controller/contact.t
@@ -248,6 +248,9 @@ for my $test (
)
{
subtest 'check email sent correctly' => sub {
+ $problem_main->discard_changes;
+ ok !$problem_main->flagged, 'problem not flagged';
+
$mech->clear_emails_ok;
if ($test->{fields}{id}) {
$mech->get_ok('/contact?id=' . $test->{fields}{id});
@@ -267,6 +270,14 @@ for my $test (
my $problem_id = $test->{fields}{id};
like $email->body, qr/Complaint about report $problem_id/, 'reporting a report'
if $test->{fields}{id};
+
+ $problem_main->discard_changes;
+ if ( $problem_id ) {
+ ok $problem_main->flagged, 'problem flagged';
+ } else {
+ ok !$problem_main->flagged, 'problem not flagged';
+ }
+
};
}
diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t
index 61ee28b88..385445565 100644
--- a/t/app/controller/report_import.t
+++ b/t/app/controller/report_import.t
@@ -77,7 +77,7 @@ subtest "Submit a correct entry" => sub {
with_fields => {
service => 'test-script',
name => 'Test User',
- email => 'test@example.com',
+ email => 'Test@example.com',
subject => 'Test report',
detail => 'This is a test report',
photo => $sample_file,
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index f06c23501..fa188210a 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -151,8 +151,8 @@ foreach my $test (
msg => 'title and details tidied up',
pc => 'SW1A 1AA',
fields => {
- title => 'DOG SHIT ON WALLS',
- detail => 'on this portakabin - more of a portaloo HEH!!',
+ title => "DOG SHIT\r\nON WALLS",
+ detail => "on this portakabin -\r\n\r\nmore of a portaloo HEH!!",
photo => '',
name => 'Bob Jones',
may_show_name => '1',
@@ -166,7 +166,7 @@ foreach my $test (
changes => {
title => 'Dog poo on walls',
detail =>
- 'On this [portable cabin] - more of a [portable loo] HEH!!',
+ "On this [portable cabin] -\n\nMore of a [portable loo] HEH!!",
},
errors => [ 'Please enter your email', ],
},
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index ec4aa7342..9606afc8e 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -324,13 +324,13 @@ for my $test (
form_values => {
submit_update => 1,
rznvy => 'unregistered@example.com',
- update => 'update from an unregistered user',
+ update => "update from an\r\n\r\nunregistered user",
add_alert => 1,
name => 'Unreg User',
may_show_name => undef,
},
changes => {
- update => 'Update from an unregistered user',
+ update => "Update from an\n\nUnregistered user",
},
}
) {
diff --git a/t/app/helpers/send_email.t b/t/app/helpers/send_email.t
index ac7e5b5c2..8c043f701 100644
--- a/t/app/helpers/send_email.t
+++ b/t/app/helpers/send_email.t
@@ -9,7 +9,7 @@ BEGIN {
FixMyStreet->test_mode(1);
}
-use Test::More tests => 5;
+use Test::More tests => 6;
use Email::Send::Test;
use Path::Class;
@@ -44,6 +44,7 @@ is scalar(@emails), 1, "caught one email";
# Get the email, check it has a date and then strip it out
my $email_as_string = $emails[0]->as_string;
ok $email_as_string =~ s{\s+Date:\s+\S.*?$}{}xms, "Found and stripped out date";
+ok $email_as_string =~ s{\s+Message-ID:\s+\S.*?$}{}xms, "Found and stripped out message ID (contains epoch)";
my $expected_email_content = file(__FILE__)->dir->file('send_email_sample.txt')->slurp;
my $name = FixMyStreet->config('CONTACT_NAME');