diff options
Diffstat (limited to 't')
-rw-r--r-- | t/app/controller/moderate.t | 10 | ||||
-rw-r--r-- | t/app/controller/photo.t | 75 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 7 | ||||
-rw-r--r-- | t/app/model/photoset.t | 76 | ||||
-rw-r--r-- | t/cobrand/zurich.t | 18 |
5 files changed, 175 insertions, 11 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/report_import.t b/t/app/controller/report_import.t index 16874ac3c..480fdd89f 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -364,11 +364,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/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(); diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 6394c8942..e1cb55b16 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -6,6 +6,7 @@ use warnings; use DateTime; use Test::More; use JSON; +use Path::Tiny; # Check that you have the required locale installed - the following # should return a line with de_CH.utf8 in. If not install that locale. @@ -21,6 +22,10 @@ my $c = FixMyStreet::App->new(); my $cobrand = FixMyStreet::Cobrand::Zurich->new({ c => $c }); $c->stash->{cobrand} = $cobrand; +my $sample_file = path(__FILE__)->parent->parent->child("app/controller/sample.jpg"); +ok $sample_file->exists, "sample file $sample_file exists"; +my $sample_photo = $sample_file->slurp_raw; + # This is a helper method that will send the reports but with the config # correctly set - notably SEND_REPORTS_ON_STAGING needs to be true. sub send_reports_for_zurich { @@ -103,6 +108,7 @@ my @reports = $mech->create_problems_for_body( 1, $division->id, 'Test', { state => 'unconfirmed', confirmed => undef, cobrand => 'zurich', + photo => $sample_photo, }); my $report = $reports[0]; @@ -136,7 +142,6 @@ $mech->content_contains( 'report_edit/' . $report->id ); $mech->content_contains( DateTime->now->strftime("%d.%m.%Y") ); $mech->content_contains( 'Erfasst' ); - subtest "changing of categories" => sub { # create a few categories (which are actually contacts) foreach my $name ( qw/Cat1 Cat2/ ) { @@ -213,11 +218,14 @@ subtest "report_edit" => sub { $mech->content_contains( 'Unbestätigt' ); # Unconfirmed email $mech->submit_form_ok( { with_fields => { state => 'confirmed' } } ); $mech->get_ok( '/report/' . $report->id ); + + $report->discard_changes(); + is $report->state, 'confirmed', 'state has been updated to confirmed'; }; $mech->content_contains('Aufgenommen'); $mech->content_contains('Test Test'); - $mech->content_lacks('photo/' . $report->id . '.jpeg'); + $mech->content_lacks('photo/' . $report->id . '.0.jpeg'); $mech->email_count_is(0); $report->discard_changes; @@ -302,7 +310,7 @@ FixMyStreet::override_config { $mech->get_ok( '/admin/report_edit/' . $report->id ); $mech->submit_form_ok( { with_fields => { state => 'confirmed', publish_photo => 1 } } ); $mech->get_ok( '/report/' . $report->id ); - $mech->content_contains('photo/' . $report->id . '.jpeg'); + $mech->content_contains('photo/' . $report->id . '.0.jpeg'); # Internal notes $mech->get_ok( '/admin/report_edit/' . $report->id ); @@ -424,6 +432,7 @@ $mech->clear_emails_ok; state => 'unconfirmed', confirmed => undef, cobrand => 'zurich', + photo => $sample_photo, }); $report = $reports[0]; @@ -458,6 +467,7 @@ $mech->email_count_is(0); state => 'unconfirmed', confirmed => undef, cobrand => 'zurich', + photo => $sample_photo, }); $report = $reports[0]; @@ -679,3 +689,5 @@ END { ok $mech->host("www.fixmystreet.com"), "change host back"; done_testing(); } + +1; |