diff options
Diffstat (limited to 't')
58 files changed, 1041 insertions, 354 deletions
diff --git a/t/00-check-we-are-staging.t b/t/00-check-we-are-staging.t index 4c9a255fe..072b5df76 100644 --- a/t/00-check-we-are-staging.t +++ b/t/00-check-we-are-staging.t @@ -5,21 +5,12 @@ use Test::More; use FixMyStreet; -# check that all the fields listed in general-example are also present in -# general - helps prevent later test failures due to un-noticed additions to the -# config file. - -# This code will bail_out to prevent the test suite proceeding to save time if -# issues are found. - -# load the config file and store the contents in a readonly hash - -my $CONF_FILE = $ENV{FMS_OVERRIDE_CONFIG} || 'general'; -mySociety::Config::set_file( FixMyStreet->path_to("conf/${CONF_FILE}") ); +# check that we are running on staging BAIL_OUT( "Test suite modifies databases so should not be run on live servers" ) - unless mySociety::Config::get('STAGING_SITE', undef); + unless FixMyStreet->config('STAGING_SITE'); -ok mySociety::Config::get('STAGING_SITE', undef), 'staging server'; +my $staging = FixMyStreet->config('STAGING_SITE'); +ok $staging, 'staging server'; done_testing(); diff --git a/t/Mock/Facebook.pm b/t/Mock/Facebook.pm new file mode 100644 index 000000000..eb882af21 --- /dev/null +++ b/t/Mock/Facebook.pm @@ -0,0 +1,52 @@ +package t::Mock::Facebook; + +use JSON::MaybeXS; +use Web::Simple; +use MooX::Types::MooseLike::Base qw(:all); + +has json => ( + is => 'lazy', + default => sub { + JSON->new->pretty->allow_blessed->convert_blessed; + }, +); + +has returns_email => ( + is => 'rw', + isa => Bool, + default => 1, +); + +sub dispatch_request { + my $self = shift; + + sub (GET + /v2.2/dialog/oauth + ?*) { + my ($self) = @_; + return [ 200, [ 'Content-Type' => 'text/html' ], [ 'FB login page' ] ]; + }, + + sub (GET + /v2.2/oauth/access_token + ?*) { + my ($self) = @_; + return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'access_token=access_token&expires=never' ] ]; + }, + + sub (GET + /me + ?fields=) { + my ($self, $fields) = @_; + my $data = { + id => '123456789', + name => 'Fiona Tester', + }; + $data->{email} = 'facebook@example.org' if $self->returns_email; + my $json = $self->json->encode($data); + return [ 200, [ 'Content-Type' => 'text/html' ], [ $json ] ]; + }, + + sub (GET + /search + ?q=) { + my ($self, $q) = @_; + my $response = $self->query($q); + my $json = $self->json->encode($response); + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, +} + +__PACKAGE__->run_if_script; diff --git a/t/MapIt.pm b/t/Mock/MapIt.pm index a10118013..754cc327e 100644 --- a/t/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -1,6 +1,6 @@ -package t::MapIt; +package t::Mock::MapIt; -use JSON; +use JSON::MaybeXS; use Web::Simple; use mySociety::Locale; diff --git a/t/Mock/MapItZurich.pm b/t/Mock/MapItZurich.pm new file mode 100644 index 000000000..ece9a9b22 --- /dev/null +++ b/t/Mock/MapItZurich.pm @@ -0,0 +1,43 @@ +package t::Mock::MapItZurich; + +use JSON::MaybeXS; +use Web::Simple; + +use mySociety::Locale; + +has json => ( + is => 'lazy', + default => sub { + JSON->new->pretty->allow_blessed->convert_blessed; + }, +); + +sub dispatch_request { + my $self = shift; + + sub (GET + /areas/**) { + my ($self, $areas) = @_; + my $response = { + "423017" => {"parent_area" => undef, "generation_high" => 4, "all_names" => {}, "id" => 423017, "codes" => {}, "name" => "Zurich", "country" => "G", "type_name" => "OpenStreetMap Layer 8", "generation_low" => 4, "country_name" => "Global", "type" => "O08"} + }; + my $json = $self->json->encode($response); + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, + + sub (GET + /point/**) { + my ($self, $point) = @_; + my $response = { + "423017" => {"parent_area" => undef, "generation_high" => 4, "all_names" => {}, "id" => 423017, "codes" => {}, "name" => "Zurich", "country" => "G", "type_name" => "OpenStreetMap Layer 8", "generation_low" => 4, "country_name" => "Global", "type" => "O08"} + }; + my $json = $self->json->encode($response); + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, + + sub (GET + /area/*/example_postcode) { + my ($self, $area) = @_; + my $json = $self->json->encode({}); + return [ 200, [ 'Content-Type' => 'application/json' ], [ $json ] ]; + }, +} + +__PACKAGE__->run_if_script; diff --git a/t/Nominatim.pm b/t/Mock/Nominatim.pm index 2041b4677..5c8c549d1 100644 --- a/t/Nominatim.pm +++ b/t/Mock/Nominatim.pm @@ -1,6 +1,6 @@ -package t::Nominatim; +package t::Mock::Nominatim; -use JSON; +use JSON::MaybeXS; use Web::Simple; has json => ( diff --git a/t/Mock/Static.pm b/t/Mock/Static.pm new file mode 100644 index 000000000..260c181cd --- /dev/null +++ b/t/Mock/Static.pm @@ -0,0 +1,18 @@ +package t::Mock::Static; + +use Path::Tiny; +use Web::Simple; + +my $sample_file = path(__FILE__)->parent->parent->child("app/controller/sample.jpg"); +my $sample_photo = $sample_file->slurp_raw; + +sub dispatch_request { + my $self = shift; + + sub (GET + /image.jpeg) { + my ($self) = @_; + return [ 200, [ 'Content-Type' => 'image/jpeg' ], [ $sample_photo ] ]; + }, +} + +__PACKAGE__->run_if_script; diff --git a/t/app/01app.t b/t/app/01app.t index 02ffcd217..eb98b6319 100644 --- a/t/app/01app.t +++ b/t/app/01app.t @@ -1,10 +1,27 @@ #!/usr/bin/env perl + use strict; use warnings; -use Test::More; +package FixMyStreet::Cobrand::Tester; +use parent 'FixMyStreet::Cobrand::FiksGataMi'; +sub front_stats_data { { new => 0, fixed => 0, updates => 12345 } } + +package main; + +use Test::More; use Catalyst::Test 'FixMyStreet::App'; +use charnames ':full'; +use Encode qw(encode); ok( request('/')->is_success, 'Request should succeed' ); +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ 'tester' ], +}, sub { + my $page = get('/'); + my $num = encode('UTF-8', "12\N{NO-BREAK SPACE}345"); + like $page, qr/$num/; +}; + done_testing(); diff --git a/t/app/controller/about.t b/t/app/controller/about.t index fb0744d6a..6a082a2ff 100644 --- a/t/app/controller/about.t +++ b/t/app/controller/about.t @@ -7,10 +7,19 @@ use Test::WWW::Mechanize::Catalyst 'FixMyStreet::App'; ok( my $mech = Test::WWW::Mechanize::Catalyst->new, 'Created mech object' ); # check that we can get the page -$mech->get_ok('/about'); -$mech->content_like(qr{About us ::\s+FixMyStreet}); +$mech->get_ok('/faq'); +$mech->content_like(qr{Frequently Asked Questions ::\s+FixMyStreet}); $mech->content_contains('html class="no-js" lang="en-gb"'); +$mech->get_ok('/privacy'); +is $mech->res->code, 200, "got 200 for final destination"; +is $mech->res->previous->code, 302, "got 302 for redirect"; +is $mech->uri->path, '/about/privacy'; + +$mech->get('/about/page-that-does-not-exist'); +ok !$mech->res->is_success(), "want a bad response"; +is $mech->res->code, 404, "got 404"; + FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'emptyhomes' ], }, sub { diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index e2dd5df19..92cbbc00f 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -6,18 +6,11 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; -my $secret = FixMyStreet::App->model('DB::Secret')->search(); - -# don't explode if there's nothing in the secret table -if ( $secret == 0 ) { - diag "You need to put an entry in the secret table for the admin tests to run"; - plan skip_all => 'No entry in secret table'; -} - my $user = FixMyStreet::App->model('DB::User') - ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); + ->find_or_create( { email => 'test@example.com' } ); ok $user, "created test user"; +$user->update({ name => 'Test User' }); my $user2 = FixMyStreet::App->model('DB::User') @@ -70,8 +63,8 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( { - alert_type => 'new_updates', - parameter => $report->id, + alert_type => 'area_problems', + parameter => 2482, confirmed => 1, user => $user, }, @@ -1240,9 +1233,7 @@ subtest "Check admin_base_url" => sub { my $rs = FixMyStreet::App->model('DB::Problem'); my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($report->cobrand)->new(); - is (FixMyStreet::App->model('DB::Problem')->get_admin_url( - $cobrand, - $report), + is ($report->admin_url($cobrand), (sprintf 'https://secure.mysociety.org/admin/bci/report_edit/%d', $report_id), 'get_admin_url OK'); }; diff --git a/t/app/controller/alert.t b/t/app/controller/alert.t index 5bf2af428..c7dc9ed09 100644 --- a/t/app/controller/alert.t +++ b/t/app/controller/alert.t @@ -6,7 +6,7 @@ use LWP::Protocol::PSGI; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; -use t::Nominatim; +use t::Mock::Nominatim; # check that we can get the page $mech->get_ok('/alert'); @@ -42,7 +42,7 @@ FixMyStreet::override_config { $mech->content_contains('ward:2651:20728:City_of_Edinburgh:City_Centre'); subtest "Test Nominatim lookup" => sub { - LWP::Protocol::PSGI->register(t::Nominatim->run_if_script, host => 'nominatim.openstreetmap.org'); + LWP::Protocol::PSGI->register(t::Mock::Nominatim->run_if_script, host => 'nominatim.openstreetmap.org'); $mech->get_ok('/alert/list?pc=High Street'); $mech->content_contains('We found more than one match for that location'); }; diff --git a/t/app/controller/around.t b/t/app/controller/around.t index a70116525..89ca5246e 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -3,7 +3,7 @@ use warnings; use Test::More; use LWP::Protocol::PSGI; -use t::MapIt; +use t::Mock::MapIt; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -84,7 +84,7 @@ foreach my $test ( ) { subtest "check lat/lng for '$test->{pc}'" => sub { - LWP::Protocol::PSGI->register(t::MapIt->run_if_script, host => 'mapit.uk'); + LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); $mech->get_ok('/'); FixMyStreet::override_config { diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t new file mode 100644 index 000000000..84fdd4dfe --- /dev/null +++ b/t/app/controller/auth_social.t @@ -0,0 +1,143 @@ +use strict; +use warnings; +use Test::More; +use LWP::Protocol::PSGI; +use LWP::Simple; +use JSON::MaybeXS; + +use t::Mock::Facebook; +use t::Mock::MapIt; + +use FixMyStreet::TestMech; +my $mech = FixMyStreet::TestMech->new; + +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + +my ($report) = $mech->create_problems_for_body(1, '2345', 'Test'); + +LWP::Protocol::PSGI->register(t::Mock::MapIt->to_psgi_app, host => 'mapit.uk'); + +FixMyStreet::override_config { + FACEBOOK_APP_ID => 'facebook-app-id', + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.uk/', +}, sub { + +my $fb_email = 'facebook@example.org'; +my $fb_uid = 123456789; + +for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) { + for my $page ( 'my', 'report', 'update' ) { + subtest "test FB '$fb_state' login for page '$page'" => sub { + $mech->log_out_ok; + if ($fb_state eq 'existing UID') { + my $user = $mech->create_user_ok($fb_email); + $user->update({ facebook_id => $fb_uid }); + } else { + $mech->delete_user($fb_email); + } + + # Set up a mock to catch (most, see below) requests to Facebook + my $fb = t::Mock::Facebook->new; + $fb->returns_email(0) if $fb_state eq 'no email' || $fb_state eq 'existing UID'; + LWP::Protocol::PSGI->register($fb->to_psgi_app, host => 'www.facebook.com'); + LWP::Protocol::PSGI->register($fb->to_psgi_app, host => 'graph.facebook.com'); + + # Due to https://metacpan.org/pod/Test::WWW::Mechanize::Catalyst#External-Redirects-and-allow_external + # the redirect to Facebook's OAuth page can mess up the session + # cookie. So let's pretend we always on www.facebook.com, which + # sorts that out. + $mech->host('www.facebook.com'); + + # Fetch the page with the form via which we wish to log in + my $fields; + if ($page eq 'my') { + $mech->get_ok('/my'); + } elsif ($page eq 'report') { + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => 'SW1A1AA' } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + $fields = { + title => 'Test title', + detail => 'Test detail', + }; + } else { + $mech->get_ok('/report/' . $report->id); + $fields = { + update => 'Test update', + }; + } + $mech->submit_form(with_fields => $fields, button => 'facebook_sign_in'); + + # As well as the cookie issue above, caused by this external + # redirect rewriting the host, the redirect gets handled directly + # by Catalyst, not our mocked handler, so will be a 404. Check + # the redirect happened instead. + is $mech->res->previous->code, 302, 'FB button redirected'; + like $mech->res->previous->header('Location'), qr{facebook\.com.*dialog/oauth.*facebook-app-id}, 'FB redirect to oauth URL'; + + # Okay, now call the callback Facebook would send us to + if ($fb_state eq 'refused') { + $mech->get_ok('/auth/Facebook?error_code=ERROR'); + } else { + $mech->get_ok('/auth/Facebook?code=response-code'); + } + + # Check we're showing the right form, regardless of what came back + if ($page eq 'report') { + $mech->content_contains('/report/new'); + } elsif ($page eq 'update') { + $mech->content_contains('/report/update'); + } + + if ($fb_state eq 'refused') { + $mech->content_contains('Sorry, we could not log you in. Please fill in the form below.'); + $mech->not_logged_in_ok; + } elsif ($fb_state eq 'no email') { + $mech->content_contains('We need your email address, please give it below.'); + # We don't have an email, so check that we can still submit it, + # and the ID carries through the confirmation + if ($page eq 'update') { + $fields->{rznvy} = $fb_email; + } else { + $fields->{email} = $fb_email; + } + $fields->{name} = 'Ffion Tester'; + $mech->submit_form(with_fields => $fields); + $mech->content_contains('Nearly done! Now check your email'); + + my $email = $mech->get_email; + ok $email, "got an email"; + $mech->clear_emails_ok; + my ( $url, $url_token ) = $email->body =~ m{(https?://\S+/[CMP]/)(\S+)}; + ok $url, "extracted confirm url '$url'"; + + my $user = FixMyStreet::App->model( 'DB::User' )->find( { email => $fb_email } ); + if ($page eq 'my') { + is $user, undef, 'No user yet exists'; + } else { + is $user->facebook_id, undef, 'User has no facebook ID'; + } + $mech->get_ok( $url . $url_token ); + $user = FixMyStreet::App->model( 'DB::User' )->find( { email => $fb_email } ); + is $user->facebook_id, $fb_uid, 'User now has correct facebook ID'; + + } elsif ($page ne 'my') { + # /my auth login goes directly there, no message like this + $mech->content_contains('You have successfully signed in; please check and confirm your details are accurate'); + $mech->logged_in_ok; + } else { + is $mech->uri->path, '/my', 'Successfully on /my page'; + } + } + } +} + +}; + +END { + $mech->delete_problems_for_body('2345'); + done_testing(); +} diff --git a/t/app/controller/my.t b/t/app/controller/my.t index b723e537e..d24a66c8e 100644 --- a/t/app/controller/my.t +++ b/t/app/controller/my.t @@ -9,12 +9,17 @@ my $mech = FixMyStreet::TestMech->new; $mech->get_ok('/my'); is $mech->uri->path, '/auth', "got sent to the sign in page"; +$mech->create_problems_for_body(1, 1234, 'Test Title'); + # sign in my $user = $mech->log_in_ok( 'test@example.com' ); $mech->get_ok('/my'); is $mech->uri->path, '/my', "stayed on '/my/' page"; +# Report listed +$mech->content_contains('Test Title'); + # cleanup $mech->delete_user( $user ); - +$mech->delete_problems_for_body(1234); done_testing(); diff --git a/t/app/controller/page_not_found.t b/t/app/controller/page_not_found.t index 05e983109..3c2bc3c3d 100644 --- a/t/app/controller/page_not_found.t +++ b/t/app/controller/page_not_found.t @@ -1,5 +1,3 @@ -#!/usr/bin/perl - use strict; use warnings; diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t index 6e61ebb32..39380e769 100644 --- a/t/app/controller/photo.t +++ b/t/app/controller/photo.t @@ -64,6 +64,9 @@ subtest "Check multiple upload worked" => sub { ); ok $mech->success, 'Made request with multiple photo upload'; $mech->base_is('http://localhost/report/new'); + $mech->content_like( + qr[(<img align="right" src="/photo/1cdd4329ceee2234bd4e89cb33b42061a0724687.temp.jpeg" alt="">\s*){3}], + 'Three uploaded pictures are all shown, safe'); $mech->content_contains( 'name="upload_fileid" value="1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687"', 'Returned upload_fileid contains expected hash, 3 times'); diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t index 2a89454d5..7718d5034 100644 --- a/t/app/controller/questionnaire.t +++ b/t/app/controller/questionnaire.t @@ -87,7 +87,7 @@ foreach my $test ( { desc => 'User goes to questionnaire URL with a bad token', token_extra => 'BAD', - content => "we couldn't validate that token", + content => "Sorry, that wasn’t a valid link", }, { desc => 'User goes to questionnaire URL for a now-hidden problem', diff --git a/t/app/controller/report_import.t b/t/app/controller/report_import.t index 4d0f6e5d1..26acf7790 100644 --- a/t/app/controller/report_import.t +++ b/t/app/controller/report_import.t @@ -3,7 +3,7 @@ use warnings; use Test::More; use LWP::Protocol::PSGI; -use t::MapIt; +use t::Mock::MapIt; use FixMyStreet::TestMech; use FixMyStreet::App; use Web::Scraper; @@ -92,7 +92,7 @@ subtest "Test creating bad partial entries" => sub { }; subtest "Submit a correct entry" => sub { - LWP::Protocol::PSGI->register(t::MapIt->run_if_script, host => 'mapit.uk'); + LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.uk'); $mech->get_ok('/import'); @@ -153,10 +153,13 @@ subtest "Submit a correct entry" => sub { name => 'Test User', title => 'Test report', detail => 'This is a test report', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', phone => '', may_show_name => '1', category => '-- Pick a category --', + gender => undef, }, "check imported fields are shown"; @@ -187,10 +190,13 @@ subtest "Submit a correct entry" => sub { name => 'Test User', title => 'Test report', detail => 'This is a test report', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', phone => '', may_show_name => '1', category => '-- Pick a category --', + gender => undef, }, "check imported fields are shown"; @@ -275,10 +281,13 @@ subtest "Submit a correct entry (with location)" => sub { name => 'Test User ll', title => 'Test report ll', detail => 'This is a test report ll', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', phone => '', may_show_name => '1', category => '-- Pick a category --', + gender => undef, }, "check imported fields are shown"; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 3c05adfbd..cf72221b4 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -103,7 +103,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -127,7 +129,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -154,7 +158,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -178,7 +184,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => undef, email => '', @@ -202,7 +210,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => undef, email => '', @@ -225,7 +235,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => '1', email => '', @@ -248,7 +260,9 @@ foreach my $test ( fields => { title => "DOG SHIT\r\nON WALLS", detail => "on this portakabin -\r\n\r\nmore of a portaloo HEH!!", - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => '1', email => '', @@ -271,7 +285,9 @@ foreach my $test ( fields => { title => 'Test title', detail => 'Test detail', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'DUDE', may_show_name => '1', email => '', @@ -293,7 +309,9 @@ foreach my $test ( fields => { title => 'Test title', detail => 'Test detail', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'anonymous', may_show_name => '1', email => '', @@ -315,7 +333,9 @@ foreach my $test ( fields => { title => 'Test title', detail => 'Test detail', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => 'Joe Smith', may_show_name => '1', email => 'not an email', @@ -334,7 +354,9 @@ foreach my $test ( fields => { title => " Test title ", detail => " first line \n\n second\nline\n\n ", - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -359,7 +381,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => ' Bob Jones ', may_show_name => '1', email => ' BOB @ExAmplE.COM ', @@ -381,7 +405,9 @@ foreach my $test ( fields => { title => 'Title', detail => 'Detail', - photo => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ], + photo1 => [ [ undef, 'bad.txt', Content => 'This is not a JPEG', Content_Type => 'text/plain' ], 1 ], + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => '1', email => 'bob@example.com', @@ -392,7 +418,7 @@ foreach my $test ( remember_me => undef, }, changes => { - photo => '', + photo1 => '', }, errors => [ "Please upload a JPEG image only" ], }, @@ -402,7 +428,9 @@ foreach my $test ( fields => { title => 'Title', detail => 'Detail', - photo => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ], + photo1 => [ [ undef, 'fake.jpeg', Content => 'This is not a JPEG', Content_Type => 'image/jpeg' ], 1 ], + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => '1', email => 'bob@example.com', @@ -413,7 +441,7 @@ foreach my $test ( remember_me => undef, }, changes => { - photo => '', + photo1 => '', }, errors => [ "That image doesn't appear to have uploaded correctly (Please upload a JPEG image only ), please try again." ], }, @@ -423,7 +451,9 @@ foreach my $test ( fields => { title => '', detail => 'Detail', - photo => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ], + photo1 => [ [ $sample_file, undef, Content_Type => 'application/octet-stream' ], 1 ], + photo2 => '', + photo3 => '', name => 'Bob Jones', may_show_name => '1', email => 'bob@example.com', @@ -434,7 +464,7 @@ foreach my $test ( remember_me => undef, }, changes => { - photo => '', + photo1 => '', }, errors => [ "Please enter a subject" ], }, @@ -468,6 +498,7 @@ foreach my $test ( my $new_values = { %{ $test->{fields} }, # values added to form %{ $test->{changes} }, # changes we expect + gender => undef, }; is_deeply $mech->visible_form_values, $new_values, "values correctly changed"; @@ -534,7 +565,7 @@ foreach my $test ( with_fields => { title => 'Test Report', detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', may_show_name => '1', email => 'test-1@example.com', @@ -652,7 +683,7 @@ subtest "test password errors for a user who is signing in as they report" => su with_fields => { title => 'Test Report', detail => 'Test report details.', - photo => '', + photo1 => '', email => 'test-2@example.com', password_sign_in => 'secret1', category => 'Street lighting', @@ -704,7 +735,7 @@ subtest "test report creation for a user who is signing in as they report" => su with_fields => { title => 'Test Report', detail => 'Test report details.', - photo => '', + photo1 => '', email => 'test-2@example.com', password_sign_in => 'secret2', category => 'Street lighting', @@ -803,8 +834,11 @@ foreach my $test ( may_show_name => '1', name => 'Test User', phone => '01234 567 890', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', category => '-- Pick a category --', + gender => undef, }, "user's details prefilled" ); @@ -814,7 +848,7 @@ foreach my $test ( with_fields => { title => "Test Report at café", detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', may_show_name => '1', phone => '07903 123 456', @@ -898,7 +932,7 @@ subtest "test report creation for a category that is non public" => sub { with_fields => { title => 'Test Report', detail => 'Test report details.', - photo => '', + photo1 => '', email => 'test-2@example.com', name => 'Joe Bloggs', category => 'Street lighting', @@ -1087,7 +1121,7 @@ for my $test ( my $submission_fields = { title => "Test Report", detail => 'Test report details.', - photo => '', + photo1 => '', email => 'firstlast@example.com', may_show_name => '1', phone => '07903 123 456', @@ -1156,7 +1190,7 @@ subtest 'user title not reset if no user title in submission' => sub { my $submission_fields = { title => "Test Report", detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Has Title', may_show_name => '1', phone => '07903 123 456', @@ -1250,7 +1284,7 @@ subtest "test Hart" => sub { with_fields => { title => 'Test Report', detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', may_show_name => '1', category => $test->{category}, @@ -1484,7 +1518,7 @@ subtest "unresponsive body handling works" => sub { with_fields => { title => "Test Report at café", detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', email => $test_email, may_show_name => '1', @@ -1523,7 +1557,7 @@ subtest "unresponsive body handling works" => sub { with_fields => { title => "Test Report at café", detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', email => $test_email, may_show_name => '1', @@ -1604,7 +1638,7 @@ subtest "extra google analytics code displayed on logged in problem creation" => with_fields => { title => "Test Report at café", detail => 'Test report details.', - photo => '', + photo1 => '', name => 'Joe Bloggs', may_show_name => '1', phone => '07903 123 456', @@ -1646,7 +1680,7 @@ subtest "extra google analytics code displayed on email confirmation problem cre my $submission_fields = { title => "Test Report", detail => 'Test report details.', - photo => '', + photo1 => '', email => 'firstlast@example.com', name => 'Test User', may_show_name => '1', diff --git a/t/app/controller/report_new_mobile.t b/t/app/controller/report_new_mobile.t new file mode 100644 index 000000000..61cb14a1b --- /dev/null +++ b/t/app/controller/report_new_mobile.t @@ -0,0 +1,38 @@ +use Test::More; +use FixMyStreet::TestMech; + +my $mech = FixMyStreet::TestMech->new; + +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + +subtest "Check signed up for alert when logged in" => sub { + FixMyStreet::override_config { + MAPIT_URL => 'http://global.mapit.mysociety.org', + MAPIT_TYPES => [ 'O06' ], + }, sub { + $mech->log_in_ok('user@example.org'); + $mech->post_ok( '/report/new/mobile', { + service => 'iPhone', + title => 'Title', + detail => 'Problem detail', + lat => 47.381817, + lon => 8.529156, + email => 'user@example.org', + pc => '', + name => 'Name', + }); + my $res = $mech->response; + ok $res->header('Content-Type') =~ m{^application/json\b}, 'response should be json'; + + my $user = FixMyStreet::DB->resultset('User')->search({ email => 'user@example.org' })->first; + my $a = FixMyStreet::DB->resultset('Alert')->search({ user_id => $user->id })->first; + isnt $a, undef, 'User is signed up for alert'; + }; +}; + +END { + $mech->delete_user('user@example.org'); + done_testing(); +} diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t index d3ca93f0e..22b37fd55 100644 --- a/t/app/controller/report_new_open311.t +++ b/t/app/controller/report_new_open311.t @@ -45,7 +45,9 @@ foreach my $test ( fields => { title => '', detail => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', name => '', may_show_name => '1', email => '', @@ -129,6 +131,7 @@ foreach my $test ( my $new_values = { %{ $test->{fields} }, # values added to form %{ $test->{changes} }, # changes we expect + gender => undef, }; is_deeply $mech->visible_form_values, $new_values, "values correctly changed"; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 6c6b4ca19..f9f5189e5 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -199,7 +199,9 @@ for my $test ( rznvy => '', update => '', name => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', fixed => undef, add_alert => 1, may_show_name => undef, @@ -216,7 +218,9 @@ for my $test ( rznvy => 'test', update => '', name => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', fixed => undef, add_alert => 1, may_show_name => undef, @@ -233,7 +237,9 @@ for my $test ( rznvy => 'test @ example. com', update => '', name => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', fixed => undef, add_alert => 1, may_show_name => undef, @@ -252,7 +258,9 @@ for my $test ( rznvy => 'test@EXAMPLE.COM', update => '', name => '', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', fixed => undef, add_alert => 1, may_show_name => undef, @@ -292,7 +300,9 @@ for my $test ( rznvy => '', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, remember_me => undef, @@ -316,7 +326,9 @@ for my $test ( rznvy => '', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, remember_me => undef, @@ -417,7 +429,9 @@ for my $test ( rznvy => '', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, remember_me => undef, @@ -502,7 +516,9 @@ subtest 'check non authority user cannot change set state' => sub { name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'this is a forbidden update', state => 'fixed - council', }, @@ -530,7 +546,9 @@ for my $state ( qw/unconfirmed hidden partial/ ) { name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'this is a forbidden update', state => $state, }, @@ -553,7 +571,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to investigating', state => 'investigating', }, @@ -565,7 +585,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to in progress', state => 'in progress', }, @@ -577,7 +599,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to fixed', state => 'fixed', }, @@ -589,7 +613,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to action scheduled', state => 'action scheduled', }, @@ -601,7 +627,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to unable to fix', state => 'unable to fix', }, @@ -613,7 +641,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to internal referral', state => 'internal referral', }, @@ -626,7 +656,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to not responsible', state => 'not responsible', }, @@ -639,7 +671,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to duplicate', state => 'duplicate', }, @@ -652,7 +686,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to internal referral', state => 'internal referral', }, @@ -665,7 +701,9 @@ for my $test ( name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Set state to fixed', state => 'fixed', }, @@ -783,7 +821,9 @@ subtest "check comment with no status change has not status in meta" => sub { name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Comment that does not change state', }, }, @@ -813,7 +853,9 @@ subtest "check comment with no status change has not status in meta" => sub { name => $user->name, may_show_name => 1, add_alert => undef, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => 'Comment that sets state to investigating', state => 'investigating', }, @@ -1049,6 +1091,9 @@ subtest 'submit an update for a registered user, creating update by email' => su $mech->delete_user( $user ); }; +my $sample_file = file(__FILE__)->parent->file("sample.jpg")->stringify; +ok -e $sample_file, "sample file $sample_file exists"; + for my $test ( { desc => 'submit update for registered user', @@ -1056,7 +1101,9 @@ for my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1066,6 +1113,7 @@ for my $test ( update => 'update from a registered user', add_alert => undef, fixed => undef, + photo1 => [ [ $sample_file, undef, Content_Type => 'image/jpeg' ], 1 ], }, changed => { update => 'Update from a registered user' @@ -1081,7 +1129,9 @@ for my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1107,7 +1157,9 @@ for my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1132,7 +1184,9 @@ for my $test ( name => 'Commenter', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1157,7 +1211,9 @@ for my $test ( name => 'Commenter', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', }, email => 'commenter@example.com', @@ -1210,6 +1266,11 @@ for my $test ( $mech->content_contains("/report/" . $report_id); $mech->get_ok("/report/" . $report_id); + my $update = $report->comments->first; + ok $update, 'found update'; + + $mech->content_contains("/photo/c/" . $update->id . ".0.jpeg") if $test->{fields}->{photo1}; + if ( !defined( $test->{endstate_banner} ) ) { is $mech->extract_problem_banner->{text}, undef, 'endstate banner'; } else { @@ -1223,8 +1284,6 @@ for my $test ( %{ $test->{changed} }, }; - my $update = $report->comments->first; - ok $update, 'found update'; is $update->text, $results->{update}, 'update text'; is $update->user->email, $test->{email}, 'update user'; is $update->state, 'confirmed', 'update confirmed'; @@ -1245,7 +1304,9 @@ foreach my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1271,7 +1332,9 @@ foreach my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1298,7 +1361,9 @@ foreach my $test ( name => 'Test User', may_show_name => 1, add_alert => 1, - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', update => '', fixed => undef, }, @@ -1771,7 +1836,9 @@ for my $test ( my %standard_fields = ( name => $report->user->name, update => 'update text', - photo => '', + photo1 => '', + photo2 => '', + photo3 => '', may_show_name => 1, add_alert => 1, ); diff --git a/t/app/controller/rss.t b/t/app/controller/rss.t index db653c094..3e820cff3 100644 --- a/t/app/controller/rss.t +++ b/t/app/controller/rss.t @@ -181,7 +181,7 @@ my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_c subtest "check RSS feeds on cobrand have correct URLs for non-cobrand reports" => sub { $mech->host('hart.fixmystreet.com'); - my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id; + my $expected1 = FixMyStreet->config('BASE_URL') . '/report/' . $report_to_county_council->id; my $expected2; FixMyStreet::override_config { diff --git a/t/app/helpers/send_email.t b/t/app/helpers/send_email.t index d1609cb2f..f60f7fa5a 100644 --- a/t/app/helpers/send_email.t +++ b/t/app/helpers/send_email.t @@ -1,5 +1,3 @@ -#!/usr/bin/perl - use strict; use warnings; use utf8; @@ -9,6 +7,7 @@ BEGIN { FixMyStreet->test_mode(1); } +use Email::MIME; use Test::More; use Test::LongString; @@ -38,14 +37,17 @@ is scalar(@emails), 1, "caught one email"; # Get the email, check it has a date and then strip it out my $email_as_string = $mech->get_first_email(@emails); +my $email = Email::MIME->new($email_as_string); 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}; +my $expected_email = Email::MIME->new($expected_email_content); -is_string $email_as_string, $expected_email_content, "email is as expected"; +is_deeply { $email->header_pairs }, { $expected_email->header_pairs }, 'MIME email headers ok'; +is_string $email->body, $expected_email->body, 'email is as expected'; subtest 'MIME attachments' => sub { my $data = path(__FILE__)->parent->child('grey.gif')->slurp_raw; @@ -82,15 +84,25 @@ subtest 'MIME attachments' => sub { 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 $email = Email::MIME->new($email_as_string); 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' + $expected_email_content =~ s{BOUNDARY}{$boundary}g; + my $expected_email = Email::MIME->new($expected_email_content); + + my @email_parts; + $email->walk_parts(sub { + my ($part) = @_; + push @email_parts, [ { $part->header_pairs }, $part->body ]; + }); + my @expected_email_parts; + $expected_email->walk_parts(sub { + my ($part) = @_; + push @expected_email_parts, [ { $part->header_pairs }, $part->body ]; + }); + is_deeply \@email_parts, \@expected_email_parts, 'MIME email text ok' or do { (my $test_name = $0) =~ s{/}{_}g; my $path = path("test-output-$test_name.tmp"); diff --git a/t/app/helpers/send_email_sample_mime.txt b/t/app/helpers/send_email_sample_mime.txt index 4ce0f9520..c4ca97bcc 100644 --- a/t/app/helpers/send_email_sample_mime.txt +++ b/t/app/helpers/send_email_sample_mime.txt @@ -1,12 +1,12 @@ MIME-Version: 1.0 Subject: test email =?utf-8?Q?=E2=98=BA?= -Content-Type: multipart/mixed; boundary="" +Content-Type: multipart/mixed; boundary="BOUNDARY" To: test@recipient.com Content-Transfer-Encoding: 7bit From: CONTACT_EMAIL --- +--BOUNDARY MIME-Version: 1.0 Subject: test email =?utf-8?Q?=E2=98=BA?= Content-Type: text/plain; charset="utf-8" @@ -36,7 +36,7 @@ FixMyStreet.=20= --- +--BOUNDARY MIME-Version: 1.0 Content-Type: image/gif; name="foo.gif" Content-Disposition: inline; filename="foo.gif" @@ -45,7 +45,7 @@ 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;= --- +--BOUNDARY MIME-Version: 1.0 Content-Type: image/gif; name="bar.gif" Content-Disposition: inline; filename="bar.gif" @@ -54,4 +54,4 @@ 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;= ----- +--BOUNDARY-- diff --git a/t/app/load_general_config.t b/t/app/load_general_config.t index 3855c2565..1051aac3f 100644 --- a/t/app/load_general_config.t +++ b/t/app/load_general_config.t @@ -1,5 +1,3 @@ -#!/usr/bin/perl -w - use strict; use warnings; diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t index 2620dd68c..0130f404e 100644 --- a/t/app/model/alert_type.t +++ b/t/app/model/alert_type.t @@ -9,21 +9,21 @@ my $mech = FixMyStreet::TestMech->new(); # this is the easiest way to make sure we're not going # to get any emails sent by data kicking about in the database -FixMyStreet::App->model('DB::AlertType')->email_alerts(); +FixMyStreet::DB->resultset('AlertType')->email_alerts(); $mech->clear_emails_ok; my $user = - FixMyStreet::App->model('DB::User') + FixMyStreet::DB->resultset('User') ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); ok $user, "created test user"; my $user2 = - FixMyStreet::App->model('DB::User') + FixMyStreet::DB->resultset('User') ->find_or_create( { email => 'commenter@example.com', name => 'Commenter' } ); ok $user2, "created comment user"; my $user3 = - FixMyStreet::App->model('DB::User') + FixMyStreet::DB->resultset('User') ->find_or_create( { email => 'bystander@example.com', name => 'Bystander' } ); ok $user3, "created bystander"; @@ -36,7 +36,7 @@ my $dt = DateTime->new( second => 23 ); -my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( +my $report = FixMyStreet::DB->resultset('Problem')->find_or_create( { postcode => 'SW1A 1AA', bodies_str => '2504', @@ -62,7 +62,7 @@ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( my $report_id = $report->id; ok $report, "created test report - $report_id"; -my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( +my $comment = FixMyStreet::DB->resultset('Comment')->find_or_create( { problem_id => $report_id, user_id => $user2->id, @@ -74,7 +74,7 @@ my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( anonymous => 'f', } ); -my $comment2 = FixMyStreet::App->model('DB::Comment')->find_or_create( +my $comment2 = FixMyStreet::DB->resultset('Comment')->find_or_create( { problem_id => $report_id, user_id => $user2->id, @@ -90,7 +90,7 @@ my $comment2 = FixMyStreet::App->model('DB::Comment')->find_or_create( $comment->confirmed( \"current_timestamp - '3 days'::interval" ); $comment->update; -my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( +my $alert = FixMyStreet::DB->resultset('Alert')->find_or_create( { user => $user, parameter => $report_id, @@ -101,7 +101,7 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create( } ); -my $alert3 = FixMyStreet::App->model('DB::Alert')->find_or_create( +my $alert3 = FixMyStreet::DB->resultset('Alert')->find_or_create( { user => $user3, parameter => $report_id, @@ -129,7 +129,7 @@ for my $test ( subtest "correct summary for state of $test->{state}" => sub { $mech->clear_emails_ok; - my $sent = FixMyStreet::App->model('DB::AlertSent')->search( + my $sent = FixMyStreet::DB->resultset('AlertSent')->search( { alert_id => [ $alert->id, $alert3->id ], parameter => $comment->id, @@ -139,7 +139,7 @@ for my $test ( $report->state( $test->{state} ); $report->update; - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::DB->resultset('AlertType')->email_alerts(); $mech->email_count_is( 2 ); my @emails = $mech->get_email; @@ -167,7 +167,7 @@ my $now = DateTime->now(); $report->confirmed( $now->ymd . ' ' . $now->hms ); $report->update(); -my $council_alert = FixMyStreet::App->model('DB::Alert')->find_or_create( +my $council_alert = FixMyStreet::DB->resultset('Alert')->find_or_create( { user => $user2, parameter => 2504, @@ -181,7 +181,7 @@ my $council_alert = FixMyStreet::App->model('DB::Alert')->find_or_create( subtest "correct text for title after URL" => sub { $mech->clear_emails_ok; - my $sent = FixMyStreet::App->model('DB::AlertSent')->search( + my $sent = FixMyStreet::DB->resultset('AlertSent')->search( { alert_id => $council_alert->id, parameter => $report->id, @@ -190,7 +190,7 @@ subtest "correct text for title after URL" => sub { FixMyStreet::override_config { MAPIT_URL => 'http://mapit.mysociety.org/', }, sub { - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; my $email = $mech->get_email; @@ -304,7 +304,7 @@ foreach my $test ( subtest "correct Nearest Road text with $test->{desc}" => sub { $mech->clear_emails_ok; - my $sent = FixMyStreet::App->model('DB::AlertSent')->search( + my $sent = FixMyStreet::DB->resultset('AlertSent')->search( { alert_id => $council_alert->id, parameter => $report->id, @@ -327,7 +327,7 @@ foreach my $test ( FixMyStreet::override_config { MAPIT_URL => 'http://mapit.mysociety.org/', }, sub { - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; my $email = $mech->get_email; @@ -341,7 +341,7 @@ foreach my $test ( }; } -my $ward_alert = FixMyStreet::App->model('DB::Alert')->find_or_create( +my $ward_alert = FixMyStreet::DB->resultset('Alert')->find_or_create( { user => $user, parameter => 7117, @@ -352,7 +352,7 @@ my $ward_alert = FixMyStreet::App->model('DB::Alert')->find_or_create( } ); -my $report_to_council = FixMyStreet::App->model('DB::Problem')->find_or_create( +my $report_to_council = FixMyStreet::DB->resultset('Problem')->find_or_create( { postcode => 'WS13 6YY', bodies_str => '2434', @@ -376,7 +376,7 @@ my $report_to_council = FixMyStreet::App->model('DB::Problem')->find_or_create( } ); -my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_create( +my $report_to_county_council = FixMyStreet::DB->resultset('Problem')->find_or_create( { postcode => 'WS13 6YY', bodies_str => '2240', @@ -400,7 +400,7 @@ my $report_to_county_council = FixMyStreet::App->model('DB::Problem')->find_or_c } ); -my $report_outside_district = FixMyStreet::App->model('DB::Problem')->find_or_create( +my $report_outside_district = FixMyStreet::DB->resultset('Problem')->find_or_create( { postcode => 'WS13 6YY', bodies_str => '2221', @@ -427,7 +427,7 @@ my $report_outside_district = FixMyStreet::App->model('DB::Problem')->find_or_cr subtest "check alerts from cobrand send main site url for alerts for different council" => sub { $mech->clear_emails_ok; - my $sent = FixMyStreet::App->model('DB::AlertSent')->search( + my $sent = FixMyStreet::DB->resultset('AlertSent')->search( { alert_id => $ward_alert->id, } @@ -436,14 +436,14 @@ subtest "check alerts from cobrand send main site url for alerts for different c FixMyStreet::override_config { MAPIT_URL => 'http://mapit.mysociety.org/', }, sub { - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; my $email = $mech->get_email; my $body = $email->body; - my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id; - my $expected3 = mySociety::Config::get('BASE_URL') . '/report/' . $report_outside_district->id; + my $expected1 = FixMyStreet->config('BASE_URL') . '/report/' . $report_to_county_council->id; + my $expected3 = FixMyStreet->config('BASE_URL') . '/report/' . $report_outside_district->id; my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('hart')->new(); my $expected2 = $cobrand->base_url . '/report/' . $report_to_council->id; @@ -453,7 +453,7 @@ subtest "check alerts from cobrand send main site url for alerts for different c }; -my $local_alert = FixMyStreet::App->model('DB::Alert')->find_or_create( +my $local_alert = FixMyStreet::DB->resultset('Alert')->find_or_create( { user => $user, parameter => -1.731322, @@ -468,18 +468,18 @@ my $local_alert = FixMyStreet::App->model('DB::Alert')->find_or_create( subtest "check local alerts from cobrand send main site url for alerts for different council" => sub { $mech->clear_emails_ok; - my $sent = FixMyStreet::App->model('DB::AlertSent')->search( + my $sent = FixMyStreet::DB->resultset('AlertSent')->search( { alert_id => $local_alert->id, } )->delete; - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::DB->resultset('AlertType')->email_alerts(); my $email = $mech->get_email; my $body = $email->body; - my $expected1 = mySociety::Config::get('BASE_URL') . '/report/' . $report_to_county_council->id; + my $expected1 = FixMyStreet->config('BASE_URL') . '/report/' . $report_to_county_council->id; my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('hart')->new(); my $expected2 = $cobrand->base_url . '/report/' . $report_to_council->id; @@ -494,7 +494,7 @@ subtest "correct i18n-ed summary for state of closed" => sub { $report->update( { state => 'closed' } ); $alert->update( { lang => 'nb', cobrand => 'fiksgatami' } ); - FixMyStreet::App->model('DB::AlertSent')->search( { + FixMyStreet::DB->resultset('AlertSent')->search( { alert_id => $alert->id, parameter => $comment->id, } )->delete; @@ -502,7 +502,7 @@ subtest "correct i18n-ed summary for state of closed" => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fiksgatami' ], }, sub { - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; $mech->email_count_is( 1 ); diff --git a/t/app/model/comment.t b/t/app/model/comment.t index 3141af828..e83d795fc 100644 --- a/t/app/model/comment.t +++ b/t/app/model/comment.t @@ -1,14 +1,12 @@ -#!/usr/bin/perl - use strict; use warnings; use Test::More tests => 2; use FixMyStreet; -use FixMyStreet::App; +use FixMyStreet::DB; -my $comment_rs = FixMyStreet::App->model('DB::Comment'); +my $comment_rs = FixMyStreet::DB->resultset('Comment'); my $comment = $comment_rs->new( { diff --git a/t/app/model/extra.t b/t/app/model/extra.t index 21c37336e..52e2d839c 100644 --- a/t/app/model/extra.t +++ b/t/app/model/extra.t @@ -3,13 +3,11 @@ use warnings; use Test::More; use utf8; -use FixMyStreet::App; +use FixMyStreet::DB; use Data::Dumper; use DateTime; -my $c = FixMyStreet::App->new; - -my $db = FixMyStreet::App->model('DB')->schema; +my $db = FixMyStreet::DB->connect; $db->txn_begin; my $body = $db->resultset('Body')->create({ name => 'ExtraTestingBody' }); diff --git a/t/app/model/moderation.t b/t/app/model/moderation.t index cdc9a91b0..8fa333db4 100644 --- a/t/app/model/moderation.t +++ b/t/app/model/moderation.t @@ -4,17 +4,17 @@ use Test::More; use Test::Exception; use utf8; -use FixMyStreet::App; +use FixMyStreet::DB; use Data::Dumper; use DateTime; my $dt = DateTime->now; -my $user = FixMyStreet::App->model('DB::User')->find_or_create({ +my $user = FixMyStreet::DB->resultset('User')->find_or_create({ name => 'Bob', email => 'bob@example.com', }); sub get_report_and_original_data { - my $report = FixMyStreet::App->model('DB::Problem')->create( + my $report = FixMyStreet::DB->resultset('Problem')->create( { postcode => 'BR1 3SB', bodies_str => '', diff --git a/t/app/model/photoset.t b/t/app/model/photoset.t index 9e566f873..cfb5236a8 100644 --- a/t/app/model/photoset.t +++ b/t/app/model/photoset.t @@ -4,27 +4,29 @@ use Test::More; use Test::Exception; use utf8; -use FixMyStreet::App; -use Data::Dumper; +use FixMyStreet::DB; 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({ +my $db = FixMyStreet::DB->storage->schema; + +my $user = $db->resultset('User')->find_or_create({ name => 'Bob', email => 'bob@example.com', }); -my $image_path = path('t/app/controller/sample.jpg'); +FixMyStreet::override_config { + UPLOAD_DIR => $UPLOAD_DIR, +}, sub { -my $db = FixMyStreet::App->model('DB')->schema; $db->txn_begin; +my $image_path = path('t/app/controller/sample.jpg'); + sub make_report { my $photo_data = shift; return $db->resultset('Problem')->create({ @@ -54,23 +56,26 @@ sub make_report { subtest 'Photoset with photo inline in DB' => sub { my $report = make_report( $image_path->slurp ); - my $photoset = $report->get_photoset($c); + my $photoset = $report->get_photoset(); is $photoset->num_images, 1, 'Found just 1 image'; + is $photoset->data, '1cdd4329ceee2234bd4e89cb33b42061a0724687'; }; $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); + my $photoset = $report->get_photoset(); is $photoset->num_images, 1, 'Found just 1 image'; }; -subtest 'Photoset with 1 referenced photo' => sub { +subtest 'Photoset with 3 referenced photo' => sub { my $report = make_report( '0123456789012345678901234567890123456789,0123456789012345678901234567890123456789,0123456789012345678901234567890123456789' ); - my $photoset = $report->get_photoset($c); + my $photoset = $report->get_photoset(); is $photoset->num_images, 3, 'Found 3 images'; }; $db->txn_rollback; +}; + done_testing(); diff --git a/t/app/model/problem.t b/t/app/model/problem.t index 82569d72a..4e4a098d7 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -1,5 +1,3 @@ -#!/usr/bin/perl - use strict; use warnings; @@ -7,13 +5,13 @@ use Test::More; use FixMyStreet::TestMech; use FixMyStreet; -use FixMyStreet::App; +use FixMyStreet::DB; use mySociety::Locale; use Sub::Override; mySociety::Locale::gettext_domain('FixMyStreet'); -my $problem_rs = FixMyStreet::App->model('DB::Problem'); +my $problem_rs = FixMyStreet::DB->resultset('Problem'); my $problem = $problem_rs->new( { @@ -147,7 +145,7 @@ for my $test ( }; } -my $user = FixMyStreet::App->model('DB::User')->find_or_create( +my $user = FixMyStreet::DB->resultset('User')->find_or_create( { email => 'system_user@example.com' } @@ -161,7 +159,7 @@ $problem->insert; my $tz_local = DateTime::TimeZone->new( name => 'local' ); -my $body = FixMyStreet::App->model('DB::Body')->new({ +my $body = FixMyStreet::DB->resultset('Body')->new({ name => 'Edinburgh City Council' }); @@ -521,7 +519,7 @@ foreach my $test ( { $mech->clear_emails_ok; - FixMyStreet::App->model('DB::Problem')->search( + $problem_rs->search( { whensent => undef } @@ -541,7 +539,7 @@ foreach my $test ( { } ); FixMyStreet::override_config $override, sub { - FixMyStreet::App->model('DB::Problem')->send_reports(); + $problem_rs->send_reports(); }; $mech->email_count_is( $test->{ email_count } ); @@ -596,7 +594,7 @@ subtest 'check can set mutiple emails as a single contact' => sub { $mech->clear_emails_ok; - FixMyStreet::App->model('DB::Problem')->search( + $problem_rs->search( { whensent => undef } @@ -615,7 +613,7 @@ subtest 'check can set mutiple emails as a single contact' => sub { } ); FixMyStreet::override_config $override, sub { - FixMyStreet::App->model('DB::Problem')->send_reports(); + $problem_rs->send_reports(); }; $mech->email_count_is(1); @@ -630,7 +628,7 @@ subtest 'check can turn on report sent email alerts' => sub { ); $mech->clear_emails_ok; - FixMyStreet::App->model('DB::Problem')->search( + $problem_rs->search( { whensent => undef } @@ -648,7 +646,7 @@ subtest 'check can turn on report sent email alerts' => sub { send_fail_count => 0, } ); - FixMyStreet::App->model('DB::Problem')->send_reports(); + $problem_rs->send_reports(); $mech->email_count_is( 2 ); my @emails = $mech->get_email; @@ -675,7 +673,7 @@ subtest 'check can turn on report sent email alerts' => sub { subtest 'check iOS app store test reports not sent' => sub { $mech->clear_emails_ok; - FixMyStreet::App->model('DB::Problem')->search( + $problem_rs->search( { whensent => undef } @@ -692,7 +690,7 @@ subtest 'check iOS app store test reports not sent' => sub { send_fail_count => 0, } ); - FixMyStreet::App->model('DB::Problem')->send_reports(); + $problem_rs->send_reports(); $mech->email_count_is( 0 ); @@ -704,7 +702,7 @@ subtest 'check iOS app store test reports not sent' => sub { subtest 'check reports from abuser not sent' => sub { $mech->clear_emails_ok; - FixMyStreet::App->model('DB::Problem')->search( + $problem_rs->search( { whensent => undef } @@ -721,7 +719,7 @@ subtest 'check reports from abuser not sent' => sub { send_fail_count => 0, } ); - FixMyStreet::App->model('DB::Problem')->send_reports(); + $problem_rs->send_reports(); $mech->email_count_is( 1 ); @@ -734,10 +732,10 @@ subtest 'check reports from abuser not sent' => sub { whensent => undef, } ); - my $abuse = FixMyStreet::App->model('DB::Abuse')->create( { email => $problem->user->email } ); + my $abuse = FixMyStreet::DB->resultset('Abuse')->create( { email => $problem->user->email } ); $mech->clear_emails_ok; - FixMyStreet::App->model('DB::Problem')->send_reports(); + $problem_rs->send_reports(); $mech->email_count_is( 0 ); diff --git a/t/app/model/questionnaire.t b/t/app/model/questionnaire.t index 240d6d050..945a64633 100644 --- a/t/app/model/questionnaire.t +++ b/t/app/model/questionnaire.t @@ -1,5 +1,3 @@ -#!/usr/bin/perl - use strict; use warnings; @@ -8,9 +6,9 @@ use Test::More; use FixMyStreet; use FixMyStreet::TestMech; -my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => 'test@example.com' } ); +my $user = FixMyStreet::DB->resultset('User')->find_or_create( { email => 'test@example.com' } ); -my $problem = FixMyStreet::App->model('DB::Problem')->create( +my $problem = FixMyStreet::DB->resultset('Problem')->create( { postcode => 'EH99 1SP', latitude => 1, @@ -106,7 +104,7 @@ for my $test ( $mech->email_count_is(0); - FixMyStreet::App->model('DB::Questionnaire') + FixMyStreet::DB->resultset('Questionnaire') ->send_questionnaires( { site => 'fixmystreet' } ); $mech->email_count_is( $test->{send_email} ); diff --git a/t/app/model/token.t b/t/app/model/token.t index d72574bb1..e31901187 100644 --- a/t/app/model/token.t +++ b/t/app/model/token.t @@ -1,12 +1,10 @@ -#!/usr/bin/perl - use strict; use warnings; use Test::More; use FixMyStreet; -use FixMyStreet::App; +use FixMyStreet::DB; my %tests = ( nested_hash => { foo => 'bar', and => [ 'baz', 'bundy' ] }, @@ -14,7 +12,7 @@ my %tests = ( scalar => 123, ); -my $token_rs = FixMyStreet::App->model('DB::Token'); +my $token_rs = FixMyStreet::DB->resultset('Token'); foreach my $test_data_name ( sort keys %tests ) { my $test_data = $tests{$test_data_name}; diff --git a/t/app/model/user.t b/t/app/model/user.t new file mode 100644 index 000000000..24e5d2d98 --- /dev/null +++ b/t/app/model/user.t @@ -0,0 +1,61 @@ +use strict; +use warnings; + +use Test::More; + +use FixMyStreet::TestMech; +use FixMyStreet::DB; + +my $mech = FixMyStreet::TestMech->new(); +$mech->log_in_ok('test@example.com'); + +my ($problem) = $mech->create_problems_for_body(1, '2504', 'Title', { anonymous => 'f' }); +is $problem->user->latest_anonymity, 0, "User's last report was not anonymous"; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $mech->get_ok('/around?pc=sw1a1aa'); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + $mech->content_like(qr/may_show_name[^>]*checked/); +}; + +($problem) = $mech->create_problems_for_body(1, '2504', 'Title', { anonymous => 't' }); +is $problem->user->latest_anonymity, 1, "User's last report was anonymous"; + +create_update($problem, anonymous => 'f'); +is $problem->user->latest_anonymity, 0, "User's last update was not anonyous"; + +create_update($problem, anonymous => 't'); +is $problem->user->latest_anonymity, 1, "User's last update was anonymous"; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { fixmystreet => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $mech->get_ok('/around?pc=sw1a1aa'); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + $mech->content_like(qr/may_show_name[^>c]*>/); +}; + +END { + $mech->delete_user( $problem->user ) if $problem; + done_testing(); +} + +sub create_update { + my ($problem, %params) = @_; + my $dt = DateTime->now()->add(hours => 1); + return FixMyStreet::App->model('DB::Comment')->find_or_create({ + problem_id => $problem->id, + user_id => $problem->user_id, + name => 'Other User', + mark_fixed => 'false', + text => 'This is some update text', + state => 'confirmed', + anonymous => 'f', + created => $dt->ymd . ' ' . $dt->hms, + %params, + }); +} diff --git a/t/app/sendreport/email.t b/t/app/sendreport/email.t index 65cd7bfa8..471145dcb 100644 --- a/t/app/sendreport/email.t +++ b/t/app/sendreport/email.t @@ -1,12 +1,10 @@ -#!/usr/bin/perl - use strict; use warnings; use Test::More; use FixMyStreet; -use FixMyStreet::App; +use FixMyStreet::DB; use FixMyStreet::SendReport::Email; use FixMyStreet::TestMech; use mySociety::Locale; @@ -17,7 +15,7 @@ my $e = FixMyStreet::SendReport::Email->new(); # area id 1000 my $params = { id => 1000, name => 'Council of the Thousand' }; -my $body = FixMyStreet::App->model('DB::Body')->find_or_create($params); +my $body = FixMyStreet::DB->resultset('Body')->find_or_create($params); ok $body, "found/created body"; my $contact = $mech->create_contact_ok( @@ -27,7 +25,7 @@ my $contact = $mech->create_contact_ok( note => '', ); -my $row = FixMyStreet::App->model('DB::Problem')->new( { +my $row = FixMyStreet::DB->resultset('Problem')->new( { bodies_str => '1000', category => 'category', cobrand => '', diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t index fdded5606..1f61cd3de 100644 --- a/t/cobrand/bromley.t +++ b/t/cobrand/bromley.t @@ -21,7 +21,7 @@ my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', { my $report = $reports[0]; for my $update ('in progress', 'unable to fix') { - FixMyStreet::App->model('DB::Comment')->find_or_create( { + FixMyStreet::DB->resultset('Comment')->find_or_create( { problem_state => $update, problem_id => $report->id, user_id => $user->id, @@ -48,7 +48,7 @@ subtest 'testing special Open311 behaviour', sub { FixMyStreet::override_config { SEND_REPORTS_ON_STAGING => 1, }, sub { - FixMyStreet::App->model('DB::Problem')->send_reports(); + FixMyStreet::DB->resultset('Problem')->send_reports(); }; $report->discard_changes; ok $report->whensent, 'Report marked as sent'; @@ -58,5 +58,5 @@ subtest 'testing special Open311 behaviour', sub { # Clean up $mech->delete_user($user); -$mech->delete_problems_for_body( $body->id ); +$mech->delete_body($body); done_testing(); diff --git a/t/cobrand/closest.t b/t/cobrand/closest.t index d06f7e9a0..43b36f608 100644 --- a/t/cobrand/closest.t +++ b/t/cobrand/closest.t @@ -4,7 +4,7 @@ use warnings; use Test::More; use mySociety::Locale; -use FixMyStreet::App; +use FixMyStreet::DB; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -16,7 +16,7 @@ mySociety::Locale::gettext_domain( 'FixMyStreet' ); my $c = FixMyStreet::Cobrand::UK->new(); my $user = - FixMyStreet::App->model('DB::User') + FixMyStreet::DB->resultset('User') ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); ok $user, "created test user"; @@ -29,7 +29,7 @@ my $dt = DateTime->new( second => 23 ); -my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( +my $report = FixMyStreet::DB->resultset('Problem')->find_or_create( { postcode => 'SW1A 1AA', bodies_str => '2504', diff --git a/t/cobrand/fixamingata.t b/t/cobrand/fixamingata.t index d181d3890..50b7713d1 100644 --- a/t/cobrand/fixamingata.t +++ b/t/cobrand/fixamingata.t @@ -8,7 +8,7 @@ BEGIN { FixMyStreet->test_mode(1); } -use t::MapIt; +use t::Mock::MapIt; use mySociety::Locale; use FixMyStreet::TestMech; @@ -43,7 +43,7 @@ $mech->email_count_is(0); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixamingata' ], }, sub { - FixMyStreet::App->model('DB::Problem')->send_reports(); + FixMyStreet::DB->resultset('Problem')->send_reports(); }; my $email = $mech->get_email; like $email->header('Content-Type'), qr/iso-8859-1/, 'encoding looks okay'; @@ -53,16 +53,16 @@ like $email->body, qr/V=E4nligen,/, 'signature looks correct'; $mech->clear_emails_ok; my $user = - FixMyStreet::App->model('DB::User') + FixMyStreet::DB->resultset('User') ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); ok $user, "created test user"; my $user2 = - FixMyStreet::App->model('DB::User') + FixMyStreet::DB->resultset('User') ->find_or_create( { email => 'commenter@example.com', name => 'Commenter' } ); ok $user2, "created comment user"; -my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create({ +my $comment = FixMyStreet::DB->resultset('Comment')->find_or_create({ problem_id => $report->id, user_id => $user2->id, name => 'Other User', @@ -74,7 +74,7 @@ my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create({ $comment->confirmed( \"current_timestamp - '3 days'::interval" ); $comment->update; -my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create({ +my $alert = FixMyStreet::DB->resultset('Alert')->find_or_create({ user => $user, parameter => $report->id, alert_type => 'new_updates', @@ -86,7 +86,7 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create({ FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixamingata' ], }, sub { - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; $mech->email_count_is(1); @@ -102,7 +102,7 @@ subtest "Test ajax decimal points" => sub { # A note to the future - the run_if_script line must be within a subtest # otherwise it fails to work - LWP::Protocol::PSGI->register(t::MapIt->run_if_script, host => 'mapit.sweden'); + LWP::Protocol::PSGI->register(t::Mock::MapIt->run_if_script, host => 'mapit.sweden'); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixamingata' ], @@ -115,7 +115,7 @@ subtest "Test ajax decimal points" => sub { }; END { - $mech->delete_problems_for_body(1); + $mech->delete_body($body); ok $mech->host("www.fixmystreet.com"), "change host back"; done_testing(); } diff --git a/t/cobrand/fixmybarangay.t b/t/cobrand/fixmybarangay.t index 316739dfa..2f99b8c1e 100644 --- a/t/cobrand/fixmybarangay.t +++ b/t/cobrand/fixmybarangay.t @@ -30,8 +30,8 @@ $bsn->update( { send_method => 'Email' } ); my $dps = $mech->create_body_ok( 3, 'DPS', id => 3 ); $dps->update( { send_method => 'Open311', endpoint => 'http://dps.endpoint.example.com', jurisdiction => 'FMB', api_key => 'test' } ); -FixMyStreet::App->model('DB::BodyArea')->find_or_create({ area_id => 1, body_id => $dps->id }); -FixMyStreet::App->model('DB::BodyArea')->find_or_create({ area_id => 2, body_id => $dps->id }); +FixMyStreet::DB->resultset('BodyArea')->find_or_create({ area_id => 1, body_id => $dps->id }); +FixMyStreet::DB->resultset('BodyArea')->find_or_create({ area_id => 2, body_id => $dps->id }); # Create contacts for these bodies # TODO: log in as a Bgy user, and create a report using the front end, @@ -72,7 +72,7 @@ $mech->email_count_is(0); FixMyStreet::override_config { SEND_REPORTS_ON_STAGING => 1, }, sub { - FixMyStreet::App->model('DB::Problem')->send_reports('fixmybarangay'); + FixMyStreet::DB->resultset('Problem')->send_reports('fixmybarangay'); }; # Check BGY one sent by email @@ -89,10 +89,10 @@ is $dps_report->send_method_used, 'Open311', 'DPS report sent via Open311'; is $dps_report->external_id, 248, 'DPS report has right external ID'; my $fmb_test_email = 'luz_test_user@example.com'; -my $user = FixMyStreet::App->model('DB::User')->find_or_create( { email => $fmb_test_email, from_body => $luz->id, password => 'fmbsecret' } ); +my $user = FixMyStreet::DB->resultset('User')->find_or_create( { email => $fmb_test_email, from_body => $luz->id, password => 'fmbsecret' } ); ok $user, "test user does exist"; -my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create({ +my $alert = FixMyStreet::DB->resultset('Alert')->find_or_create({ user => $user, parameter => '-0.142497580865087', parameter2 => '51.5016605453401', @@ -105,7 +105,7 @@ my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create({ FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixmybarangay' ], }, sub { - FixMyStreet::App->model('DB::AlertType')->email_alerts(); + FixMyStreet::DB->resultset('AlertType')->email_alerts(); }; $mech->email_count_is(1); @@ -141,8 +141,9 @@ is $luz_report->state, 'hidden', 'should be hidden'; $mech->delete_user($fmb_test_email); -$mech->delete_problems_for_body( $luz->id ); -$mech->delete_problems_for_body( $dps->id ); +$mech->delete_body($luz); +$mech->delete_body($bsn); +$mech->delete_body($dps); ok $mech->host("www.fixmystreet.com"), "change host back"; diff --git a/t/cobrand/form_extras.t b/t/cobrand/form_extras.t new file mode 100644 index 000000000..9c20b7ad4 --- /dev/null +++ b/t/cobrand/form_extras.t @@ -0,0 +1,73 @@ +use strict; +use warnings; + +package FixMyStreet::Cobrand::Tester; +use parent 'FixMyStreet::Cobrand::FixMyStreet'; + +sub report_form_extras { + ( { name => 'address', required => 1 }, { name => 'passport', required => 0 } ) +} + +# To allow a testing template override +sub path_to_web_templates { + my $self = shift; + return [ + FixMyStreet->path_to( 't/cobrand/form_extras/templates' )->stringify, + FixMyStreet->path_to( 'templates/web/fixmystreet' )->stringify + ]; +} + +package main; + +use Test::More; +use FixMyStreet::TestMech; + +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + +my $mech = FixMyStreet::TestMech->new; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => [ { tester => '.' } ], + MAPIT_URL => 'http://mapit.mysociety.org/', +}, sub { + $mech->get_ok('/around'); + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB', } }, "submit location" ); + $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" ); + $mech->submit_form_ok( { + button => 'submit_register', + with_fields => { + title => 'Test Report', + detail => 'Test report details.', + name => 'Joe Bloggs', + may_show_name => '1', + email => 'test-1@example.com', + passport => '123456', + password_register => '', + } + }, + "submit details without address, with passport", + ); + $mech->content_like(qr{<label for="form_address">Address</label>\s*<p class='form-error'>This information is required</p>}, 'Address is required'); + $mech->content_contains('value="123456" name="passport"', 'Passport number reshown'); + + $mech->submit_form_ok( { + button => 'submit_register', + with_fields => { + address => 'My address', + } + }, + "submit details, now with address", + ); + $mech->content_contains('Now check your email'); + + my $problem = FixMyStreet::DB->resultset('Problem')->search({}, { order_by => '-id' })->first; + is $problem->get_extra_metadata('address'), 'My address', 'Address is stored'; + is $problem->get_extra_metadata('passport'), '123456', 'Passport number is stored'; +}; + +END { + $mech->delete_problems_for_body(undef); + done_testing(); +} diff --git a/t/cobrand/form_extras/templates/report/new/after_photo.html b/t/cobrand/form_extras/templates/report/new/after_photo.html new file mode 100644 index 000000000..b0c08ba20 --- /dev/null +++ b/t/cobrand/form_extras/templates/report/new/after_photo.html @@ -0,0 +1,12 @@ +<label for="form_address">Address</label> +[% IF field_errors.address %] +<p class='form-error'>[% field_errors.address %]</p> +[% END %] +<input type="text" value="[% report.get_extra_metadata('address') | html %]" name="address" id="form_address" required> + +<label for="form_passport">Passport number (optional)</label> +[% IF field_errors.passport %] +<p class='form-error'>[% field_errors.passport %]</p> +[% END %] +<input type="text" value="[% report.get_extra_metadata('passport') | html %]" name="passport" id="form_passport"> + diff --git a/t/cobrand/get_body_sender.t b/t/cobrand/get_body_sender.t index a9ba49479..66cfc02b7 100644 --- a/t/cobrand/get_body_sender.t +++ b/t/cobrand/get_body_sender.t @@ -4,7 +4,7 @@ use warnings; use Test::More; use mySociety::Locale; -use FixMyStreet::App; +use FixMyStreet::DB; use_ok 'FixMyStreet::Cobrand'; @@ -12,10 +12,10 @@ mySociety::Locale::gettext_domain( 'FixMyStreet' ); my $c = FixMyStreet::Cobrand::FixMyStreet->new(); -FixMyStreet::App->model('DB::BodyArea')->search( { body_id => 1000 } )->delete; -FixMyStreet::App->model('DB::Body')->search( { name => 'Body of a Thousand' } )->delete; +FixMyStreet::DB->resultset('BodyArea')->search( { body_id => 1000 } )->delete; +FixMyStreet::DB->resultset('Body')->search( { name => 'Body of a Thousand' } )->delete; -my $body = FixMyStreet::App->model('DB::Body')->find_or_create({ +my $body = FixMyStreet::DB->resultset('Body')->find_or_create({ id => 1000, name => 'Body of a Thousand', }); diff --git a/t/cobrand/restriction.t b/t/cobrand/restriction.t new file mode 100644 index 000000000..873a396b7 --- /dev/null +++ b/t/cobrand/restriction.t @@ -0,0 +1,55 @@ +use strict; +use warnings; + +package FixMyStreet::Cobrand::Tester; + +use parent 'FixMyStreet::Cobrand::Default'; + +sub problems_restriction { + my ($self, $rs) = @_; + return $rs->search({ cobrand => 'tester' }); +} + +sub updates_restriction { + my ($self, $rs) = @_; + return $rs->search({ 'problem.cobrand' => 'tester' }, { join => 'problem' }); +} + +package main; + +use Test::More; +use FixMyStreet::TestMech; + +my $c = FixMyStreet::App->new; +my $cobrand = FixMyStreet::Cobrand::Tester->new({c => $c}); +$c->stash->{cobrand} = $cobrand; + +my $mech = FixMyStreet::TestMech->new; + +my ($prob1) = $mech->create_problems_for_body(1, 1234, 'Title'); +my ($prob2) = $mech->create_problems_for_body(1, 1234, 'Title', { cobrand => 'tester' }); +$mech->create_problems_for_body(1, 1234, 'Title', { latitude => 0, longitude => 0 }); +$mech->create_problems_for_body(1, 1234, 'Title', { cobrand => 'tester', latitude => 0, longitude => 0 }); + +for (1..2) { + $c->model('DB::Comment')->create({ + problem_id => $_ == 1 ? $prob1->id : $prob2->id, + user_id => $prob2->user_id, + name => 'User', + mark_fixed => 'false', + text => 'This is some update text', + state => 'confirmed', + cobrand => 'tester', + anonymous => 'f', + }); +} + +is($c->model('DB::Problem')->count, 4, 'Four reports in database'); +is($cobrand->problems->count, 2, 'Two reports in the right cobrand'); +is($cobrand->updates->count, 1, 'One update in the right cobrand'); + +my $nearby = $c->model('DB::Nearby')->nearby($c, 5, [], 10, 0.003, 0.004); +is(@$nearby, 1, 'One report close to the origin point'); + +$mech->delete_problems_for_body(1234); +done_testing(); diff --git a/t/cobrand/seesomething.t b/t/cobrand/seesomething.t index 57a8a11ed..4da1c9c6e 100644 --- a/t/cobrand/seesomething.t +++ b/t/cobrand/seesomething.t @@ -2,7 +2,6 @@ use strict; use warnings; use DateTime; use Test::More; -use JSON; use FixMyStreet; use FixMyStreet::TestMech; @@ -10,7 +9,7 @@ use FixMyStreet::TestMech; my $EMAIL = 'seesomething@example.com'; my $mech = FixMyStreet::TestMech->new; -my $db = FixMyStreet::App->model('DB')->schema; +my $db = FixMyStreet::DB->storage->schema; my $dt_parser = $db->storage->datetime_parser; $db->txn_begin; @@ -32,7 +31,7 @@ $user->update({ from_body => $body }); my $date = $dt_parser->format_datetime(DateTime->now); -my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( { +my $report = FixMyStreet::DB->resultset('Problem')->find_or_create( { postcode => 'EH1 1BB', bodies_str => '2520', areas => ',2520,', diff --git a/t/cobrand/two_tier.t b/t/cobrand/two_tier.t index b3d6ca7db..f52e66abc 100644 --- a/t/cobrand/two_tier.t +++ b/t/cobrand/two_tier.t @@ -20,8 +20,8 @@ FixMyStreet::override_config { for my $c (@cobrands) { my ($m, $id) = @$c; my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($m); - my $body_restriction = $cobrand->body_restriction; - is $body_restriction, $id, "body_restriction for $m"; + my $council_id = $cobrand->council_id; + is $council_id, $id, "council_id for $m"; } }; diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 721ee547c..4734dc837 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -4,10 +4,12 @@ use strict; use warnings; use DateTime; +use Email::MIME; +use LWP::Protocol::PSGI; use Test::More; use Test::LongString; -use JSON; use Path::Tiny; +use t::Mock::MapItZurich; # Check that you have the required locale installed - the following # should return a line with de_CH.utf8 in. If not install that locale. @@ -19,9 +21,7 @@ use Path::Tiny; # commonlib/bin/gettext-makemo FixMyStreet use FixMyStreet; -my $c = FixMyStreet::App->new(); -my $cobrand = FixMyStreet::Cobrand::Zurich->new({ c => $c }); -$c->stash->{cobrand} = $cobrand; +my $cobrand = FixMyStreet::Cobrand::Zurich->new(); my $sample_file = path(__FILE__)->parent->parent->child("app/controller/sample.jpg"); ok $sample_file->exists, "sample file $sample_file exists"; @@ -37,7 +37,7 @@ sub send_reports_for_zurich { ALLOWED_COBRANDS => ['zurich'] }, sub { # Actually send the report - $c->model('DB::Problem')->send_reports('zurich'); + FixMyStreet::DB->resultset('Problem')->send_reports('zurich'); }; } sub reset_report_state { @@ -74,7 +74,7 @@ $division->parent( $zurich->id ); $division->send_method( 'Zurich' ); $division->endpoint( 'division@example.org' ); $division->update; -$division->body_areas->find_or_create({ area_id => 274456 }); +$division->body_areas->find_or_create({ area_id => 423017 }); my $subdivision = $mech->create_body_ok( 3, 'Subdivision A' ); $subdivision->parent( $division->id ); $subdivision->send_method( 'Zurich' ); @@ -195,7 +195,7 @@ subtest "changing of categories" => sub { sub get_moderated_count { # my %date_params = ( ); - # my $moderated = FixMyStreet::App->model('DB::Problem')->search({ + # my $moderated = FixMyStreet::DB->resultset('Problem')->search({ # extra => { like => '%moderated_overdue,I1:0%' }, %date_params } )->count; # return $moderated; @@ -703,10 +703,11 @@ subtest "only superuser can edit bodies" => sub { }; subtest "only superuser can see 'Add body' form" => sub { + LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich'); $user = $mech->log_in_ok( 'dm1@example.org' ); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'zurich' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', MAPIT_TYPES => [ 'O08' ], MAPIT_ID_WHITELIST => [ 423017 ], }, sub { @@ -717,12 +718,12 @@ subtest "only superuser can see 'Add body' form" => sub { }; subtest "phone number is mandatory" => sub { + LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich'); FixMyStreet::override_config { MAPIT_TYPES => [ 'O08' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', ALLOWED_COBRANDS => [ 'zurich' ], - MAPIT_ID_WHITELIST => [ 274456 ], - MAPIT_GENERATION => 2, + MAPIT_ID_WHITELIST => [ 423017 ], MAP_TYPE => 'Zurich,OSM', }, sub { $user = $mech->log_in_ok( 'dm1@example.org' ); @@ -734,12 +735,12 @@ subtest "phone number is mandatory" => sub { }; subtest "phone number is not mandatory for reports from mobile apps" => sub { + LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich'); FixMyStreet::override_config { MAPIT_TYPES => [ 'O08' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', ALLOWED_COBRANDS => [ 'zurich' ], MAPIT_ID_WHITELIST => [ 423017 ], - MAPIT_GENERATION => 4, MAP_TYPE => 'Zurich,OSM', }, sub { $mech->post_ok( '/report/new/mobile?lat=47.381817&lon=8.529156' , { @@ -761,6 +762,7 @@ subtest "phone number is not mandatory for reports from mobile apps" => sub { }; subtest "problems can't be assigned to deleted bodies" => sub { + LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich'); $user = $mech->log_in_ok( 'dm1@example.org' ); $user->from_body( $zurich->id ); $user->update; @@ -768,7 +770,7 @@ subtest "problems can't be assigned to deleted bodies" => sub { $report->update; FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'zurich' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', MAPIT_TYPES => [ 'O08' ], MAPIT_ID_WHITELIST => [ 423017 ], MAP_TYPE => 'Zurich,OSM', @@ -789,6 +791,7 @@ subtest "problems can't be assigned to deleted bodies" => sub { }; subtest "photo must be supplied for categories that require it" => sub { + LWP::Protocol::PSGI->register(t::Mock::MapItZurich->run_if_script, host => 'mapit.zurich'); FixMyStreet::App->model('DB::Contact')->find_or_create({ body => $division, category => "Graffiti - photo required", @@ -802,10 +805,9 @@ subtest "photo must be supplied for categories that require it" => sub { }); FixMyStreet::override_config { MAPIT_TYPES => [ 'O08' ], - MAPIT_URL => 'http://global.mapit.mysociety.org/', + MAPIT_URL => 'http://mapit.zurich/', ALLOWED_COBRANDS => [ 'zurich' ], - MAPIT_ID_WHITELIST => [ 274456 ], - MAPIT_GENERATION => 2, + MAPIT_ID_WHITELIST => [ 423017 ], MAP_TYPE => 'Zurich,OSM', }, sub { $mech->post_ok( '/report/new', { @@ -848,7 +850,7 @@ subtest "test stats" => sub { subtest "test admin_log" => sub { diag $report->id; - my @entries = FixMyStreet::App->model('DB::AdminLog')->search({ + my @entries = FixMyStreet::DB->resultset('AdminLog')->search({ object_type => 'problem', object_id => $report->id, }); @@ -868,7 +870,6 @@ subtest 'email images to external partners' => sub { my $photo = path(__FILE__)->parent->child('zurich-logo_portal.x.jpg')->slurp_raw; my $photoset = FixMyStreet::App::Model::PhotoSet->new({ - c => $c, data_items => [ $photo ], }); my $fileid = $photoset->data; @@ -888,15 +889,26 @@ subtest 'email images to external partners' => sub { my @emails = $mech->get_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, 4, '4 boundaries'; # header + 3 around the 2x parts (text + 1 image) + my $email = Email::MIME->new($email_as_string); my $expected_email_content = path(__FILE__)->parent->child('zurich_attachments.txt')->slurp; my $REPORT_ID = $report->id; $expected_email_content =~ s{REPORT_ID}{$REPORT_ID}g; + $expected_email_content =~ s{BOUNDARY}{$boundary}g; + my $expected_email = Email::MIME->new($expected_email_content); - is_string $email_as_string, $expected_email_content, 'MIME email text ok' + my @email_parts; + $email->walk_parts(sub { + my ($part) = @_; + push @email_parts, [ { $part->header_pairs }, $part->body ]; + }); + my @expected_email_parts; + $expected_email->walk_parts(sub { + my ($part) = @_; + push @expected_email_parts, [ { $part->header_pairs }, $part->body ]; + }); + is_deeply \@email_parts, \@expected_email_parts, 'MIME email text ok' or do { (my $test_name = $0) =~ s{/}{_}g; my $path = path("test-output-$test_name.tmp"); diff --git a/t/cobrand/zurich_attachments.txt b/t/cobrand/zurich_attachments.txt index 1c989c4d9..4ccc90205 100644 --- a/t/cobrand/zurich_attachments.txt +++ b/t/cobrand/zurich_attachments.txt @@ -1,12 +1,12 @@ MIME-Version: 1.0 Subject: =?iso-8859-1?Q?Z=FCri?= wie neu: Weitergeleitete Meldung #REPORT_ID -Content-Type: multipart/mixed; boundary="" +Content-Type: multipart/mixed; boundary="BOUNDARY" To: "External Body" <external_body@example.org> Content-Transfer-Encoding: 7bit From: FixMyStreet <division@example.org> --- +--BOUNDARY MIME-Version: 1.0 Subject: =?iso-8859-1?Q?Z=FCri?= wie neu: Weitergeleitete Meldung #REPORT_ID Content-Type: text/plain; charset="iso-8859-1" @@ -23,7 +23,7 @@ gis-zentrum@zuerich.ch.= --- +--BOUNDARY MIME-Version: 1.0 Content-Type: image/jpeg; name="REPORT_ID.0.jpeg" Content-Disposition: inline; filename="REPORT_ID.0.jpeg" @@ -37,4 +37,4 @@ BxcYVVaUpf/EABcBAQEBAQAAAAAAAAAAAAAAAAAFBgT/xAAgEQEAAAQHAQAAAAAAAAAAAAAAAwQV UgECFlNhodGx/9oADAMBAAIRAxEAPwCywAIozyxS5R58tbbujSW33j6zFRj3fGbKbjAGAgAACs9N FCbtUfYg2mO1BM25e/V+lQeW3ISo/9k= ----- +--BOUNDARY-- diff --git a/t/email.t b/t/email.t new file mode 100644 index 000000000..40a650da5 --- /dev/null +++ b/t/email.t @@ -0,0 +1,20 @@ +use strict; +use warnings; + +use Test::More; +use FixMyStreet::Email; + +my $secret = FixMyStreet::DB->resultset('Secret')->update({ + secret => 'abcdef123456' }); + +my $hash = FixMyStreet::Email::hash_from_id("report", 123); +is $hash, '8fb274c6', 'Hash generation okay'; + +my $token = FixMyStreet::Email::generate_verp_token("report", 123); +is $token, "report-123-8fb274c6", 'Token generation okay'; + +my ($type, $id) = FixMyStreet::Email::check_verp_token($token); +is $type, "report", 'Correct type from token'; +is $id, 123, 'Correct ID from token'; + +done_testing(); diff --git a/t/map/tilma/original.t b/t/map/tilma/original.t index 9e296686d..a1c6d83f4 100644 --- a/t/map/tilma/original.t +++ b/t/map/tilma/original.t @@ -1,9 +1,7 @@ -#!/usr/bin/perl - use strict; use warnings; use Test::More; -use FixMyStreet::App; +use FixMyStreet::DB; use FixMyStreet::Map; use FixMyStreet::TestMech; use DateTime; @@ -20,14 +18,14 @@ my $c = ctx_request('http://fixmystreet.com/test?bbox=-7.6,49.7,-7.5,49.8'); $mech->delete_user('test@example.com'); my $user = - FixMyStreet::App->model('DB::User') + FixMyStreet::DB->resultset('User') ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); ok $user, "created test user"; my $dt = DateTime->now(); -my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( +my $report = FixMyStreet::DB->resultset('Problem')->find_or_create( { postcode => 'SW1A 1AA', bodies_str => '2504', diff --git a/t/open311.t b/t/open311.t index 15bebe2fc..6333355e8 100644 --- a/t/open311.t +++ b/t/open311.t @@ -5,7 +5,7 @@ use strict; use warnings; use Test::More; use Test::Warn; -use FixMyStreet::App; +use FixMyStreet::DB; use CGI::Simple; use HTTP::Response; use DateTime; @@ -26,9 +26,9 @@ is $o->_process_error( '503 - service unavailable' ), 'unknown error', 'error te my $o2 = Open311->new( endpoint => 'http://192.168.50.1/open311/', jurisdiction => 'example.org' ); -my $u = FixMyStreet::App->model('DB::User')->new( { email => 'test@example.org', name => 'A User' } ); +my $u = FixMyStreet::DB->resultset('User')->new( { email => 'test@example.org', name => 'A User' } ); -my $p = FixMyStreet::App->model('DB::Problem')->new( { +my $p = FixMyStreet::DB->resultset('Problem')->new( { latitude => 1, longitude => 1, title => 'title', @@ -45,12 +45,12 @@ warning_like {$o2->send_service_request( $p, { url => 'http://example.com/' }, 1 my $dt = DateTime->now(); -my $user = FixMyStreet::App->model('DB::User')->new( { +my $user = FixMyStreet::DB->resultset('User')->new( { name => 'Test User', email => 'test@example.com', } ); -my $problem = FixMyStreet::App->model('DB::Problem')->new( { +my $problem = FixMyStreet::DB->resultset('Problem')->new( { id => 80, external_id => 81, state => 'confirmed', @@ -207,7 +207,7 @@ for my $test ( } -my $comment = FixMyStreet::App->model('DB::Comment')->new( { +my $comment = FixMyStreet::DB->resultset('Comment')->new( { id => 38362, user => $user, problem => $problem, @@ -394,7 +394,7 @@ for my $test ( my $dt2 = $dt->clone; $dt2->add( 'minutes' => 1 ); -my $comment2 = FixMyStreet::App->model('DB::Comment')->new( { +my $comment2 = FixMyStreet::DB->resultset('Comment')->new( { id => 38363, user => $user, problem => $problem, diff --git a/t/open311/endpoint.t b/t/open311/endpoint.t index 7e684c491..a2a4ea83e 100644 --- a/t/open311/endpoint.t +++ b/t/open311/endpoint.t @@ -6,12 +6,11 @@ use Test::MockTime ':all'; use Open311::Endpoint; use Data::Dumper; -use JSON; +use JSON::MaybeXS; use t::open311::endpoint::Endpoint1; my $endpoint = t::open311::endpoint::Endpoint1->new; -my $json = JSON->new; subtest "GET Service List" => sub { my $res = $endpoint->run_test_request( GET => '/services.xml' ); @@ -43,7 +42,7 @@ CONTENT $res = $endpoint->run_test_request( GET => '/services.json' ); ok $res->is_success, 'json success'; - is_deeply $json->decode($res->content), + is_deeply decode_json($res->content), [ { "keywords" => "deep,hole,wow", "group" => "highways", @@ -90,10 +89,6 @@ subtest "GET Service Definition" => sub { <required>false</required> <values> <value> - <name>Triangle</name> - <key>triangle</key> - </value> - <value> <name>Circle</name> <key>circle</key> </value> @@ -101,6 +96,10 @@ subtest "GET Service Definition" => sub { <name>Square</name> <key>square</key> </value> + <value> + <name>Triangle</name> + <key>triangle</key> + </value> </values> <variable>true</variable> </attribute> @@ -111,7 +110,7 @@ CONTENT $res = $endpoint->run_test_request( GET => '/services/POT.json' ); ok $res->is_success, 'json success'; - is_deeply $json->decode($res->content), + is_deeply decode_json($res->content), { "service_code" => "POT", "attributes" => [ @@ -134,17 +133,17 @@ CONTENT "datatype" => "singlevaluelist", "values" => [ { - "name" => "Triangle", - "key" => "triangle" - }, - { "name" => "Circle", "key" => "circle" }, { "name" => "Square", "key" => "square" - } + }, + { + "name" => "Triangle", + "key" => "triangle" + }, ], } ], @@ -209,7 +208,7 @@ subtest "POST Service Request valid test" => sub { ok $res->is_success, 'valid request' or diag $res->content; - is_deeply $json->decode($res->content), + is_deeply decode_json($res->content), [ { "service_notice" => "This is a test service", "service_request_id" => 0 diff --git a/t/open311/endpoint/Endpoint1.pm b/t/open311/endpoint/Endpoint1.pm index c4119075c..ae12172b8 100644 --- a/t/open311/endpoint/Endpoint1.pm +++ b/t/open311/endpoint/Endpoint1.pm @@ -103,8 +103,7 @@ sub get_service_requests { my ($self, $args) = @_; my $service_code = $args->{service_code} or return $self->get_requests; - # we use ~~ as the service_code arg will be an arrayref like ['POT'] - return $self->filter_requests( sub { shift->service->service_code ~~ $service_code }); + return $self->filter_requests( sub { my $c = shift->service->service_code; grep { $_ eq $c } @$service_code }); } sub get_service_request { diff --git a/t/open311/endpoint/mysociety.t b/t/open311/endpoint/mysociety.t index c63e03e43..d0ad60602 100644 --- a/t/open311/endpoint/mysociety.t +++ b/t/open311/endpoint/mysociety.t @@ -6,12 +6,11 @@ use Test::MockTime ':all'; use Open311::Endpoint; use Data::Dumper; -use JSON; +use JSON::MaybeXS; use t::open311::endpoint::Endpoint2; my $endpoint = t::open311::endpoint::Endpoint2->new; -my $json = JSON->new; subtest "POST OK" => sub { diag "Serves as sanity test of subclassing, as well as preparing our data"; @@ -31,7 +30,7 @@ subtest "POST OK" => sub { ok $res->is_success, 'valid request' or diag $res->content; - is_deeply $json->decode($res->content), + is_deeply decode_json($res->content), [ { "service_notice" => "This is a test service", "service_request_id" => 0 diff --git a/t/open311/endpoint/spark.t b/t/open311/endpoint/spark.t index 589f39baf..015876c94 100644 --- a/t/open311/endpoint/spark.t +++ b/t/open311/endpoint/spark.t @@ -4,10 +4,8 @@ use Test::More; use Open311::Endpoint; use Data::Dumper; -use JSON; my $endpoint = Open311::Endpoint->new; -my $json = JSON->new; subtest "Spark test" => sub { my $spark = $endpoint->spark; diff --git a/t/open311/endpoint/warwick.t b/t/open311/endpoint/warwick.t index b51c601f3..e5f124c8d 100644 --- a/t/open311/endpoint/warwick.t +++ b/t/open311/endpoint/warwick.t @@ -5,9 +5,9 @@ use Test::LongString; use Test::MockTime ':all'; use Data::Dumper; -use JSON; +use JSON::MaybeXS; -use FixMyStreet::App; +use FixMyStreet::DB; use Module::Loaded; BEGIN { mark_as_loaded('DBD::Oracle') } @@ -19,7 +19,6 @@ use Open311::PopulateServiceList; use Open311::GetServiceRequestUpdates; my $endpoint = t::open311::endpoint::Endpoint_Warwick->new; -my $json = JSON->new; subtest "GET Service List" => sub { my $res = $endpoint->run_test_request( GET => '/services.xml' ); @@ -59,7 +58,7 @@ subtest "POST OK" => sub { ok $res->is_success, 'valid request' or diag $res->content; - is_deeply $json->decode($res->content), + is_deeply decode_json($res->content), [ { "service_notice" => "Warwickshire Open311 Endpoint", "service_request_id" => 1001 @@ -141,16 +140,16 @@ subtest "End to end" => sub { my $WARWICKSHIRE_MAPIT_ID = 2243; - my $db = FixMyStreet::App->model('DB')->schema; + my $db = FixMyStreet::DB->connect; $db->txn_begin; - my $body = FixMyStreet::App->model('DB::Body')->find_or_create( { + my $body = FixMyStreet::DB->resultset('Body')->find_or_create( { id => $WARWICKSHIRE_MAPIT_ID, name => 'Warwickshire County Council', }); - my $user = FixMyStreet::App->model('DB::User') + my $user = FixMyStreet::DB->resultset('User') ->find_or_create( { email => 'test@example.com', name => 'Test User' } ); $body->update({ @@ -175,7 +174,7 @@ subtest "End to end" => sub { my $bodies = self_rs($body); - my $p = Open311::PopulateServiceList->new( bodies => $bodies, verbose => 0 ); + my $p = Open311::PopulateServiceList->new( bodies => $bodies, verbose => 0, schema => $db ); $p->process_bodies; is $body->contacts->count, 1, 'Categories imported from Open311'; @@ -183,7 +182,7 @@ subtest "End to end" => sub { set_fixed_time('2014-07-20T15:05:00Z'); - my $problem = FixMyStreet::App->model('DB::Problem')->create({ + my $problem = FixMyStreet::DB->resultset('Problem')->create({ postcode => 'WC1 1AA', bodies_str => $WARWICKSHIRE_MAPIT_ID, areas => ",$WARWICKSHIRE_MAPIT_ID,", @@ -219,7 +218,7 @@ subtest "End to end" => sub { # self_rs($problem)->send_reports; ## instead, as we are in a transaction, we'll just delete everything else. - my $rs = FixMyStreet::App->model('DB::Problem'); + my $rs = FixMyStreet::DB->resultset('Problem'); $rs->search({ id => { '!=', $problem->id } })->delete; $rs->send_reports; }; @@ -242,7 +241,7 @@ subtest "End to end" => sub { is $problem->state, 'confirmed', 'sanity check status'; - my $updates = Open311::GetServiceRequestUpdates->new( verbose => 1 ); + my $updates = Open311::GetServiceRequestUpdates->new( verbose => 1, schema => $db ); $updates->fetch; $problem->discard_changes; diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t index 0ab5b232d..18a5802bb 100644 --- a/t/open311/getservicerequestupdates.t +++ b/t/open311/getservicerequestupdates.t @@ -4,23 +4,25 @@ use strict; use warnings; use Test::More; use CGI::Simple; +use LWP::Protocol::PSGI; +use t::Mock::Static; use_ok( 'Open311' ); use_ok( 'Open311::GetServiceRequestUpdates' ); use DateTime; use DateTime::Format::W3CDTF; -use FixMyStreet::App; +use FixMyStreet::DB; -my $user = FixMyStreet::App->model('DB::User')->find_or_create( +my $user = FixMyStreet::DB->resultset('User')->find_or_create( { email => 'system_user@example.com' } ); my %bodies = ( - 2482 => FixMyStreet::App->model("DB::Body")->new({ id => 2482 }), - 2651 => FixMyStreet::App->model("DB::Body")->new({ id => 2651 }), + 2482 => FixMyStreet::DB->resultset("Body")->new({ id => 2482 }), + 2651 => FixMyStreet::DB->resultset("Body")->new({ id => 2651 }), ); my $requests_xml = qq{<?xml version="1.0" encoding="utf-8"?> @@ -104,7 +106,7 @@ subtest 'check extended request parsed correctly' => sub { }; -my $problem_rs = FixMyStreet::App->model('DB::Problem'); +my $problem_rs = FixMyStreet::DB->resultset('Problem'); my $problem = $problem_rs->new( { postcode => 'EH99 1SP', @@ -353,7 +355,7 @@ for my $test ( is $problem->comments->count, 1, 'comment count'; $problem->discard_changes; - my $c = FixMyStreet::App->model('DB::Comment')->search( { external_id => $test->{external_id} } )->first; + my $c = FixMyStreet::DB->resultset('Comment')->search( { external_id => $test->{external_id} } )->first; ok $c, 'comment exists'; is $c->text, $test->{description}, 'text correct'; is $c->mark_fixed, $test->{mark_fixed}, 'mark_closed correct'; @@ -363,6 +365,31 @@ for my $test ( }; } +subtest 'Update with media_url includes image in update' => sub { + my $guard = LWP::Protocol::PSGI->register(t::Mock::Static->to_psgi_app, host => 'example.com'); + + my $local_requests_xml = $requests_xml; + my $updated_datetime = sprintf( '<updated_datetime>%s</updated_datetime>', $dt ); + $local_requests_xml =~ s/UPDATED_DATETIME/$updated_datetime/; + $local_requests_xml =~ s#<service_request_id>\d+</service_request_id># + <service_request_id>@{[$problem->external_id]}</service_request_id> + <media_url>http://example.com/image.jpeg</media_url>#; + + my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } ); + + $problem->comments->delete; + $problem->lastupdate( DateTime->now()->subtract( days => 1 ) ); + $problem->state('confirmed'); + $problem->update; + + my $update = Open311::GetServiceRequestUpdates->new( system_user => $user ); + $update->update_comments( $o, $bodies{2482} ); + + is $problem->comments->count, 1, 'comment count'; + my $c = $problem->comments->first; + is $c->external_id, 638344; + is $c->photo, '1cdd4329ceee2234bd4e89cb33b42061a0724687', 'photo exists'; +}; foreach my $test ( { @@ -527,7 +554,7 @@ subtest 'check that existing comments are not duplicated' => sub { $problem->comments->delete; - my $comment = FixMyStreet::App->model('DB::Comment')->new( + my $comment = FixMyStreet::DB->resultset('Comment')->new( { problem => $problem, external_id => 638344, @@ -660,7 +687,7 @@ foreach my $test ( { $problem->update; my @alerts = map { - my $alert = FixMyStreet::App->model('DB::Alert')->create( { + my $alert = FixMyStreet::DB->resultset('Alert')->create( { alert_type => 'new_updates', parameter => $problem->id, confirmed => 1, @@ -680,7 +707,7 @@ foreach my $test ( { $update->update_comments( $o, $bodies{2482} ); $problem->discard_changes; - my $alerts_sent = FixMyStreet::App->model('DB::AlertSent')->search( + my $alerts_sent = FixMyStreet::DB->resultset('AlertSent')->search( { alert_id => [ map $_->id, @alerts ], parameter => $problem->comments->first->id, diff --git a/t/open311/getupdates.t b/t/open311/getupdates.t index 7dc7ff164..0e31db482 100644 --- a/t/open311/getupdates.t +++ b/t/open311/getupdates.t @@ -3,19 +3,21 @@ use strict; use warnings; use Test::More; +use URI::Split qw(uri_split); use FixMyStreet; +use FixMyStreet::DB; use_ok( 'Open311::GetUpdates' ); use_ok( 'Open311' ); -my $user = FixMyStreet::App->model('DB::User')->find_or_create( +my $user = FixMyStreet::DB->resultset('User')->find_or_create( { email => 'system_user@example.com' } ); -my $body = FixMyStreet::App->model('DB::Body')->new( { +my $body = FixMyStreet::DB->resultset('Body')->new( { name => 'Test Body', } ); @@ -42,7 +44,7 @@ UPDATED_DATETIME </service_requests> }; -my $problem_rs = FixMyStreet::App->model('DB::Problem'); +my $problem_rs = FixMyStreet::DB->resultset('Problem'); my $problem = $problem_rs->new( { postcode => 'EH99 1SP', @@ -102,8 +104,11 @@ for my $test ( my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $local_requests_xml } ); - ok $updates->update_reports( [ 638344 ], $o, $body ); - is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638344', 'get url'; + ok $updates->update_reports( [ 638344 ], $o, $body ), 'Updated reports'; + my @parts = uri_split($o->test_uri_used); + is $parts[2], '/requests.xml', 'path matches'; + my @qs = sort split '&', $parts[3]; + is_deeply(\@qs, [ 'jurisdiction_id=mysociety', 'service_request_id=638344' ], 'query string matches'); is $problem->comments->count, $test->{comment_count}, 'added a comment'; }; @@ -177,8 +182,11 @@ subtest 'update with two requests' => sub { my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'requests.xml' => $local_requests_xml } ); - ok $updates->update_reports( [ 638344,638345 ], $o, $body ); - is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638344%2C638345', 'get url'; + ok $updates->update_reports( [ 638344,638345 ], $o, $body ), 'Updated reports'; + my @parts = uri_split($o->test_uri_used); + is $parts[2], '/requests.xml', 'path matches'; + my @qs = sort split '&', $parts[3]; + is_deeply(\@qs, [ 'jurisdiction_id=mysociety', 'service_request_id=638344%2C638345' ], 'query string matches'); is $problem->comments->count, 1, 'added a comment to first problem'; is $problem2->comments->count, 1, 'added a comment to second problem'; @@ -231,9 +239,12 @@ subtest 'test translation of auto-added comment from old-style Open311 update' = FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'fixamingata' ], }, sub { - ok $updates->update_reports( [ 638346 ], $o, $body ); + ok $updates->update_reports( [ 638346 ], $o, $body ), 'Updated reports'; }; - is $o->test_uri_used, 'http://example.com/requests.xml?jurisdiction_id=mysociety&service_request_id=638346', 'get url'; + my @parts = uri_split($o->test_uri_used); + is $parts[2], '/requests.xml', 'path matches'; + my @qs = sort split '&', $parts[3]; + is_deeply(\@qs, [ 'jurisdiction_id=mysociety', 'service_request_id=638346' ], 'query string matches'); is $problem3->comments->count, 1, 'added a comment'; is $problem3->comments->first->text, "St\xe4ngd av kommunen", 'correct comment text'; diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t index 1574732fb..f001926d2 100644 --- a/t/open311/populate-service-list.t +++ b/t/open311/populate-service-list.t @@ -4,7 +4,7 @@ use strict; use warnings; use Test::More; -use FixMyStreet::App; +use FixMyStreet::DB; use_ok( 'Open311::PopulateServiceList' ); use_ok( 'Open311' ); @@ -13,7 +13,7 @@ use_ok( 'Open311' ); my $processor = Open311::PopulateServiceList->new(); ok $processor, 'created object'; -my $body = FixMyStreet::App->model('DB::Body')->find_or_create( { +my $body = FixMyStreet::DB->resultset('Body')->find_or_create( { id => 1, name => 'Body Numero Uno', } ); @@ -22,7 +22,7 @@ $body->body_areas->find_or_create({ } ); my $BROMLEY = 'Bromley Council'; -my $bromley = FixMyStreet::App->model('DB::Body')->find_or_create( { +my $bromley = FixMyStreet::DB->resultset('Body')->find_or_create( { id => 2482, name => $BROMLEY, } ); @@ -32,7 +32,7 @@ $bromley->body_areas->find_or_create({ } ); subtest 'check basic functionality' => sub { - FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete(); + FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete(); my $service_list = get_xml_simple_object( get_standard_xml() ); @@ -40,14 +40,14 @@ subtest 'check basic functionality' => sub { $processor->_current_body( $body ); $processor->process_services( $service_list ); - my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count(); + my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->count(); is $contact_count, 3, 'correct number of contacts'; }; subtest 'check non open311 contacts marked as deleted' => sub { - FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete(); + FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete(); - my $contact = FixMyStreet::App->model('DB::Contact')->create( + my $contact = FixMyStreet::DB->resultset('Contact')->create( { body_id => 1, email => 'contact@example.com', @@ -66,17 +66,17 @@ subtest 'check non open311 contacts marked as deleted' => sub { $processor->_current_body( $body ); $processor->process_services( $service_list ); - my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count(); + my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->count(); is $contact_count, 4, 'correct number of contacts'; - $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1, deleted => 1 } )->count(); + $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1, deleted => 1 } )->count(); is $contact_count, 1, 'correct number of deleted contacts'; }; subtest 'check email changed if matching category' => sub { - FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete(); + FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete(); - my $contact = FixMyStreet::App->model('DB::Contact')->create( + my $contact = FixMyStreet::DB->resultset('Contact')->create( { body_id => 1, email => '009', @@ -102,14 +102,14 @@ subtest 'check email changed if matching category' => sub { is $contact->confirmed, 1, 'contact still confirmed'; is $contact->deleted, 0, 'contact still not deleted'; - my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count(); + my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->count(); is $contact_count, 3, 'correct number of contacts'; }; subtest 'check category name changed if updated' => sub { - FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete(); + FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete(); - my $contact = FixMyStreet::App->model('DB::Contact')->create( + my $contact = FixMyStreet::DB->resultset('Contact')->create( { body_id => 1, email => '001', @@ -136,14 +136,14 @@ subtest 'check category name changed if updated' => sub { is $contact->confirmed, 1, 'contact still confirmed'; is $contact->deleted, 0, 'contact still not deleted'; - my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count(); + my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->count(); is $contact_count, 3, 'correct number of contacts'; }; subtest 'check conflicting contacts not changed' => sub { - FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->delete(); + FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete(); - my $contact = FixMyStreet::App->model('DB::Contact')->create( + my $contact = FixMyStreet::DB->resultset('Contact')->create( { body_id => 1, email => 'existing@example.com', @@ -158,7 +158,7 @@ subtest 'check conflicting contacts not changed' => sub { ok $contact, 'contact created'; - my $contact2 = FixMyStreet::App->model('DB::Contact')->create( + my $contact2 = FixMyStreet::DB->resultset('Contact')->create( { body_id => 1, email => '001', @@ -191,7 +191,7 @@ subtest 'check conflicting contacts not changed' => sub { is $contact2->confirmed, 1, 'second contact contact still confirmed'; is $contact2->deleted, 0, 'second contact contact still not deleted'; - my $contact_count = FixMyStreet::App->model('DB::Contact')->search( { body_id => 1 } )->count(); + my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->count(); is $contact_count, 4, 'correct number of contacts'; }; @@ -215,7 +215,7 @@ subtest 'check meta data population' => sub { </service_definition> '; - my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( + my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create( { body_id => 1, email => '001', @@ -395,7 +395,7 @@ for my $test ( $services_xml =~ s/metadata>false/metadata>true/ms; } - my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( + my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create( { body_id => 1, email => '100', @@ -470,7 +470,7 @@ subtest 'check attribute ordering' => sub { </service_definition> '; - my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( + my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create( { body_id => 1, email => '001', @@ -572,7 +572,7 @@ subtest 'check bromely skip code' => sub { </service_definition> '; - my $contact = FixMyStreet::App->model('DB::Contact')->find_or_create( + my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create( { body_id => 1, email => '001', |