aboutsummaryrefslogtreecommitdiffstats
path: root/t/app
diff options
context:
space:
mode:
Diffstat (limited to 't/app')
-rw-r--r--t/app/controller/moderate.t10
-rw-r--r--t/app/controller/photo.t75
-rw-r--r--t/app/controller/questionnaire.t2
-rw-r--r--t/app/controller/report_display.t142
-rw-r--r--t/app/controller/report_import.t8
-rw-r--r--t/app/helpers/grey.gifbin0 -> 34 bytes
-rw-r--r--t/app/helpers/send_email.t72
-rw-r--r--t/app/helpers/send_email_sample_mime.txt57
-rw-r--r--t/app/model/photoset.t76
9 files changed, 362 insertions, 80 deletions
diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t
index cd4c742bb..b79f50e73 100644
--- a/t/app/controller/moderate.t
+++ b/t/app/controller/moderate.t
@@ -42,10 +42,7 @@ sub create_report {
latitude => '51.4129',
longitude => '0.007831',
user_id => $user->id,
- photo => 'DUMMY DATA', # this obv fake data would not be
- # accepted by front-end but is
- # enough to trigger "I have a
- # photo" behaviour
+ photo => $mech->get_photo_data,
});
}
my $report = create_report();
@@ -216,7 +213,7 @@ sub create_update {
user => $user,
name => 'Test User',
anonymous => 'f',
- photo => 'DUMMY DATA', # as above
+ photo => $mech->get_photo_data,
text => 'update good good bad good',
state => 'confirmed',
mark_fixed => 0,
@@ -283,7 +280,8 @@ subtest 'updates' => sub {
$mech->get_ok($REPORT_URL);
- $mech->content_contains('Photo of this report');
+ $mech->content_contains('Photo of this report')
+ or die $mech->content;
$mech->post_ok( $MODERATE_UPDATE_URL, {
%update_prepopulated,
diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t
new file mode 100644
index 000000000..6e61ebb32
--- /dev/null
+++ b/t/app/controller/photo.t
@@ -0,0 +1,75 @@
+use strict;
+use utf8; # sign in error message has – in it
+use warnings;
+use feature 'say';
+use Test::More;
+use utf8;
+
+use FixMyStreet::TestMech;
+use FixMyStreet::App;
+use Web::Scraper;
+use Path::Tiny;
+use File::Temp 'tempdir';
+
+# disable info logs for this test run
+FixMyStreet::App->log->disable('info');
+END { FixMyStreet::App->log->enable('info'); }
+
+my $mech = FixMyStreet::TestMech->new;
+
+my $sample_file = path(__FILE__)->parent->child("sample.jpg");
+ok $sample_file->exists, "sample file $sample_file exists";
+
+my $westminster = $mech->create_body_ok(2527, 'Liverpool City Council');
+
+subtest "Check multiple upload worked" => sub {
+ $mech->get_ok('/around');
+
+ my $UPLOAD_DIR = tempdir( CLEANUP => 1 );
+
+ # submit initial pc form
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { fixmystreet => '.' } ],
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ UPLOAD_DIR => $UPLOAD_DIR,
+ }, sub {
+
+ $mech->log_in_ok('test@example.com');
+
+
+ # submit the main form
+ # can't post_ok as we lose the Content_Type header
+ # (TODO rewrite with HTTP::Request::Common and request_ok)
+ $mech->post( '/report/new',
+ Content_Type => 'form-data',
+ Content =>
+ {
+ submit_problem => 1,
+ title => 'Test',
+ lat => 53.4031156, lon => -2.9840579, # in Liverpool
+ pc => 'L1 4LN',
+ detail => 'Detail',
+ photo1 => [ $sample_file, undef, Content_Type => 'application/octet-stream' ],
+ photo2 => [ $sample_file, undef, Content_Type => 'application/octet-stream' ],
+ photo3 => [ $sample_file, undef, Content_Type => 'application/octet-stream' ],
+ name => 'Bob Jones',
+ may_show_name => '1',
+ email => 'test@example.com',
+ phone => '',
+ category => 'Street lighting',
+ #password_sign_in => '',
+ #password_register => '',
+ #remember_me => undef,
+ }
+ );
+ ok $mech->success, 'Made request with multiple photo upload';
+ $mech->base_is('http://localhost/report/new');
+ $mech->content_contains(
+ 'name="upload_fileid" value="1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687"',
+ 'Returned upload_fileid contains expected hash, 3 times');
+ my $image_file = path($UPLOAD_DIR, '1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg');
+ ok $image_file->exists, 'File uploaded to temp';
+ };
+};
+
+done_testing();
diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t
index d4fc9c74b..2a89454d5 100644
--- a/t/app/controller/questionnaire.t
+++ b/t/app/controller/questionnaire.t
@@ -276,7 +276,7 @@ foreach my $test (
$questionnaire->discard_changes;
is $report->state, $result eq 'unknown' ? $test->{problem_state} : $result;
is $report->send_questionnaire, $another;
- ok DateTime::Format::Pg->format_datetime( $report->lastupdate) gt $report_time, 'lastupdate changed'
+ ok (DateTime::Format::Pg->format_datetime( $report->lastupdate) gt $report_time, 'lastupdate changed')
unless $test->{fields}{been_fixed} eq 'Unknown' || $test->{lastupdate_static};
is $questionnaire->old_state, $test->{problem_state};
is $questionnaire->new_state, $result;
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index 002cdc1e5..265760d86 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -96,19 +96,6 @@ subtest "change report to unconfirmed and check for 404 status" => sub {
};
-subtest "Zurich unconfirmeds are 200" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'zurich' ],
- }, sub {
- $mech->host( 'zurich.example.com' );
- ok $report->update( { state => 'unconfirmed' } ), 'unconfirm report';
- $mech->get_ok("/report/$report_id");
- $mech->content_contains( 'Überprüfung ausstehend' );
- ok $report->update( { state => 'confirmed' } ), 'confirm report again';
- $mech->host( 'www.fixmystreet.com' );
- };
-};
-
subtest "change report to hidden and check for 410 status" => sub {
ok $report->update( { state => 'hidden' } ), 'hide report';
ok $mech->get("/report/$report_id"), "get '/report/$report_id'";
@@ -400,9 +387,72 @@ for my $test (
};
}
+my $body_westminster = $mech->create_body_ok(2504, 'Westminster City Council');
+my $body_camden = $mech->create_body_ok(2505, 'Camden Borough Council');
+
+for my $test (
+ {
+ desc => 'no state dropdown if user not from authority',
+ from_body => undef,
+ no_state => 1,
+ report_body => $body_westminster->id,
+ },
+ {
+ desc => 'state dropdown if user from authority',
+ from_body => $body_westminster->id,
+ no_state => 0,
+ report_body => $body_westminster->id,
+ },
+ {
+ desc => 'no state dropdown if user not from same body as problem',
+ from_body => $body_camden->id,
+ no_state => 1,
+ report_body => $body_westminster->id,
+ },
+ {
+ desc => 'state dropdown if user from authority and problem sent to multiple bodies',
+ from_body => $body_westminster->id,
+ no_state => 0,
+ report_body => $body_westminster->id . ',2506',
+ },
+) {
+ subtest $test->{desc} => sub {
+ $mech->log_in_ok( $user->email );
+ $user->from_body( $test->{from_body} );
+ $user->update;
+
+ $report->discard_changes;
+ $report->bodies_str( $test->{report_body} );
+ $report->update;
+
+ $mech->get_ok("/report/$report_id");
+ my $fields = $mech->visible_form_values( 'updateForm' );
+ if ( $test->{no_state} ) {
+ ok !$fields->{state};
+ } else {
+ ok $fields->{state};
+ }
+ };
+}
+
+subtest "Zurich unconfirmeds are 200" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'zurich' ],
+ MAP_TYPE => 'Zurich,OSM',
+ }, sub {
+ $mech->host( 'zurich.example.com' );
+ ok $report->update( { state => 'unconfirmed' } ), 'unconfirm report';
+ $mech->get_ok("/report/$report_id");
+ $mech->content_contains( 'Überprüfung ausstehend' );
+ ok $report->update( { state => 'confirmed' } ), 'confirm report again';
+ $mech->host( 'www.fixmystreet.com' );
+ };
+};
+
subtest "Zurich banners are displayed correctly" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'zurich' ],
+ MAP_TYPE => 'Zurich,OSM',
}, sub {
$mech->host( 'zurich.example.com' );
@@ -428,8 +478,8 @@ subtest "Zurich banners are displayed correctly" => sub {
{
description => 'closed report',
state => 'closed',
- banner_id => 'fixed',
- banner_text => 'Beantwortet',
+ banner_id => 'closed',
+ banner_text => _('Extern'),
},
{
description => 'in progress report',
@@ -443,6 +493,21 @@ subtest "Zurich banners are displayed correctly" => sub {
banner_id => 'progress',
banner_text => 'In Bearbeitung',
},
+ {
+ description => 'planned report',
+ state => 'planned',
+ banner_id => 'progress',
+ banner_text => 'In Bearbeitung',
+ },
+ {
+ description => 'jurisdiction unknown',
+ state => 'unable to fix',
+ banner_id => 'fixed',
+ # We can't use _('Jurisdiction Unknown') here because
+ # TestMech::extract_problem_banner decodes the HTML entities before
+ # the string is passed back.
+ banner_text => 'Zust\x{e4}ndigkeit unbekannt',
+ },
) {
subtest "banner for $test->{description}" => sub {
$report->state( $test->{state} );
@@ -470,53 +535,6 @@ subtest "Zurich banners are displayed correctly" => sub {
};
};
-my $body_westminster = $mech->create_body_ok(2504, 'Westminster City Council');
-my $body_camden = $mech->create_body_ok(2505, 'Camden Borough Council');
-
-for my $test (
- {
- desc => 'no state dropdown if user not from authority',
- from_body => undef,
- no_state => 1,
- report_body => $body_westminster->id,
- },
- {
- desc => 'state dropdown if user from authority',
- from_body => $body_westminster->id,
- no_state => 0,
- report_body => $body_westminster->id,
- },
- {
- desc => 'no state dropdown if user not from same body as problem',
- from_body => $body_camden->id,
- no_state => 1,
- report_body => $body_westminster->id,
- },
- {
- desc => 'state dropdown if user from authority and problem sent to multiple bodies',
- from_body => $body_westminster->id,
- no_state => 0,
- report_body => $body_westminster->id . ',2506',
- },
-) {
- subtest $test->{desc} => sub {
- $mech->log_in_ok( $user->email );
- $user->from_body( $test->{from_body} );
- $user->update;
-
- $report->discard_changes;
- $report->bodies_str( $test->{report_body} );
- $report->update;
-
- $mech->get_ok("/report/$report_id");
- my $fields = $mech->visible_form_values( 'updateForm' );
- if ( $test->{no_state} ) {
- ok !$fields->{state};
- } else {
- ok $fields->{state};
- }
- };
-}
END {
$mech->delete_user('test@example.com');
diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t
index 16874ac3c..4d0f6e5d1 100644
--- a/t/app/controller/report_import.t
+++ b/t/app/controller/report_import.t
@@ -321,6 +321,7 @@ subtest "Submit a correct entry (with location) to cobrand" => sub {
MAPIT_URL => 'http://global.mapit.mysociety.org/',
MAPIT_TYPES => [ 'O08' ],
MAPIT_ID_WHITELIST => [],
+ MAP_TYPE => 'Zurich,OSM',
}, sub {
ok $mech->host("zurich.example.org"), 'change host to zurich';
@@ -364,11 +365,14 @@ subtest "Submit a correct entry (with location) to cobrand" => sub {
{
name => 'Test User ll',
detail => 'This is a test report ll',
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
phone => '',
email => 'test-ll@example.com',
},
- "check imported fields are shown";
+ "check imported fields are shown"
+ or diag Dumper( $mech->visible_form_values ); use Data::Dumper;
my $user =
FixMyStreet::App->model('DB::User')
diff --git a/t/app/helpers/grey.gif b/t/app/helpers/grey.gif
new file mode 100644
index 000000000..98eee7d12
--- /dev/null
+++ b/t/app/helpers/grey.gif
Binary files differ
diff --git a/t/app/helpers/send_email.t b/t/app/helpers/send_email.t
index 14c7d363b..d1609cb2f 100644
--- a/t/app/helpers/send_email.t
+++ b/t/app/helpers/send_email.t
@@ -9,12 +9,16 @@ BEGIN {
FixMyStreet->test_mode(1);
}
-use Test::More tests => 5;
+use Test::More;
+use Test::LongString;
use Catalyst::Test 'FixMyStreet::App';
use Email::Send::Test;
-use Path::Class;
+use Path::Tiny;
+
+use FixMyStreet::TestMech;
+my $mech = FixMyStreet::TestMech->new;
my $c = ctx_request("/");
@@ -33,16 +37,66 @@ my @emails = Email::Send::Test->emails;
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 $email_as_string = $mech->get_first_email(@emails);
-my $expected_email_content = file(__FILE__)->dir->file('send_email_sample.txt')->slurp;
+my $expected_email_content = path(__FILE__)->parent->child('send_email_sample.txt')->slurp;
my $name = FixMyStreet->config('CONTACT_NAME');
$name = "\"$name\"" if $name =~ / /;
my $sender = $name . ' <' . FixMyStreet->config('DO_NOT_REPLY_EMAIL') . '>';
$expected_email_content =~ s{CONTACT_EMAIL}{$sender};
-is $email_as_string,
-$expected_email_content,
- "email is as expected";
+is_string $email_as_string, $expected_email_content, "email is as expected";
+
+subtest 'MIME attachments' => sub {
+ my $data = path(__FILE__)->parent->child('grey.gif')->slurp_raw;
+
+ Email::Send::Test->clear;
+ my @emails = Email::Send::Test->emails;
+ is scalar(@emails), 0, "reset";
+
+ ok $c->send_email( 'test.txt',
+ { to => 'test@recipient.com',
+ attachments => [
+ {
+ body => $data,
+ attributes => {
+ filename => 'foo.gif',
+ content_type => 'image/gif',
+ encoding => 'quoted-printable',
+ name => 'foo.gif',
+ },
+ },
+ {
+ body => $data,
+ attributes => {
+ filename => 'bar.gif',
+ content_type => 'image/gif',
+ encoding => 'quoted-printable',
+ name => 'bar.gif',
+ },
+ },
+ ]
+ } ), "sent an email with MIME attachments";
+
+ @emails = $mech->get_email;
+ is scalar(@emails), 1, "caught one email";
+
+ my $email_as_string = $mech->get_first_email(@emails);
+
+ my ($boundary) = $email_as_string =~ /boundary="([A-Za-z0-9.]*)"/ms;
+ my $changes = $email_as_string =~ s{$boundary}{}g;
+ is $changes, 5, '5 boundaries'; # header + 4 around the 3x parts (text + 2 images)
+
+ my $expected_email_content = path(__FILE__)->parent->child('send_email_sample_mime.txt')->slurp;
+ $expected_email_content =~ s{CONTACT_EMAIL}{$sender}g;
+
+ is_string $email_as_string, $expected_email_content, 'MIME email text ok'
+ or do {
+ (my $test_name = $0) =~ s{/}{_}g;
+ my $path = path("test-output-$test_name.tmp");
+ $path->spew($email_as_string);
+ diag "Saved output in $path";
+ };
+};
+
+done_testing;
diff --git a/t/app/helpers/send_email_sample_mime.txt b/t/app/helpers/send_email_sample_mime.txt
new file mode 100644
index 000000000..4ce0f9520
--- /dev/null
+++ b/t/app/helpers/send_email_sample_mime.txt
@@ -0,0 +1,57 @@
+MIME-Version: 1.0
+Subject: test email =?utf-8?Q?=E2=98=BA?=
+Content-Type: multipart/mixed; boundary=""
+To: test@recipient.com
+Content-Transfer-Encoding: 7bit
+From: CONTACT_EMAIL
+
+
+--
+MIME-Version: 1.0
+Subject: test email =?utf-8?Q?=E2=98=BA?=
+Content-Type: text/plain; charset="utf-8"
+To: test@recipient.com
+Content-Transfer-Encoding: quoted-printable
+From: CONTACT_EMAIL
+
+Hello,
+
+This is a test email where foo: bar.
+
+utf8: =E6=88=91=E4=BB=AC=E5=BA=94=E8=AF=A5=E8=83=BD=E5=A4=9F=E6=97=A0=E7=BC=
+=9D=E5=A4=84=E7=90=86UTF8=E7=BC=96=E7=A0=81
+
+ indented_text
+
+long line: Lorem ipsum dolor sit amet, consectetur adipisicing elit,
+sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
+nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+culpa qui officia deserunt mollit anim id est laborum.
+
+Yours,=20=20
+FixMyStreet.=20=
+
+
+
+--
+MIME-Version: 1.0
+Content-Type: image/gif; name="foo.gif"
+Content-Disposition: inline; filename="foo.gif"
+Content-Transfer-Encoding: quoted-printable
+
+GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00=
+=02=01L=00;=
+
+--
+MIME-Version: 1.0
+Content-Type: image/gif; name="bar.gif"
+Content-Disposition: inline; filename="bar.gif"
+Content-Transfer-Encoding: quoted-printable
+
+GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00=
+=02=01L=00;=
+
+----
diff --git a/t/app/model/photoset.t b/t/app/model/photoset.t
new file mode 100644
index 000000000..9e566f873
--- /dev/null
+++ b/t/app/model/photoset.t
@@ -0,0 +1,76 @@
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+use utf8;
+
+use FixMyStreet::App;
+use Data::Dumper;
+use DateTime;
+use Path::Tiny 'path';
+use File::Temp 'tempdir';
+
+my $dt = DateTime->now;
+
+my $c = FixMyStreet::App->new;
+my $UPLOAD_DIR = tempdir( CLEANUP => 1 );
+local $c->config->{UPLOAD_DIR} = $UPLOAD_DIR;
+
+my $user = $c->model('DB::User')->find_or_create({
+ name => 'Bob', email => 'bob@example.com',
+});
+
+my $image_path = path('t/app/controller/sample.jpg');
+
+my $db = FixMyStreet::App->model('DB')->schema;
+$db->txn_begin;
+
+sub make_report {
+ my $photo_data = shift;
+ return $db->resultset('Problem')->create({
+ postcode => 'BR1 3SB',
+ bodies_str => '',
+ areas => ",,",
+ category => 'Other',
+ title => 'test',
+ detail => 'test',
+ used_map => 't',
+ name => 'Anon',
+ anonymous => 't',
+ state => 'confirmed',
+ confirmed => $dt,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '51.4129',
+ longitude => '0.007831',
+ user => $user,
+ photo => $photo_data,
+ });
+}
+
+
+subtest 'Photoset with photo inline in DB' => sub {
+ my $report = make_report( $image_path->slurp );
+ my $photoset = $report->get_photoset($c);
+ is $photoset->num_images, 1, 'Found just 1 image';
+};
+
+$image_path->copy( path( $UPLOAD_DIR, '0123456789012345678901234567890123456789.jpeg' ) );
+subtest 'Photoset with 1 referenced photo' => sub {
+ my $report = make_report( '0123456789012345678901234567890123456789' );
+ my $photoset = $report->get_photoset($c);
+ is $photoset->num_images, 1, 'Found just 1 image';
+};
+
+subtest 'Photoset with 1 referenced photo' => sub {
+ my $report = make_report( '0123456789012345678901234567890123456789,0123456789012345678901234567890123456789,0123456789012345678901234567890123456789' );
+ my $photoset = $report->get_photoset($c);
+ is $photoset->num_images, 3, 'Found 3 images';
+};
+
+$db->txn_rollback;
+
+done_testing();