diff options
author | Hakim Cassimally <hakim@mysociety.org> | 2015-01-27 18:32:02 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2015-10-06 09:09:22 +0100 |
commit | a78bb3fc98dd1851e371c78d9743125d02baf04e (patch) | |
tree | be8bb660db9c982ac6b0b2add70a82acc01f30b9 /t/app/model | |
parent | ccc71f8f2d4a514f6ffaab2f3bbc76ea423f212b (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/model')
-rw-r--r-- | t/app/model/photoset.t | 76 |
1 files changed, 76 insertions, 0 deletions
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(); |