aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller/photo.t
diff options
context:
space:
mode:
authorHakim Cassimally <hakim@mysociety.org>2015-01-27 18:32:02 +0000
committerDave Arter <davea@mysociety.org>2015-10-06 09:09:22 +0100
commita78bb3fc98dd1851e371c78d9743125d02baf04e (patch)
treebe8bb660db9c982ac6b0b2add70a82acc01f30b9 /t/app/controller/photo.t
parentccc71f8f2d4a514f6ffaab2f3bbc76ea423f212b (diff)
Add support for multiple photos per report.
For Zurich, see mysociety/FixMyStreet-Commercial#664. This commit includes a new PhotoSet class (NB: called Model:: though not really a model), should handle binary data (e.g. old style photos in database), fileids (40-char hash), and Catalyst::Upload objects.
Diffstat (limited to 't/app/controller/photo.t')
-rw-r--r--t/app/controller/photo.t75
1 files changed, 75 insertions, 0 deletions
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 &ndash; 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();