aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2016-06-13 20:45:04 +0200
committerMarius Halden <marius.h@lden.org>2016-06-13 20:45:04 +0200
commit2cf7f0dcf146143613beb102d0dd227238776b69 (patch)
tree89d622eb300738f367800b9faa0f404d9ae0683f /t
parenta1ca7ffcddb7753c78db3f9965a7592f66f7e3b2 (diff)
parent2e7086d04d1ea729bf898acc0cae6835518bc106 (diff)
Merge branch 'fiksgatami-dev' into fiksgatami-prod
Diffstat (limited to 't')
-rw-r--r--t/00-check-we-are-staging.t17
-rw-r--r--t/Mock/Facebook.pm52
-rw-r--r--t/Mock/MapIt.pm (renamed from t/MapIt.pm)4
-rw-r--r--t/Mock/MapItZurich.pm43
-rw-r--r--t/Mock/Nominatim.pm (renamed from t/Nominatim.pm)4
-rw-r--r--t/Mock/Static.pm18
-rw-r--r--t/Mock/Twitter.pm43
-rw-r--r--t/app/01app.t23
-rw-r--r--t/app/controller/about.t31
-rw-r--r--t/app/controller/admin.t30
-rw-r--r--t/app/controller/alert.t4
-rw-r--r--t/app/controller/around.t13
-rw-r--r--t/app/controller/auth_social.t260
-rw-r--r--t/app/controller/my.t7
-rw-r--r--t/app/controller/page_not_found.t2
-rw-r--r--t/app/controller/photo.t5
-rw-r--r--t/app/controller/questionnaire.t37
-rw-r--r--t/app/controller/report_import.t19
-rw-r--r--t/app/controller/report_interest_count.t24
-rw-r--r--t/app/controller/report_new.t100
-rw-r--r--t/app/controller/report_new_mobile.t38
-rw-r--r--t/app/controller/report_new_open311.t5
-rw-r--r--t/app/controller/report_updates.t134
-rw-r--r--t/app/controller/reports.t16
-rw-r--r--t/app/controller/rss.t2
-rw-r--r--t/app/helpers/send_email.t31
-rw-r--r--t/app/helpers/send_email_sample.txt6
-rw-r--r--t/app/helpers/send_email_sample_mime.txt106
-rw-r--r--t/app/load_general_config.t7
-rw-r--r--t/app/model/alert_type.t62
-rw-r--r--t/app/model/comment.t6
-rw-r--r--t/app/model/extra.t6
-rw-r--r--t/app/model/moderation.t6
-rw-r--r--t/app/model/photoset.t27
-rw-r--r--t/app/model/problem.t34
-rw-r--r--t/app/model/questionnaire.t8
-rw-r--r--t/app/model/token.t6
-rw-r--r--t/app/model/user.t61
-rw-r--r--t/app/sendreport/angus.t61
-rw-r--r--t/app/sendreport/email.t8
-rw-r--r--t/app/uri_for.t26
-rw-r--r--t/cobrand/bromley.t6
-rw-r--r--t/cobrand/closest.t6
-rw-r--r--t/cobrand/fixamingata.t26
-rw-r--r--t/cobrand/fixmybarangay.t149
-rw-r--r--t/cobrand/form_extras.t72
-rw-r--r--t/cobrand/form_extras/templates/report/new/after_photo.html12
-rw-r--r--t/cobrand/get_body_sender.t8
-rw-r--r--t/cobrand/loading.t30
-rw-r--r--t/cobrand/restriction.t55
-rw-r--r--t/cobrand/seesomething.t5
-rw-r--r--t/cobrand/two_tier.t4
-rw-r--r--t/cobrand/zurich.t63
-rw-r--r--t/cobrand/zurich_attachments.txt73
-rw-r--r--t/email.t20
-rw-r--r--t/fixmystreet.t6
-rw-r--r--t/i18n.t37
-rw-r--r--t/map/tilma/original.t8
-rw-r--r--t/open311.t40
-rw-r--r--t/open311/endpoint.t27
-rw-r--r--t/open311/endpoint/Endpoint1.pm3
-rw-r--r--t/open311/endpoint/mysociety.t5
-rw-r--r--t/open311/endpoint/spark.t2
-rw-r--r--t/open311/endpoint/warwick.t21
-rw-r--r--t/open311/getservicerequestupdates.t58
-rw-r--r--t/open311/getupdates.t29
-rw-r--r--t/open311/populate-service-list.t46
67 files changed, 1465 insertions, 738 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/Mock/Twitter.pm b/t/Mock/Twitter.pm
new file mode 100644
index 000000000..930895e28
--- /dev/null
+++ b/t/Mock/Twitter.pm
@@ -0,0 +1,43 @@
+package t::Mock::Twitter;
+
+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;
+ },
+);
+
+sub dispatch_request {
+ my $self = shift;
+
+ sub (GET + /oauth/authenticate + ?*) {
+ my ($self) = @_;
+ return [ 200, [ 'Content-Type' => 'text/html' ], [ 'TwitteB login page' ] ];
+ },
+
+ sub (GET + /oauth/access_token + ?*) {
+ my ($self) = @_;
+ return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'oauth_token=access_token&oauth_token_secret=secret' ] ];
+ },
+
+ sub (GET + /oauth/request_token + ?*) {
+ my ($self) = @_;
+ return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'oauth_token=request-token&oauth_token_secret=secret&oauth_callback_confirmed=true' ] ];
+ },
+
+ sub (GET + /1.1/account/verify_credentials.json + ?*) {
+ my ($self) = @_;
+ my $data = {
+ id => '987654321',
+ name => 'Fiona Tester',
+ };
+ my $json = $self->json->encode($data);
+ return [ 200, [ 'Content-Type' => 'text/html' ], [ $json ] ];
+ },
+}
+
+__PACKAGE__->run_if_script;
diff --git a/t/app/01app.t b/t/app/01app.t
index 02ffcd217..df562b829 100644
--- a/t/app/01app.t
+++ b/t/app/01app.t
@@ -1,10 +1,31 @@
#!/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' );
+SKIP: {
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'tester' ],
+}, sub {
+ skip 'Test will not pass on Mac OS', 1 if $^O eq 'darwin';
+
+ 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..cec50abfa 100644
--- a/t/app/controller/about.t
+++ b/t/app/controller/about.t
@@ -1,3 +1,4 @@
+use utf8;
use strict;
use warnings;
@@ -7,24 +8,26 @@ 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' ],
+ ALLOWED_COBRANDS => [ 'fiksgatami' ],
}, sub {
- # check that geting the page as EHA produces a different page
- ok $mech->host("reportemptyhomes.co.uk"), 'change host to reportemptyhomes';
- $mech->get_ok('/about');
- $mech->content_like(qr{About us ::});
- $mech->content_contains('html lang="en-gb"');
-
- # check that geting the page as EHA in welsh produces a different page
- ok $mech->host("cy.reportemptyhomes.co.uk"), 'host to cy.reportemptyhomes';
- $mech->get_ok('/about');
- $mech->content_like(qr{Amdanom ni ::});
- $mech->content_contains('html lang="cy"');
+ ok $mech->host("www.fiksgatami.no"), 'host to fiksgatami';
+ $mech->get_ok('/faq');
+ $mech->content_like(qr{Ofte spurte spørsmål ::});
+ $mech->content_contains('html class="no-js" lang="nb"');
};
done_testing();
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index e2dd5df19..1dcb768dc 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,
},
@@ -111,9 +104,9 @@ subtest 'check summary counts' => sub {
$mech->content_contains( "$q_count questionnaires sent" );
FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'barnet' ],
+ ALLOWED_COBRANDS => [ 'oxfordshire' ],
}, sub {
- ok $mech->host('barnet.fixmystreet.com');
+ ok $mech->host('oxfordshire.fixmystreet.com');
$mech->get_ok('/admin');
$mech->title_like(qr/Summary/);
@@ -122,11 +115,11 @@ subtest 'check summary counts' => sub {
my ($num_alerts) = $mech->content =~ /(\d+) confirmed alerts/;
my ($num_qs) = $mech->content =~ /(\d+) questionnaires sent/;
- $report->bodies_str(2489);
- $report->cobrand('barnet');
+ $report->bodies_str(2237);
+ $report->cobrand('oxfordshire');
$report->update;
- $alert->cobrand('barnet');
+ $alert->cobrand('oxfordshire');
$alert->update;
$mech->get_ok('/admin');
@@ -178,6 +171,7 @@ subtest 'check contact creation' => sub {
email => 'test@example.com',
note => 'test note',
non_public => undef,
+ confirmed => 0,
} } );
$mech->content_contains( 'test category' );
@@ -1240,9 +1234,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..9e2e7c524 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 {
@@ -124,8 +124,13 @@ subtest 'check non public reports are not displayed on around page' => sub {
ok $private->update( { non_public => 1 } ), 'problem marked non public';
$mech->get_ok('/');
- $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } },
- "good location" );
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ }, sub {
+ $mech->submit_form_ok( { with_fields => { pc => 'EH99 1SP' } },
+ "good location" );
+ };
$mech->content_lacks( 'Around page Test 3 for 2651',
'problem marked non public is not visible' );
};
diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t
new file mode 100644
index 000000000..6929c0ddc
--- /dev/null
+++ b/t/app/controller/auth_social.t
@@ -0,0 +1,260 @@
+use strict;
+use warnings;
+use Test::More;
+use LWP::Protocol::PSGI;
+use LWP::Simple;
+use JSON::MaybeXS;
+
+use t::Mock::Facebook;
+use t::Mock::Twitter;
+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',
+ TWITTER_KEY => 'twitter-key',
+ 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 {
+ # Lots of user changes happening here, make sure we don't confuse
+ # Catalyst with a cookie session user that no longer exists
+ $mech->log_out_ok;
+ $mech->cookie_jar({});
+ 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';
+ }
+ }
+ }
+}
+
+my $tw_email = 'twitter@example.org';
+my $tw_uid = 987654321;
+
+# Twitter has no way of getting the email, so no "okay" state here
+for my $tw_state ( 'refused', 'existing UID', 'no email' ) {
+ for my $page ( 'my', 'report', 'update' ) {
+ subtest "test Twitter '$tw_state' login for page '$page'" => sub {
+ # Lots of user changes happening here, make sure we don't confuse
+ # Catalyst with a cookie session user that no longer exists
+ $mech->log_out_ok;
+ $mech->cookie_jar({});
+ if ($tw_state eq 'existing UID') {
+ my $user = $mech->create_user_ok($tw_email);
+ $user->update({ twitter_id => $tw_uid });
+ } else {
+ $mech->delete_user($tw_email);
+ }
+
+ # Set up a mock to catch (most, see below) requests to Twitter
+ my $tw = t::Mock::Twitter->new;
+ LWP::Protocol::PSGI->register($tw->to_psgi_app, host => 'api.twitter.com');
+
+ # Due to https://metacpan.org/pod/Test::WWW::Mechanize::Catalyst#External-Redirects-and-allow_external
+ # the redirect to Twitter's OAuth page can mess up the session
+ # cookie. So let's pretend we always on api.twitter.com, which
+ # sorts that out.
+ $mech->host('api.twitter.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 => 'twitter_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, 'Twitter button redirected';
+ like $mech->res->previous->header('Location'), qr{api\.twitter\.com/oauth/authenticate\?oauth_token=request-token}, 'Twitter redirect to oauth URL';
+
+ # Okay, now call the callback Facebook would send us to
+ if ($tw_state eq 'refused') {
+ $mech->get_ok('/auth/Twitter?denied=token');
+ } else {
+ $mech->get_ok('/auth/Twitter?oauth_token=request-token&oauth_verifier=verifier');
+ }
+
+ # 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 ($tw_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 ($tw_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} = $tw_email;
+ } else {
+ $fields->{email} = $tw_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 => $tw_email } );
+ if ($page eq 'my') {
+ is $user, undef, 'No user yet exists';
+ } else {
+ is $user->twitter_id, undef, 'User has no twitter ID';
+ }
+ $mech->get_ok( $url . $url_token );
+ $user = FixMyStreet::App->model( 'DB::User' )->find( { email => $tw_email } );
+ is $user->twitter_id, $tw_uid, 'User now has correct twitter 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..425e3c4df 100644
--- a/t/app/controller/photo.t
+++ b/t/app/controller/photo.t
@@ -64,8 +64,11 @@ 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/temp.1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg" alt="">\s*){3}],
+ 'Three uploaded pictures are all shown, safe');
$mech->content_contains(
- 'name="upload_fileid" value="1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687,1cdd4329ceee2234bd4e89cb33b42061a0724687"',
+ 'name="upload_fileid" value="1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg,1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg,1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg"',
'Returned upload_fileid contains expected hash, 3 times');
my $image_file = path($UPLOAD_DIR, '1cdd4329ceee2234bd4e89cb33b42061a0724687.jpeg');
ok $image_file->exists, 'File uploaded to temp';
diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t
index 2a89454d5..7bc6545db 100644
--- a/t/app/controller/questionnaire.t
+++ b/t/app/controller/questionnaire.t
@@ -63,8 +63,8 @@ my $email = $mech->get_email;
ok $email, "got an email";
like $email->body, qr/fill in our short questionnaire/i, "got questionnaire email";
-like $email->body, qr/Testing =96 Detail/, 'email contains encoded character';
-is $email->header('Content-Type'), 'text/plain; charset="windows-1252"', 'in the right character set';
+like $email->body_str, qr/Testing \x{2013} Detail/, 'email contains encoded character';
+is $email->header('Content-Type'), 'text/plain; charset="utf-8"', 'in the right character set';
my ($token) = $email->body =~ m{http://.*?/Q/(\S+)};
ok $token, "extracted questionnaire token '$token'";
@@ -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&rsquo;t a valid link",
},
{
desc => 'User goes to questionnaire URL for a now-hidden problem',
@@ -394,31 +394,23 @@ for my $test (
}
FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'emptyhomes', 'fixmystreet' ],
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
}, sub {
- # EHA extra checking
- ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes';
-
- # Reset, and all the questionaire sending function - FIXME should it detect site itself somehow?
+ $report->discard_changes;
$report->send_questionnaire( 1 );
$report->update;
$questionnaire->delete;
- FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( {
- site => 'emptyhomes'
- } );
+ FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires();
$email = $mech->get_email;
ok $email, "got an email";
$mech->clear_emails_ok;
(my $body = $email->body) =~ s/\s+/ /g;
- like $body, qr/fill in this short questionnaire/i, "got questionnaire email";
+ like $body, qr/fill in our short questionnaire/i, "got questionnaire email";
($token) = $email->body =~ m{http://.*?/Q/(\S+)};
ok $token, "extracted questionnaire token '$token'";
- $mech->get_ok("/Q/" . $token);
- $mech->content_lacks( 'Would you like to receive another questionnaire' );
-
# Test already answered the ever reported question, so not shown again
$dt = $dt->add( weeks => 4 );
my $questionnaire2 = FixMyStreet::App->model('DB::Questionnaire')->find_or_create(
@@ -429,17 +421,11 @@ FixMyStreet::override_config {
}
);
ok $questionnaire2, 'added another questionnaire';
- ok $mech->host("www.fixmystreet.com"), 'change host to fixmystreet';
$mech->get_ok("/Q/" . $token);
$mech->title_like( qr/Questionnaire/ );
$mech->content_contains( 'Has this problem been fixed?' );
$mech->content_lacks( 'ever reported' );
- # EHA extra checking
- ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes';
- $mech->get_ok("/Q/" . $token);
- $mech->content_lacks( 'Would you like to receive another questionnaire' );
-
$token = FixMyStreet::App->model("DB::Token")->find( { scope => 'questionnaire', token => $token } );
ok $token, 'found token for questionnaire';
$questionnaire = FixMyStreet::App->model('DB::Questionnaire')->find( { id => $token->data } );
@@ -452,18 +438,19 @@ FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'fiksgatami' ],
}, sub {
# I18N Unicode extra testing using FiksGataMi
+ $report->discard_changes;
$report->send_questionnaire( 1 );
$report->cobrand( 'fiksgatami' );
$report->update;
$questionnaire->delete;
- FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( { site => 'fixmystreet' } ); # It's either fixmystreet or emptyhomes
+ FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires();
$email = $mech->get_email;
ok $email, "got an email";
$mech->clear_emails_ok;
- like $email->body, qr/Testing =96 Detail/, 'email contains encoded character from user';
- like $email->body, qr/sak p=E5 FiksGataMi/, 'email contains encoded character from template';
- is $email->header('Content-Type'), 'text/plain; charset="windows-1252"', 'email is in right encoding';
+ like $email->body_str, qr/Testing \x{2013} Detail/, 'email contains encoded character from user';
+ like $email->body_str, qr/sak p\xe5 FiksGataMi/, 'email contains encoded character from template';
+ is $email->header('Content-Type'), 'text/plain; charset="utf-8"', 'email is in right encoding';
};
$mech->delete_user('test@example.com');
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_interest_count.t b/t/app/controller/report_interest_count.t
index 506b50edd..4e86789ba 100644
--- a/t/app/controller/report_interest_count.t
+++ b/t/app/controller/report_interest_count.t
@@ -1,5 +1,16 @@
use strict;
use warnings;
+
+package FixMyStreet::Cobrand::Tester;
+
+use parent 'FixMyStreet::Cobrand::Default';
+
+sub can_support_problems {
+ return 1;
+}
+
+package main;
+
use Test::More;
use FixMyStreet::TestMech;
@@ -52,7 +63,7 @@ my $report_id = $report->id;
ok $report, "created test report - $report_id";
FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'fixmybarangay' ],
+ ALLOWED_COBRANDS => [ 'tester' ],
}, sub {
my $body = $mech->create_body_ok(2504, 'Westminster City Council');
@@ -76,7 +87,6 @@ FixMyStreet::override_config {
},
) {
subtest $test->{desc} => sub {
- ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
$mech->log_in_ok( $user->email );
$user->from_body( $test->{from_body} );
$user->update;
@@ -92,7 +102,7 @@ FixMyStreet::override_config {
$mech->content_contains('Add support');
$mech->submit_form_ok( { form_number => 1 } );
- is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page';
+ is $mech->uri->path, "/report/$report_id", 'add support redirects to report page';
$mech->content_contains($test->{updated_support});
} else {
@@ -102,26 +112,22 @@ FixMyStreet::override_config {
}
subtest 'check non body user cannot increment support count' => sub {
- ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
-
ok $report->update({ interest_count => 1 }), 'updated interest count';
is $report->interest_count, 1, 'correct interest count';
$mech->get_ok("/report/$report_id");
$mech->content_contains( '1 supporter' );
- # This doesn't send cookie, so is logged out
+ $mech->log_out_ok( $user->email );
$mech->post_ok("/report/support", { id => $report_id } );
- is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page';
+ is $mech->uri->path, "/report/$report_id", 'add support redirects to report page';
$mech->content_contains( '1 supporter' );
};
};
subtest 'check support details not shown if not enabled in cobrand' => sub {
- ok $mech->host('www.fixmystreet.com'), 'changed to fixmystreet';
-
$report->interest_count(1);
ok $report->update, 'updated interest count';
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 3c05adfbd..eb29d37da 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,9 +418,9 @@ foreach my $test (
remember_me => undef,
},
changes => {
- photo => '',
+ photo1 => '',
},
- errors => [ "Please upload a JPEG image only" ],
+ errors => [ "Please upload an image only" ],
},
{
msg => 'bad photo upload gives error',
@@ -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,9 +441,9 @@ 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." ],
+ errors => [ "That image doesn't appear to have uploaded correctly (Please upload an image only ), please try again." ],
},
{
msg => 'photo with octet-stream gets through okay',
@@ -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..7b4bf7854 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',
},
@@ -722,7 +760,8 @@ subtest 'check meta correct for comments marked confirmed but not marked open' =
user => $user,
problem_id => $report->id,
text => 'update text',
- confirmed => DateTime->now( time_zone => 'local' ),
+ # Subtract a day to deal with any code/db timezone difference
+ confirmed => DateTime->now( time_zone => 'local' ) - DateTime::Duration->new( days => 1 ),
problem_state => 'confirmed',
anonymous => 0,
mark_open => 0,
@@ -783,7 +822,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 +854,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 +1092,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 +1102,9 @@ for my $test (
name => 'Test User',
may_show_name => 1,
add_alert => 1,
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
update => '',
fixed => undef,
},
@@ -1066,6 +1114,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 +1130,9 @@ for my $test (
name => 'Test User',
may_show_name => 1,
add_alert => 1,
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
update => '',
fixed => undef,
},
@@ -1107,7 +1158,9 @@ for my $test (
name => 'Test User',
may_show_name => 1,
add_alert => 1,
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
update => '',
fixed => undef,
},
@@ -1132,7 +1185,9 @@ for my $test (
name => 'Commenter',
may_show_name => 1,
add_alert => 1,
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
update => '',
fixed => undef,
},
@@ -1157,7 +1212,9 @@ for my $test (
name => 'Commenter',
may_show_name => 1,
add_alert => 1,
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
update => '',
},
email => 'commenter@example.com',
@@ -1210,6 +1267,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 +1285,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 +1305,9 @@ foreach my $test (
name => 'Test User',
may_show_name => 1,
add_alert => 1,
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
update => '',
fixed => undef,
},
@@ -1271,7 +1333,9 @@ foreach my $test (
name => 'Test User',
may_show_name => 1,
add_alert => 1,
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
update => '',
fixed => undef,
},
@@ -1298,7 +1362,9 @@ foreach my $test (
name => 'Test User',
may_show_name => 1,
add_alert => 1,
- photo => '',
+ photo1 => '',
+ photo2 => '',
+ photo3 => '',
update => '',
fixed => undef,
},
@@ -1771,7 +1837,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/reports.t b/t/app/controller/reports.t
index 02625fcc7..8869adaa7 100644
--- a/t/app/controller/reports.t
+++ b/t/app/controller/reports.t
@@ -12,6 +12,7 @@ $mech->create_body_ok(2514, 'Birmingham City Council');
my $body_edin_id = $mech->create_body_ok(2651, 'City of Edinburgh Council')->id;
my $body_west_id = $mech->create_body_ok(2504, 'Westminster City Council')->id;
my $body_fife_id = $mech->create_body_ok(2649, 'Fife Council')->id;
+my $body_slash_id = $mech->create_body_ok(10000, 'Electricity/Gas Council')->id;
$mech->delete_problems_for_body( $body_west_id );
$mech->delete_problems_for_body( $body_edin_id );
@@ -122,6 +123,10 @@ is scalar @$problems, 5, 'correct number of problems displayed';
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.mysociety.org/',
}, sub {
+ $mech->get_ok('/reports');
+ $mech->follow_link_ok({ url_regex => qr{/reports/Electricity_Gas\+Council} });
+ is $mech->uri->path, '/reports/Electricity_Gas+Council', 'Path is correct';
+
$mech->get_ok('/reports/City+of+Edinburgh?t=new');
};
$problems = $mech->extract_problem_list;
@@ -191,17 +196,6 @@ $mech->get_ok('/reports');
$stats = $mech->extract_report_stats;
is $stats->{'Westminster City Council'}->[1], 5, 'non public reports included in stats';
-subtest "test emptyhomes all reports page" => sub {
- FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'emptyhomes' ],
- }, sub {
- ok $mech->host("reportemptyhomes.com"), 'change host to reportemptyhomes';
- $mech->get_ok('/reports');
- # EHA lacks one column the others have
- $mech->content_lacks('state unknown');
- };
-};
-
subtest "test fiksgatami all reports page" => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'fiksgatami' ],
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..e2c8688a8 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,16 @@ 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') . '>';
+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 +83,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.txt b/t/app/helpers/send_email_sample.txt
index 1ccce6a23..87604008c 100644
--- a/t/app/helpers/send_email_sample.txt
+++ b/t/app/helpers/send_email_sample.txt
@@ -1,5 +1,5 @@
MIME-Version: 1.0
-Subject: test email =?utf-8?Q?=E2=98=BA?=
+Subject: =?UTF-8?B?dGVzdCBlbWFpbCDimLo=?=
Content-Type: text/plain; charset="utf-8"
To: test@recipient.com
Content-Transfer-Encoding: quoted-printable
@@ -23,6 +23,4 @@ pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
Yours,=20=20
-FixMyStreet.=20=
-
-
+FixMyStreet.=
diff --git a/t/app/helpers/send_email_sample_mime.txt b/t/app/helpers/send_email_sample_mime.txt
index 4ce0f9520..1747204f7 100644
--- a/t/app/helpers/send_email_sample_mime.txt
+++ b/t/app/helpers/send_email_sample_mime.txt
@@ -1,57 +1,49 @@
-MIME-Version: 1.0
-Subject: test email =?utf-8?Q?=E2=98=BA?=
-Content-Type: multipart/mixed; boundary=""
-To: test@recipient.com
-Content-Transfer-Encoding: 7bit
-From: CONTACT_EMAIL
-
-
---
-MIME-Version: 1.0
-Subject: test email =?utf-8?Q?=E2=98=BA?=
-Content-Type: text/plain; charset="utf-8"
-To: test@recipient.com
-Content-Transfer-Encoding: quoted-printable
-From: CONTACT_EMAIL
-
-Hello,
-
-This is a test email where foo: bar.
-
-utf8: =E6=88=91=E4=BB=AC=E5=BA=94=E8=AF=A5=E8=83=BD=E5=A4=9F=E6=97=A0=E7=BC=
-=9D=E5=A4=84=E7=90=86UTF8=E7=BC=96=E7=A0=81
-
- indented_text
-
-long line: Lorem ipsum dolor sit amet, consectetur adipisicing elit,
-sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
-Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
-nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
-reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
-pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
-culpa qui officia deserunt mollit anim id est laborum.
-
-Yours,=20=20
-FixMyStreet.=20=
-
-
-
---
-MIME-Version: 1.0
-Content-Type: image/gif; name="foo.gif"
-Content-Disposition: inline; filename="foo.gif"
-Content-Transfer-Encoding: quoted-printable
-
-GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00=
-=02=01L=00;=
-
---
-MIME-Version: 1.0
-Content-Type: image/gif; name="bar.gif"
-Content-Disposition: inline; filename="bar.gif"
-Content-Transfer-Encoding: quoted-printable
-
-GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00=
-=02=01L=00;=
-
-----
+MIME-Version: 1.0
+Subject: =?UTF-8?B?dGVzdCBlbWFpbCDimLo=?=
+Content-Type: multipart/mixed; boundary="BOUNDARY"
+To: test@recipient.com
+Content-Transfer-Encoding: 7bit
+From: CONTACT_EMAIL
+
+
+--BOUNDARY
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+Hello,
+
+This is a test email where foo: bar.
+
+utf8: =E6=88=91=E4=BB=AC=E5=BA=94=E8=AF=A5=E8=83=BD=E5=A4=9F=E6=97=A0=E7=BC=
+=9D=E5=A4=84=E7=90=86UTF8=E7=BC=96=E7=A0=81
+
+ indented_text
+
+long line: Lorem ipsum dolor sit amet, consectetur adipisicing elit,
+sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
+Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
+nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
+reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
+pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
+culpa qui officia deserunt mollit anim id est laborum.
+
+Yours,=20=20
+FixMyStreet.=
+
+--BOUNDARY
+Content-Type: image/gif; name="foo.gif"
+Content-Disposition: inline; filename="foo.gif"
+Content-Transfer-Encoding: quoted-printable
+
+GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00=
+=02=01L=00;=
+
+--BOUNDARY
+Content-Type: image/gif; name="bar.gif"
+Content-Disposition: inline; filename="bar.gif"
+Content-Transfer-Encoding: quoted-printable
+
+GIF89a=01=00=01=00=80=00=00=00=00=00=CC=CC=CC,=00=00=00=00=01=00=01=00=00=
+=02=01L=00;=
+
+--BOUNDARY--
diff --git a/t/app/load_general_config.t b/t/app/load_general_config.t
index 3855c2565..16ca2fc54 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;
@@ -7,7 +5,6 @@ use Test::More tests => 2;
use_ok 'FixMyStreet::App';
-# GAZE_URL chosen as it is unlikely to change
-is FixMyStreet::App->config->{GAZE_URL}, #
- 'http://gaze.mysociety.org/gaze', #
+is FixMyStreet::App->config->{GAZE_URL},
+ 'https://gaze.mysociety.org/gaze',
"check that known config param is loaded";
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index 2620dd68c..e94ee8ce1 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;
@@ -287,7 +287,7 @@ foreach my $test (
desc => 'address only',
addressLine => '18 North Bridge',
locality => undef,
- nearest => qr/: 18 North Bridge\n/,
+ nearest => qr/: 18 North Bridge\r?\n/,
},
{
desc => 'no fields',
@@ -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..577e39eb1 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.jpeg';
};
$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..bf73a9d09
--- /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(days => 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/angus.t b/t/app/sendreport/angus.t
new file mode 100644
index 000000000..a19ee483a
--- /dev/null
+++ b/t/app/sendreport/angus.t
@@ -0,0 +1,61 @@
+use strict;
+use warnings;
+
+use FixMyStreet::DB;
+
+use Test::More;
+
+use_ok("FixMyStreet::SendReport::Angus");
+
+my $u = FixMyStreet::DB->resultset('User')->new( { email => 'test@example.org', name => 'A User' } );
+
+my $p = FixMyStreet::DB->resultset('Problem')->new( {
+ latitude => 1,
+ longitude => 1,
+ title => 'title',
+ detail => 'detail',
+ user => $u,
+ id => 1,
+ name => 'A User',
+ cobrand => 'fixmystreet',
+} );
+
+my $angus = FixMyStreet::SendReport::Angus->new();
+
+subtest 'parses authentication token correctly' => sub {
+ my $authxml = <<EOT;
+ <AuthenticateResponse>
+
+ <AuthenticateResult>
+ TVRreUxqRTJPQzR5TlRVdU1qSjhNakF4Tmpvd01Ub3lNam94TlRvME16b3pPUT09VGhvdVNoYWx0Tm90UGFzcw==
+ </AuthenticateResult>
+ <success>
+ True
+ </success>
+ <message></message>
+
+ </AuthenticateResponse>
+EOT
+;
+ is $angus->get_auth_token($authxml), 'TVRreUxqRTJPQzR5TlRVdU1qSjhNakF4Tmpvd01Ub3lNam94TlRvME16b3pPUT09VGhvdVNoYWx0Tm90UGFzcw==', 'token correct';
+};
+
+subtest 'parses report external id correctly' => sub {
+ my $respxml = <<EOT;
+<CreateRequestResponse>
+
+ <CreateRequestResult>
+ <RequestId>7245</RequestId>
+ </CreateRequestResult>
+
+ <success>True</success>
+ <message></message>
+
+</CreateRequestResponse>
+EOT
+;
+ is $angus->get_external_id($respxml), '7245', 'external id correct';
+};
+
+
+done_testing();
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/app/uri_for.t b/t/app/uri_for.t
index 810aade62..9cbcd3767 100644
--- a/t/app/uri_for.t
+++ b/t/app/uri_for.t
@@ -17,7 +17,6 @@ use_ok('FixMyStreet::App');
my $fms_c = ctx_request('http://www.fixmystreet.com/');
my $fgm_c = ctx_request('http://www.fiksgatami.no/');
-my $reh_en_c = ctx_request('http://reportemptyhomes.com/');
is(
$fms_c->uri_for('/bar/baz') . "",
@@ -44,29 +43,4 @@ is(
'FiksGataMi url with lat not zoom'
);
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'emptyhomes' ],
-}, sub {
- like(
- $reh_en_c->uri_for_email( '/foo' ),
- qr{^http://en.},
- 'adds en to retain language'
- );
-};
-
-# instantiate this here otherwise sets locale to cy and breaks test
-# above
-my $reh_cy_c;
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'emptyhomes' ],
-}, sub {
- $reh_cy_c = ctx_request('http://cy.reportemptyhomes.com/');
-
- like(
- $reh_cy_c->uri_for_email( '/foo' ),
- qr{^http://cy.},
- 'retains language'
- );
-};
-
done_testing();
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..0cf7a31fe 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,26 +43,26 @@ $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';
+like $email->header('Content-Type'), qr/utf-8/, 'encoding looks okay';
like $email->header('Subject'), qr/Ny rapport: Test Test/, 'subject looks okay';
like $email->header('To'), qr/other\@example.org/, 'to line looks correct';
-like $email->body, qr/V=E4nligen,/, 'signature looks correct';
+like $email->body_str, qr/V\xe4nligen,/, '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,13 +86,13 @@ 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);
$email = $mech->get_email;
-like $email->header('Content-Type'), qr/iso-8859-1/, 'encoding looks okay';
-like $email->body, qr/V=E4nligen,/, 'signature looks correct';
+like $email->header('Content-Type'), qr/utf-8/, 'encoding looks okay';
+like $email->body_str, qr/V\xe4nligen,/, 'signature looks correct';
$mech->clear_emails_ok;
subtest "Test ajax decimal points" => sub {
@@ -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
deleted file mode 100644
index 316739dfa..000000000
--- a/t/cobrand/fixmybarangay.t
+++ /dev/null
@@ -1,149 +0,0 @@
-use strict;
-use warnings;
-use Test::More;
-
-BEGIN {
- use FixMyStreet;
- FixMyStreet->test_mode(1);
-}
-
-use FixMyStreet::TestMech;
-my $mech = FixMyStreet::TestMech->new;
-
-# Front page test
-
-ok $mech->host("www.fixmybarangay.com"), "change host to FixMyBarangay";
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'fixmybarangay' ],
-}, sub {
- $mech->get_ok('/');
-};
-$mech->content_like( qr/FixMyBarangay/ );
-
-# Set up bodies
-
-my $luz = $mech->create_body_ok( 1, 'Bgy Luz', id => 1 );
-$luz->update( { send_method => 'Email' } );
-
-my $bsn = $mech->create_body_ok( 2, 'Bgy BSN', id => 2 );
-$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 });
-
-# Create contacts for these bodies
-# TODO: log in as a Bgy user, and create a report using the front end,
-# testing that the drop-down has the right things in it, and so on.
-
-$mech->create_contact_ok(
- body_id => $luz->id,
- category => 'Streetlight (BGY)',
- email => 'bgy@example.com',
-);
-$mech->create_contact_ok(
- body_id => $dps->id,
- category => 'Streetlight (DPS)',
- email => 'LIGHT',
-);
-
-# Create a couple of reports
-
-my @reports = $mech->create_problems_for_body( 1, $luz->id, 'Test', {
- cobrand => 'fixmybarangay',
- category => 'Streetlight (BGY)',
-});
-my $luz_report = $reports[0];
-
-@reports = $mech->create_problems_for_body( 1, $dps->id, 'Test', {
- cobrand => 'fixmybarangay',
- category => 'Streetlight (DPS)',
-});
-my $dps_report = $reports[0];
-
-$mech->get_ok( '/report/' . $luz_report->id );
-$mech->get_ok( '/report/' . $dps_report->id );
-
-# Send the reports
-
-$mech->email_count_is(0);
-
-FixMyStreet::override_config {
- SEND_REPORTS_ON_STAGING => 1,
-}, sub {
- FixMyStreet::App->model('DB::Problem')->send_reports('fixmybarangay');
-};
-
-# Check BGY one sent by email
-my $email = $mech->get_email;
-like $email->header('Subject'), qr/Problem Report: Test Test/, 'subject looks okay';
-like $email->header('To'), qr/bgy\@example.com/, 'to line looks correct';
-$mech->clear_emails_ok;
-
-$luz_report->discard_changes;
-$dps_report->discard_changes;
-ok $luz_report->whensent, 'Luz report marked as sent';
-ok $dps_report->whensent, 'DPS report marked as sent';
-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' } );
-ok $user, "test user does exist";
-
-my $alert = FixMyStreet::App->model('DB::Alert')->find_or_create({
- user => $user,
- parameter => '-0.142497580865087',
- parameter2 => '51.5016605453401',
- alert_type => 'local_problems',
- whensubscribed => '2014-01-01 10:00:00',
- confirmed => 1,
- cobrand => 'fixmybarangay',
-});
-
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'fixmybarangay' ],
-}, sub {
- FixMyStreet::App->model('DB::AlertType')->email_alerts();
-};
-
-$mech->email_count_is(1);
-$email = $mech->get_email;
-like $email->body, qr/The following FixMyBarangay reports/, 'Start of email looks correct';
-$mech->clear_emails_ok;
-
-$mech->log_out_ok;
-$mech->get_ok( '/report/' . $luz_report->id );
-$mech->content_lacks( "Remove from site" );
-$mech->content_contains( "Report abuse" );
-
-$mech->post_ok('/report/delete/' . $luz_report->id);
-is $mech->uri->path, '/report/' . $luz_report->id, "should redirect to report page, deletion ignored";
-$luz_report->discard_changes;
-is $luz_report->state, 'confirmed', 'should be confirmed';
-
-$user = $mech->log_in_ok($fmb_test_email);
-
-FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'fixmybarangay' ],
-}, sub {
- $mech->get_ok( '/report/' . $luz_report->id );
-};
-$mech->content_contains( "Remove from site" );
-$mech->content_lacks( "Report abuse" );
-
-$mech->form_id('remove-from-site-form');
-$mech->submit_form();
-is $mech->uri->path, '/report/' . $luz_report->id, "should redirect to report page, deletion successful";
-$luz_report->discard_changes;
-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 );
-
-ok $mech->host("www.fixmystreet.com"), "change host back";
-
-done_testing();
diff --git a/t/cobrand/form_extras.t b/t/cobrand/form_extras.t
new file mode 100644
index 000000000..c6f6976d5
--- /dev/null
+++ b/t/cobrand/form_extras.t
@@ -0,0 +1,72 @@
+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,
+ ];
+}
+
+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/loading.t b/t/cobrand/loading.t
index 48a10293e..b4738fb63 100644
--- a/t/cobrand/loading.t
+++ b/t/cobrand/loading.t
@@ -44,8 +44,8 @@ FixMyStreet::override_config {
}, sub {
run_host_tests(
'www.fixmystreet.com' => 'FixMyStreet',
- 'reportemptyhomes.com' => 'FixMyStreet',
- 'barnet.fixmystreet.com' => 'FixMyStreet',
+ 'fiksgatami.example.org' => 'FixMyStreet',
+ 'oxfordshire.fixmystreet.com' => 'FixMyStreet',
'some.odd.site.com' => 'FixMyStreet',
);
};
@@ -62,49 +62,49 @@ FixMyStreet::override_config {
# Couple of cobrands, hostname checking and default fallback
FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'emptyhomes', 'fixmystreet' ],
+ ALLOWED_COBRANDS => [ 'fiksgatami', 'fixmystreet' ],
}, sub {
run_host_tests(
'www.fixmystreet.com' => 'FixMyStreet',
- 'reportemptyhomes.com' => 'EmptyHomes',
- 'barnet.fixmystreet.com' => 'FixMyStreet', # not in the allowed_cobrands list
+ 'fiksgatami.example.org' => 'FiksGataMi',
+ 'oxfordshire.fixmystreet.com' => 'FixMyStreet', # not in the allowed_cobrands list
'some.odd.site.com' => 'Default',
);
};
-# now enable barnet too and check that it works
+# now enable oxfordshire too and check that it works
FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ 'emptyhomes', 'barnet', 'fixmystreet' ],
+ ALLOWED_COBRANDS => [ 'fiksgatami', 'oxfordshire', 'fixmystreet' ],
}, sub {
run_host_tests(
'www.fixmystreet.com' => 'FixMyStreet',
- 'reportemptyhomes.com' => 'EmptyHomes',
- 'barnet.fixmystreet.com' => 'Barnet', # found now it is in allowed_cobrands
+ 'fiksgatami.example.org' => 'FiksGataMi',
+ 'oxfordshire.fixmystreet.com' => 'Oxfordshire', # found now it is in allowed_cobrands
'some.odd.site.com' => 'Default',
);
};
# And a check with some regex matching
FixMyStreet::override_config {
- ALLOWED_COBRANDS => [ { 'fixmystreet' => 'empty' }, 'barnet', { 'testing' => 'fixmystreet' } ],
+ ALLOWED_COBRANDS => [ { 'fixmystreet' => 'example' }, 'oxfordshire', { 'testing' => 'fixmystreet' } ],
}, sub {
run_host_tests(
'www.fixmystreet.com' => 'testing',
- 'reportemptyhomes.com' => 'FixMyStreet',
- 'barnet.fixmystreet.com' => 'Barnet',
+ 'fiksgatami.example.org' => 'FixMyStreet',
+ 'oxfordshire.fixmystreet.com' => 'Oxfordshire',
'some.odd.site.com' => 'Default',
);
};
# check that the moniker works as expected both on class and object.
-is FixMyStreet::Cobrand::EmptyHomes->moniker, 'emptyhomes',
+is FixMyStreet::Cobrand::FiksGataMi->moniker, 'fiksgatami',
'class->moniker works';
-is FixMyStreet::Cobrand::EmptyHomes->new->moniker, 'emptyhomes',
+is FixMyStreet::Cobrand::FiksGataMi->new->moniker, 'fiksgatami',
'object->moniker works';
# check is_default works
ok FixMyStreet::Cobrand::Default->is_default, '::Default is default';
-ok !FixMyStreet::Cobrand::EmptyHomes->is_default, '::Emptyhomes is not default';
+ok !FixMyStreet::Cobrand::FiksGataMi->is_default, '::FiksGataMi is not default';
# all done
done_testing();
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..cf66136e5 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;
@@ -661,7 +661,7 @@ subtest "external report triggers email" => sub {
};
$email = $mech->get_email;
my $report_id = $report->id;
- like $email->header('Subject'), qr/Meldung #$report_id/, 'subject looks okay';
+ like Encode::decode('MIME-Header', $email->header('Subject')), qr/Meldung #$report_id/, 'subject looks okay';
like $email->header('To'), qr/test\@example.com/, 'to line looks correct';
like $email->body, qr/$PUBLIC_RESPONSE/, 'public_response was passed on' or die $email->body;
$mech->clear_emails_ok;
@@ -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,31 @@ 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{Subject: (.*?)\r?\n}{
+ my $subj = Encode::decode('MIME-Header', $1);
+ $subj =~ s{REPORT_ID}{$REPORT_ID}g;
+ 'Subject: ' . Email::MIME::Encode::mime_encode($subj, "utf-8") . "\n";
+ }eg;
$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..bdc4333bf 100644
--- a/t/cobrand/zurich_attachments.txt
+++ b/t/cobrand/zurich_attachments.txt
@@ -1,40 +1,33 @@
-MIME-Version: 1.0
-Subject: =?iso-8859-1?Q?Z=FCri?= wie neu: Weitergeleitete Meldung #REPORT_ID
-Content-Type: multipart/mixed; boundary=""
-To: "External Body" <external_body@example.org>
-Content-Transfer-Encoding: 7bit
-From: FixMyStreet <division@example.org>
-
-
---
-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"
-To: "External Body" <external_body@example.org>
-Content-Transfer-Encoding: quoted-printable
-From: FixMyStreet <division@example.org>
-
-Gr=FCezi External Body,
-
-=D6ffentliche URL: http://www.example.org/report/REPORT_ID
-
-Bei Fragen zu "Z=FCri wie neu" wenden Sie sich bitte an
-gis-zentrum@zuerich.ch.=
-
-
-
---
-MIME-Version: 1.0
-Content-Type: image/jpeg; name="REPORT_ID.0.jpeg"
-Content-Disposition: inline; filename="REPORT_ID.0.jpeg"
-Content-Transfer-Encoding: base64
-
-/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEP
-ERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4e
-Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCABTAAEDAREA
-AhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAIIB//EAB8QAQAABAcAAAAAAAAAAAAAAAADBAbT
-BxcYVVaUpf/EABcBAQEBAQAAAAAAAAAAAAAAAAAFBgT/xAAgEQEAAAQHAQAAAAAAAAAAAAAAAwQV
-UgECFlNhodGx/9oADAMBAAIRAxEAPwCywAIozyxS5R58tbbujSW33j6zFRj3fGbKbjAGAgAACs9N
-FCbtUfYg2mO1BM25e/V+lQeW3ISo/9k=
-
-----
+MIME-Version: 1.0
+Subject: =?iso-8859-1?Q?Z=FCri?= wie neu: Weitergeleitete Meldung #REPORT_ID
+Content-Type: multipart/mixed; boundary="BOUNDARY"
+To: "External Body" <external_body@example.org>
+Content-Transfer-Encoding: 7bit
+From: "FixMyStreet" <division@example.org>
+
+
+--BOUNDARY
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: quoted-printable
+
+Gr=C3=BCezi External Body,
+
+=C3=96ffentliche URL: http://www.example.org/report/REPORT_ID
+
+Bei Fragen zu "Z=C3=BCri wie neu" wenden Sie sich bitte an
+gis-zentrum@zuerich.ch.=
+
+--BOUNDARY
+Content-Type: image/jpeg; name="REPORT_ID.0.jpeg"
+Content-Disposition: inline; filename="REPORT_ID.0.jpeg"
+Content-Transfer-Encoding: base64
+
+/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEP
+ERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4e
+Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCABTAAEDAREA
+AhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAIIB//EAB8QAQAABAcAAAAAAAAAAAAAAAADBAbT
+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/fixmystreet.t b/t/fixmystreet.t
index d7f00b047..a601c10d5 100644
--- a/t/fixmystreet.t
+++ b/t/fixmystreet.t
@@ -18,17 +18,17 @@ is "$path_to_path", $file_path, "got $file_path";
# check that the config gets loaded and is immutable
my $config = FixMyStreet->config;
isa_ok $config, 'HASH';
-is $config->{GAZE_URL}, 'http://gaze.mysociety.org/gaze',
+is $config->{GAZE_URL}, 'https://gaze.mysociety.org/gaze',
"got GAZE_URL correctly";
throws_ok(
sub { $config->{GAZE_URL} = 'some other value'; },
qr/Modification of a read-only value attempted/,
'attempt to change config caught'
);
-is $config->{GAZE_URL}, 'http://gaze.mysociety.org/gaze', "GAZE_URL unchanged";
+is $config->{GAZE_URL}, 'https://gaze.mysociety.org/gaze', "GAZE_URL unchanged";
# check that we can get the value by key as well
-is FixMyStreet->config('GAZE_URL'), 'http://gaze.mysociety.org/gaze',
+is FixMyStreet->config('GAZE_URL'), 'https://gaze.mysociety.org/gaze',
"GAZE_URL correct when got by key";
is FixMyStreet->config('BAD_KEY_DOES_NOT_EXIST'), undef, "config miss is undef";
diff --git a/t/i18n.t b/t/i18n.t
index 3337f1a7f..3984c91ce 100644
--- a/t/i18n.t
+++ b/t/i18n.t
@@ -14,11 +14,11 @@ use mySociety::Locale;
die "You need to run 'commonlib/bin/gettext-makemo --quiet FixMyStreet' "
. "to generate the *.mo files needed."
unless -e FixMyStreet->path_to(
- 'locale/cy_GB.UTF-8/LC_MESSAGES/FixMyStreet-EmptyHomes.mo');
+ 'locale/nb_NO.UTF-8/LC_MESSAGES/FixMyStreet.mo');
# Test the language negotiation works
my $lang = mySociety::Locale::negotiate_language(
- 'en-gb,English,en_GB|cy,Cymraeg,cy_GB|es,Spanish,es_ES',
+ 'en-gb,English,en_GB|es,Spanish,es_ES',
undef,
HTTP::Headers->new(
Accept_Language => 'es,en-gb;q=0.6,en;q=0.4'
@@ -28,27 +28,26 @@ is $lang, 'es', 'Language negotiation works okay';
# Example strings
my $english = "Please enter a valid email";
-my $welsh = "Cofnodwch gyfeiriad e-bost dilys";
+my $norwegian = "Legg til en gyldig e-post";
# set english as the language
mySociety::Locale::negotiate_language( #
- 'en-gb,English,en_GB|cy,Cymraeg,cy_GB', 'en_GB'
+ 'en-gb,English,en_GB|nb,Norwegian,nb_NO', 'en_GB'
);
-mySociety::Locale::gettext_domain( 'FixMyStreet-EmptyHomes', 1 );
+mySociety::Locale::gettext_domain( 'FixMyStreet', 1 );
mySociety::Locale::change();
is _($english), $english, "english to english";
-# set to welsh and check for translation
-mySociety::Locale::change('cy');
-is _($english), $welsh, "english to welsh";
+mySociety::Locale::change('nb');
+is _($english), $norwegian, "english to norwegian";
# check that being in a deep directory does not confuse the code
chdir FixMyStreet->path_to('t/app/controller') . '';
-mySociety::Locale::gettext_domain( 'FixMyStreet-EmptyHomes', 1,
+mySociety::Locale::gettext_domain( 'FixMyStreet', 1,
FixMyStreet->path_to('locale')->stringify );
-mySociety::Locale::change('cy');
-is _($english), $welsh, "english to welsh (deep directory)";
+mySociety::Locale::change('nb');
+is _($english), $norwegian, "english to norwegian (deep directory)";
# test that sorting works as expected in the right circumstances...
my @random_sorted = qw( Å Z Ø A );
@@ -56,10 +55,10 @@ my @EN_sorted = qw( A Å Ø Z );
my @NO_sorted = qw( A Z Ø Å );
my @default_sorted = qw( A Z Å Ø );
-{
+SKIP: {
mySociety::Locale::negotiate_language( #
- 'en-gb,English,en_GB|cy,Cymraeg,cy_GB', 'en_GB'
+ 'en-gb,English,en_GB', 'en_GB'
);
mySociety::Locale::change();
@@ -71,14 +70,18 @@ my @default_sorted = qw( A Z Å Ø );
is_deeply( [ keysort { $_ } @random_sorted ],
\@default_sorted, "keysort correctly with no locale" );
+ skip 'Will not pass on Mac', 1 if $^O eq 'darwin';
+
# Note - this obeys the locale
is_deeply( [ sort { strcoll( $a, $b ) } @random_sorted ],
\@EN_sorted, "sort strcoll correctly with no locale (to 'en_GB')" );
}
-{
+SKIP: {
+ skip 'Will not pass on Mac', 2 if $^O eq 'darwin';
+
mySociety::Locale::negotiate_language( #
- 'en-gb,English,en_GB|cy,Cymraeg,cy_GB', 'en_GB'
+ 'en-gb,English,en_GB', 'en_GB'
);
mySociety::Locale::change();
use locale;
@@ -93,7 +96,9 @@ my @default_sorted = qw( A Z Å Ø );
\@EN_sorted, "sort strcoll correctly with use locale 'en_GB'" );
}
-{
+SKIP: {
+ skip 'Will not pass on Mac', 2 if $^O eq 'darwin';
+
mySociety::Locale::negotiate_language( #
'nb-no,Norwegian,nb_NO', 'nb_NO'
);
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..42d09b29c 100644
--- a/t/open311.t
+++ b/t/open311.t
@@ -3,9 +3,11 @@
use utf8;
use strict;
use warnings;
+use File::Temp 'tempdir';
+use Path::Tiny;
use Test::More;
use Test::Warn;
-use FixMyStreet::App;
+use FixMyStreet::DB;
use CGI::Simple;
use HTTP::Response;
use DateTime;
@@ -24,11 +26,11 @@ EOT
is $o->_process_error( $err_text ), "400: Service Code cannot be null -- can't proceed with the request.\n", 'error text parsing';
is $o->_process_error( '503 - service unavailable' ), 'unknown error', 'error text parsing of bad error';
-my $o2 = Open311->new( endpoint => 'http://192.168.50.1/open311/', jurisdiction => 'example.org' );
+my $o2 = Open311->new( endpoint => 'http://127.0.0.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 +47,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 +209,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,
@@ -258,16 +260,26 @@ subtest 'extended request update post parameters' => sub {
};
subtest 'check media url set' => sub {
- $comment->photo(1);
+ my $UPLOAD_DIR = tempdir( CLEANUP => 1 );
+
+ my $image_path = path('t/app/controller/sample.jpg');
+ $image_path->copy( path( $UPLOAD_DIR, '0123456789012345678901234567890123456789.jpeg' ) );
+
+ $comment->photo("0123456789012345678901234567890123456789");
$comment->cobrand('fixmystreet');
- my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' );
+ FixMyStreet::override_config {
+ UPLOAD_DIR => $UPLOAD_DIR,
+ }, sub {
+ my $results = make_update_req( $comment, '<?xml version="1.0" encoding="utf-8"?><service_request_updates><request_update><update_id>248</update_id></request_update></service_request_updates>' );
- is $results->{ res }, 248, 'got update id';
+ is $results->{ res }, 248, 'got update id';
- my $c = CGI::Simple->new( $results->{ req }->content );
- my $expected_path = '/c/' . $comment->id . '.full.jpeg';
- like $c->param('media_url'), qr/$expected_path/, 'image url included';
+ my $c = CGI::Simple->new( $results->{ req }->content );
+ my $expected_path = '/c/' . $comment->id . '.0.full.jpeg';
+ like $c->param('media_url'), qr/$expected_path/, 'image url included';
+ };
+ $comment->photo(undef);
};
foreach my $test (
@@ -394,7 +406,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..134d5422e 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"?>
@@ -36,7 +38,7 @@ UPDATED_DATETIME
};
-my $dt = DateTime->now;
+my $dt = DateTime->now(formatter => DateTime::Format::W3CDTF->new);
# basic xml -> perl object tests
for my $test (
@@ -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.jpeg', '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,
@@ -544,7 +571,8 @@ subtest 'check that existing comments are not duplicated' => sub {
is $problem->comments->count, 1, 'one comment before fetching updates';
$requests_xml =~ s/UPDATED_DATETIME2/$dt/;
- $requests_xml =~ s/UPDATED_DATETIME/@{[ $comment->confirmed ]}/;
+ my $confirmed = DateTime::Format::W3CDTF->format_datetime($comment->confirmed);
+ $requests_xml =~ s/UPDATED_DATETIME/$confirmed/;
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $requests_xml } );
@@ -569,12 +597,12 @@ subtest 'check that existing comments are not duplicated' => sub {
foreach my $test ( {
desc => 'check that closed and then open comment results in correct state',
- dt1 => $dt->subtract( hours => 1 ),
+ dt1 => $dt->clone->subtract( hours => 1 ),
dt2 => $dt,
},
{
desc => 'check that old comments do not change problem status',
- dt1 => $dt->subtract( hours => 2 ),
+ dt1 => $dt->clone->subtract( minutes => 90 ),
dt2 => $dt,
}
) {
@@ -600,7 +628,7 @@ foreach my $test ( {
$problem->comments->delete;
$problem->state( 'confirmed' );
- $problem->lastupdate( $dt->subtract( hours => 3 ) );
+ $problem->lastupdate( $dt->clone->subtract( hours => 3 ) );
$problem->update;
$requests_xml =~ s/UPDATED_DATETIME/$test->{dt1}/;
@@ -656,11 +684,11 @@ foreach my $test ( {
$problem->comments->delete;
$problem->state( 'confirmed' );
- $problem->lastupdate( $dt->subtract( hours => 3 ) );
+ $problem->lastupdate( $dt->clone->subtract( hours => 3 ) );
$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 +708,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',