aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/app/controller/alert_new.t2
-rw-r--r--t/app/controller/report_new.t67
-rw-r--r--t/app/model/alert_type.t2
-rw-r--r--t/utils.t25
4 files changed, 93 insertions, 3 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 5ea73625a..3a4c2ef81 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -452,7 +452,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
$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 nearby problems have been added:/;
- $count++ if $_->body =~ / -\s+Testing, EH1 1BB/;
+ $count++ if $_->body =~ /\s+-\s+Testing,\s+EH1\s+1BB/;
}
is $count, 5, 'Five emails with the right things in them';
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 625c7531f..c16befd37 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -6,10 +6,14 @@ use utf8;
use FixMyStreet::TestMech;
use Web::Scraper;
+use Path::Class;
my $mech = FixMyStreet::TestMech->new;
$mech->get_ok('/report/new');
+my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify;
+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');
@@ -282,6 +286,69 @@ foreach my $test (
},
errors => [ 'Please enter a subject', 'Please enter some details', ],
},
+ {
+ msg => 'non-photo upload gives error',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => 'Title',
+ detail => 'Detail',
+ photo => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ],
+ name => 'Bob Jones',
+ may_show_name => '1',
+ email => 'bob@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+ },
+ changes => {
+ photo => '',
+ },
+ errors => [ "Please upload a JPEG image only" ],
+ },
+ {
+ msg => 'bad photo upload gives error',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => 'Title',
+ detail => 'Detail',
+ photo => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ],
+ name => 'Bob Jones',
+ may_show_name => '1',
+ email => 'bob@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+ },
+ changes => {
+ photo => '',
+ },
+ errors => [ "That image doesn't appear to have uploaded correctly (Please upload a JPEG image only ), please try again." ],
+ },
+ {
+ msg => 'photo with octet-stream gets through okay',
+ pc => 'SW1A 1AA',
+ fields => {
+ title => '',
+ detail => 'Detail',
+ photo => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ],
+ name => 'Bob Jones',
+ may_show_name => '1',
+ email => 'bob@example.com',
+ phone => '',
+ category => 'Street lighting',
+ password_sign_in => '',
+ password_register => '',
+ remember_me => undef,
+ },
+ changes => {
+ photo => '',
+ },
+ errors => [ "Please enter a subject" ],
+ },
)
{
subtest "check form errors where $test->{msg}" => sub {
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index ab129b4e7..67ddc10aa 100644
--- a/t/app/model/alert_type.t
+++ b/t/app/model/alert_type.t
@@ -202,7 +202,7 @@ for my $test (
(my $title = $report->title) =~ s/ /\\s+/;
my $body = $email->body;
- like $body, qr#report/$report_id - $title, $pc#, 'email contains expected postcode';
+ like $body, qr#report/$report_id\s+-\s+$title,\s+$pc#, 'email contains expected postcode';
};
}
diff --git a/t/utils.t b/t/utils.t
index 385c482ed..8ff9266fd 100644
--- a/t/utils.t
+++ b/t/utils.t
@@ -2,7 +2,7 @@
use strict;
use warnings;
-use Test::More tests => 9;
+use Test::More;
use FindBin;
use lib "$FindBin::Bin/../perllib";
@@ -39,3 +39,26 @@ foreach my $test (@convert_en_to_latlon_tests) {
[ $lat, $lon ], #
"convert ($e,$n) to ($lat,$lon)";
}
+
+my @cleanup_tests = (
+ [ 'dog shit', 'Dog poo', 'dog poo' ],
+ [ 'dog shit', 'Dog poo', 'with spaces' ],
+ [ 'dog shite', 'Dog poo', 'with extra e' ],
+ [ 'there is dog shit here', 'There is dog poo here', 'with surrounding text' ],
+ [ 'portacabin', '[portable cabin]', 'cabin' ],
+ [ 'portaloo', '[portable loo]', 'loo' ],
+ [ 'porta loo', '[portable loo]', 'with spaces' ],
+ [ ' this is a report ', 'This is a report', 'leading and trailing spaces' ],
+ [ 'This is a report ', 'This is a report', 'spaces in the middle' ],
+ [ 'I AM SHOUTING AT YOU', 'I am shouting at you', 'all shouting' ],
+ [ 'I am EMPHASISING something', 'I am EMPHASISING something', 'some shouting' ],
+ [ "This has new\n\n\nlines in it", 'This has new Lines in it', 'no new lines' ],
+);
+
+foreach my $test ( @cleanup_tests ) {
+ is Utils::cleanup_text( $test->[0]), $test->[1], $test->[2];
+}
+
+is Utils::cleanup_text( "This has new\n\n\nlines in it", { allow_multiline => 1 } ), "This has new\n\nLines in it", 'new lines allowed';
+
+done_testing();