aboutsummaryrefslogtreecommitdiffstats
path: root/t/app/controller
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2016-05-28 13:49:00 +0200
committerMarius Halden <marius.h@lden.org>2016-05-28 13:49:00 +0200
commit6791ce86ae15adbded24bd814a78cc0e87f404fa (patch)
tree99af5da31e4db091350a09bcdee913c99abc2fc3 /t/app/controller
parent6c1118dbf2c4b15bcfcd77600d36f2389428c75e (diff)
parent89b0efeb94631c4c31ce33e7f98297e754dd226d (diff)
Merge tag 'v1.8.2' into fiksgatami-dev
Diffstat (limited to 't/app/controller')
-rw-r--r--t/app/controller/about.t18
-rw-r--r--t/app/controller/admin.t11
-rw-r--r--t/app/controller/auth_social.t117
-rw-r--r--t/app/controller/photo.t4
-rw-r--r--t/app/controller/questionnaire.t35
-rw-r--r--t/app/controller/report_interest_count.t24
-rw-r--r--t/app/controller/report_new.t4
-rw-r--r--t/app/controller/report_updates.t3
-rw-r--r--t/app/controller/reports.t16
9 files changed, 166 insertions, 66 deletions
diff --git a/t/app/controller/about.t b/t/app/controller/about.t
index 6a082a2ff..cec50abfa 100644
--- a/t/app/controller/about.t
+++ b/t/app/controller/about.t
@@ -1,3 +1,4 @@
+use utf8;
use strict;
use warnings;
@@ -21,19 +22,12 @@ 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 92cbbc00f..1dcb768dc 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -104,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/);
@@ -115,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');
@@ -171,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' );
diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t
index 84fdd4dfe..6929c0ddc 100644
--- a/t/app/controller/auth_social.t
+++ b/t/app/controller/auth_social.t
@@ -6,6 +6,7 @@ use LWP::Simple;
use JSON::MaybeXS;
use t::Mock::Facebook;
+use t::Mock::Twitter;
use t::Mock::MapIt;
use FixMyStreet::TestMech;
@@ -21,6 +22,7 @@ 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 {
@@ -31,7 +33,10 @@ 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 });
@@ -135,6 +140,118 @@ for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) {
}
}
+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 {
diff --git a/t/app/controller/photo.t b/t/app/controller/photo.t
index 39380e769..425e3c4df 100644
--- a/t/app/controller/photo.t
+++ b/t/app/controller/photo.t
@@ -65,10 +65,10 @@ subtest "Check multiple upload worked" => sub {
ok $mech->success, 'Made request with multiple photo upload';
$mech->base_is('http://localhost/report/new');
$mech->content_like(
- qr[(<img align="right" src="/photo/1cdd4329ceee2234bd4e89cb33b42061a0724687.temp.jpeg" alt="">\s*){3}],
+ 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 7718d5034..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'";
@@ -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_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 cf72221b4..eb29d37da 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -420,7 +420,7 @@ foreach my $test (
changes => {
photo1 => '',
},
- errors => [ "Please upload a JPEG image only" ],
+ errors => [ "Please upload an image only" ],
},
{
msg => 'bad photo upload gives error',
@@ -443,7 +443,7 @@ foreach my $test (
changes => {
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',
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index f9f5189e5..7b4bf7854 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -760,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,
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' ],