aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2016-08-01 12:03:45 +0100
committerDave Arter <davea@mysociety.org>2016-08-01 12:03:45 +0100
commit1af9684e54aedb7f9935cdc4d38a28c61ec7d1f5 (patch)
treed6b044f54e070f8dbf265083534e849eb9ad6ead /t
parent14aaf6fafaa9aa8736f49851e95fa2c3c566c056 (diff)
parent27e0c74321f48f9997745bf00647e3958f34d8e2 (diff)
Merge branch '1281-html-emails'
Diffstat (limited to 't')
-rw-r--r--t/app/controller/alert_new.t75
-rw-r--r--t/app/controller/auth.t19
-rw-r--r--t/app/controller/auth_social.t12
-rw-r--r--t/app/controller/contact.t8
-rw-r--r--t/app/controller/moderate.t3
-rw-r--r--t/app/controller/questionnaire.t28
-rw-r--r--t/app/controller/report_import.t15
-rw-r--r--t/app/controller/report_new.t38
-rw-r--r--t/app/controller/report_updates.t27
-rw-r--r--t/app/helpers/emails/html_test.html15
-rw-r--r--t/app/helpers/emails/html_test.txt14
-rw-r--r--t/app/helpers/emails/test.txt14
-rw-r--r--t/app/helpers/send_email.t32
-rw-r--r--t/app/model/alert_type.t18
-rw-r--r--t/app/model/problem.t27
-rw-r--r--t/cobrand/bromley.t7
-rw-r--r--t/cobrand/fixamingata.t11
17 files changed, 195 insertions, 168 deletions
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 2c20daf9d..1b85adf7e 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -98,9 +98,10 @@ foreach my $test (
my $email = $mech->get_email;
ok $email, "got an email";
- like $email->body, qr/$test->{email_text}/i, "Correct email text";
+ like $mech->get_text_body_from_email($email), qr/$test->{email_text}/i, "Correct email text";
- my ( $url, $url_token ) = $email->body =~ m{(http://\S+/A/)(\S+)};
+ my $url = $mech->get_link_from_email($email);
+ my ($url_token) = $url =~ m{/A/(\S+)};
ok $url, "extracted confirm url '$url'";
my $token = FixMyStreet::App->model('DB::Token')->find(
@@ -119,10 +120,8 @@ foreach my $test (
$mech->get_ok( $test->{uri} . "&token=$csrf" );
- $email = $mech->get_email;
- ok $email, 'got a second email';
-
- ($url_token) = $email->body =~ m{http://\S+/A/(\S+)};
+ $url = $mech->get_link_from_email;
+ ($url_token) = $url =~ m{/A/(\S+)};
ok $url_token ne $existing_token, 'sent out a new token';
$token = FixMyStreet::App->model('DB::Token')->find(
@@ -361,9 +360,9 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
} );
};
if ( $alert->{email_confirm} ) {
- my $email = $mech->get_email;
+ my $url = $mech->get_link_from_email;
+ my ($url_token) = $url =~ m{/A/(\S+)};
$mech->clear_emails_ok;
- my ( $url, $url_token ) = $email->body =~ m{http://\S+(/A/(\S+))};
my $token = FixMyStreet::App->model('DB::Token')->find( { token => $url_token, scope => 'alert' } );
$mech->get_ok( $url );
$mech->content_contains('alert created');
@@ -446,30 +445,32 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
my @emails = $mech->get_email;
my $count;
for (@emails) {
- $count++ if $_->body =~ /The following updates have been left on this report:/;
- $count++ if $_->body =~ /The following new FixMyStreet reports have been added in the City of\s+Edinburgh\s+Council area:/;
- $count++ if $_->body =~ /The following FixMyStreet reports have been made within the area you\s+specified:/;
- $count++ if $_->body =~ /\s+-\s+Testing/;
+ my $body = $mech->get_text_body_from_email($_);
+ $count++ if $body =~ /The following updates have been left on this report:/;
+ $count++ if $body =~ /The following new FixMyStreet reports have been added in the City of\s+Edinburgh\s+Council area:/;
+ $count++ if $body =~ /The following FixMyStreet reports have been made within the area you\s+specified:/;
+ $count++ if $body =~ /\s+-\s+Testing/;
}
is $count, 5, 'Three emails, with five matching lines in them';
my $email = $emails[0];
- like $email->body, qr/Other User/, 'Update name given';
- unlike $email->body, qr/Anonymous User/, 'Update name not given';
+ my $body = $mech->get_text_body_from_email($email);
+ like $body, qr/Other User/, 'Update name given';
+ unlike $body, qr/Anonymous User/, 'Update name not given';
# The update alert was to the problem reporter, so has a special update URL
$mech->log_out_ok;
$mech->get_ok( "/report/$report_id" );
$mech->content_lacks( 'has not been fixed' );
- my ($url) = $email->body =~ m{(http://\S+/R/\S+)};
- ok $url, "extracted update url '$url'";
- $mech->get_ok( $url );
+ my @urls = $mech->get_link_from_email($email, 1);
+ ok $urls[0] =~ m{/R/\S+}, "extracted update url '$urls[0]'";
+ $mech->get_ok( $urls[0] );
is $mech->uri->path, "/report/" . $report_id, "redirected to report page";
$mech->content_contains( 'has not been fixed' );
$mech->not_logged_in_ok;
- ($url) = $emails[0]->body =~ m{http://\S+(/A/\S+)};
- $mech->get_ok( $url );
+ ok $urls[-1] =~ m{/A/\S+}, "unsubscribe URL '$urls[-1]'";
+ $mech->get_ok( $urls[-1] );
$mech->content_contains('alert deleted');
$mech->not_logged_in_ok;
@@ -546,13 +547,10 @@ subtest "Test signature template is used from cobrand" => sub {
}, sub {
FixMyStreet::App->model('DB::AlertType')->email_alerts();
};
- # TODO Note the below will fail if the db has an existing alert that matches
- $mech->email_count_is(1);
- my @emails = $mech->get_email;
- my $email = $emails[0];
- like $email->body, qr/All the best/, 'default signature used';
- unlike $email->body, qr/twitter.com/, 'nothing from fixmystreet signature';
+ my $email = $mech->get_text_body_from_email;
+ like $email, qr/All the best/, 'default signature used';
+ unlike $email, qr/twitter.com/, 'nothing from fixmystreet signature';
$update = FixMyStreet::App->model('DB::Comment')->create( {
problem_id => $report_id,
@@ -577,12 +575,9 @@ subtest "Test signature template is used from cobrand" => sub {
}, sub {
FixMyStreet::App->model('DB::AlertType')->email_alerts();
};
- # TODO Note the below will fail if the db has an existing alert that matches
- $mech->email_count_is(1);
- @emails = $mech->get_email;
- $email = $emails[0];
- like $email->body, qr/twitter.com/, 'fixmystreet signature used';
+ $email = $mech->get_text_body_from_email;
+ like $email, qr/twitter.com/, 'fixmystreet signature used';
$mech->delete_user($user1);
$mech->delete_user($user2);
@@ -682,9 +677,8 @@ for my $test (
}, sub {
FixMyStreet::App->model('DB::AlertType')->email_alerts();
};
- $mech->email_count_is(1);
- my $email = $mech->get_email;
- like $email->body, qr/Alert\s+test\s+for\s+non\s+public\s+reports/, 'alert contains public report';
+ my $email = $mech->get_text_body_from_email;
+ like $email, qr/Alert\s+test\s+for\s+non\s+public\s+reports/, 'alert contains public report';
$mech->delete_user( $user1 );
$mech->delete_user( $user2 );
@@ -766,16 +760,14 @@ subtest 'check new updates alerts for non public reports only go to report owner
ok $alert_user2, "alert created";
FixMyStreet::App->model('DB::AlertType')->email_alerts();
- $mech->email_count_is(1);
- my $email = $mech->get_email;
- like $email->body, qr/This is some more update text/, 'alert contains update text';
+ my $email = $mech->get_text_body_from_email;
+ like $email, qr/This is some more update text/, 'alert contains update text';
$mech->clear_emails_ok;
$report->update( { non_public => 0 } );
FixMyStreet::App->model('DB::AlertType')->email_alerts();
- $mech->email_count_is(1);
- $email = $mech->get_email;
- like $email->body, qr/This is some more update text/, 'alert contains update text';
+ $email = $mech->get_text_body_from_email;
+ like $email, qr/This is some more update text/, 'alert contains update text';
$mech->delete_user( $user1 );
$mech->delete_user( $user2 );
@@ -848,7 +840,6 @@ subtest 'check setting inlude dates in new updates cobrand option' => sub {
$mech->clear_emails_ok;
FixMyStreet::App->model('DB::AlertType')->email_alerts();
- $mech->email_count_is(1);
# if we don't do this then we're applying the date inflation code and
# it's timezone munging to the DateTime object above and not the DateTime
@@ -858,8 +849,8 @@ subtest 'check setting inlude dates in new updates cobrand option' => sub {
$update->discard_changes();
my $date_in_alert = Utils::prettify_dt( $update->confirmed );
- my $email = $mech->get_email;
- like $email->body, qr/$date_in_alert/, 'alert contains date';
+ my $email = $mech->get_text_body_from_email;
+ like $email, qr/$date_in_alert/, 'alert contains date';
$mech->delete_user( $user1 );
$mech->delete_user( $user2 );
diff --git a/t/app/controller/auth.t b/t/app/controller/auth.t
index 60f22acfb..251aa2977 100644
--- a/t/app/controller/auth.t
+++ b/t/app/controller/auth.t
@@ -72,8 +72,7 @@ $mech->not_logged_in_ok;
is $email->header('To'), $test_email, "to is correct";
# extract the link
- my ($link) = $email->body =~ m{(http://\S+)};
- ok $link, "Found a link in email '$link'";
+ my $link = $mech->get_link_from_email($email);
# check that the user does not exist
sub get_user {
@@ -117,9 +116,7 @@ $mech->not_logged_in_ok;
# follow link and change password - check not prompted for old password
$mech->not_logged_in_ok;
- my $email = $mech->get_email;
- $mech->clear_emails_ok;
- my ($link) = $email->body =~ m{(http://\S+)};
+ my $link = $mech->get_link_from_email;
$mech->get_ok($link);
is $mech->uri->path, '/faq', "redirected to the Help page";
@@ -187,9 +184,7 @@ subtest "Test change email page" => sub {
$mech->submit_form_ok({ with_fields => { email => $test_email2 } }, "change_email to $test_email2");
is $mech->uri->path, '/auth/change_email', "still on change email page";
$mech->content_contains( 'Now check your email', "found check your email" );
- my $email = $mech->get_email;
- $mech->clear_emails_ok;
- my ($link) = $email->body =~ m{(http://\S+)};
+ my $link = $mech->get_link_from_email;
$mech->get_ok($link);
is $mech->uri->path, '/auth/change_email/success', "redirected to the change_email page";
$mech->content_contains('successfully confirmed');
@@ -201,9 +196,7 @@ subtest "Test change email page" => sub {
);
is $mech->uri->path, '/auth/change_email', "still on change email page";
$mech->content_contains( 'Now check your email', "found check your email" );
- $email = $mech->get_email;
- $mech->clear_emails_ok;
- ($link) = $email->body =~ m{(http://\S+)};
+ $link = $mech->get_link_from_email;
$mech->get_ok($link);
is $mech->uri->path, '/auth/change_email/success', "redirected to the change_email page";
$mech->content_contains('successfully confirmed');
@@ -214,9 +207,7 @@ subtest "Test change email page" => sub {
);
is $mech->uri->path, '/auth/change_email', "still on change email page";
$mech->content_contains( 'Now check your email', "found check your email" );
- $email = $mech->get_email;
- $mech->clear_emails_ok;
- ($link) = $email->body =~ m{(http://\S+)};
+ $link = $mech->get_link_from_email;
$mech->log_out_ok;
$mech->get_ok($link);
isnt $mech->uri->path, '/auth/change_email/success', "not redirected to the change_email page";
diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t
index 6929c0ddc..f3eae32a7 100644
--- a/t/app/controller/auth_social.t
+++ b/t/app/controller/auth_social.t
@@ -113,10 +113,8 @@ for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) {
$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";
+ my $url = $mech->get_link_from_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 } );
@@ -125,7 +123,7 @@ for my $fb_state ( 'refused', 'no email', 'existing UID', 'okay' ) {
} else {
is $user->facebook_id, undef, 'User has no facebook ID';
}
- $mech->get_ok( $url . $url_token );
+ $mech->get_ok( $url );
$user = FixMyStreet::App->model( 'DB::User' )->find( { email => $fb_email } );
is $user->facebook_id, $fb_uid, 'User now has correct facebook ID';
@@ -225,10 +223,8 @@ for my $tw_state ( 'refused', 'existing UID', 'no email' ) {
$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";
+ my $url = $mech->get_link_from_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 } );
@@ -237,7 +233,7 @@ for my $tw_state ( 'refused', 'existing UID', 'no email' ) {
} else {
is $user->twitter_id, undef, 'User has no twitter ID';
}
- $mech->get_ok( $url . $url_token );
+ $mech->get_ok( $url );
$user = FixMyStreet::App->model( 'DB::User' )->find( { email => $tw_email } );
is $user->twitter_id, $tw_uid, 'User now has correct twitter ID';
diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t
index 1b0f09a85..dd94fc431 100644
--- a/t/app/controller/contact.t
+++ b/t/app/controller/contact.t
@@ -251,16 +251,16 @@ for my $test (
}
$mech->submit_form_ok( { with_fields => $test->{fields} } );
$mech->content_contains('Thank you for your feedback');
- $mech->email_count_is(1);
my $email = $mech->get_email;
is $email->header('Subject'), 'FMS message: ' . $test->{fields}->{subject}, 'subject';
is $email->header('From'), "\"$test->{fields}->{name}\" <$test->{fields}->{em}>", 'from';
- like $email->body, qr/$test->{fields}->{message}/, 'body';
- like $email->body, qr/Sent by contact.cgi on \S+. IP address (?:\d{1,3}\.){3,}\d{1,3}/, 'body footer';
+ my $body = $mech->get_text_body_from_email($email);
+ like $body, qr/$test->{fields}->{message}/, 'body';
+ like $body, qr/Sent by contact.cgi on \S+. IP address (?:\d{1,3}\.){3,}\d{1,3}/, 'body footer';
my $problem_id = $test->{fields}{id};
- like $email->body, qr/Complaint about report $problem_id/, 'reporting a report'
+ like $body, qr/Complaint about report $problem_id/, 'reporting a report'
if $test->{fields}{id};
$problem_main->discard_changes;
diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t
index 14c751115..e3e8bf2cf 100644
--- a/t/app/controller/moderate.t
+++ b/t/app/controller/moderate.t
@@ -169,8 +169,7 @@ subtest 'Problem moderation' => sub {
$report->discard_changes;
is $report->state, 'hidden', 'Is hidden';
- my $email = $mech->get_email;
- my ($url) = $email->body =~ m{(http://\S+)};
+ my $url = $mech->get_link_from_email;
ok $url, "extracted complain url '$url'";
$mech->get_ok($url);
diff --git a/t/app/controller/questionnaire.t b/t/app/controller/questionnaire.t
index 7a46e48bd..b05f74225 100644
--- a/t/app/controller/questionnaire.t
+++ b/t/app/controller/questionnaire.t
@@ -58,12 +58,14 @@ FixMyStreet::App->model('DB::Questionnaire')->send_questionnaires( {
} );
my $email = $mech->get_email;
ok $email, "got an email";
-like $email->body, qr/fill in our short questionnaire/i, "got questionnaire email";
+my $plain = $mech->get_text_body_from_email($email, 1);
+like $plain->body, qr/fill in our short questionnaire/i, "got questionnaire email";
-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';
+like $plain->body_str, qr/Testing \x{2013} Detail/, 'email contains encoded character';
+is $plain->header('Content-Type'), 'text/plain; charset="utf-8"', 'in the right character set';
-my ($token) = $email->body =~ m{http://.*?/Q/(\S+)};
+my $url = $mech->get_link_from_email($email);
+my ($token) = $url =~ m{/Q/(\S+)};
ok $token, "extracted questionnaire token '$token'";
$mech->clear_emails_ok;
@@ -399,13 +401,14 @@ FixMyStreet::override_config {
$questionnaire->delete;
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;
+ my $email = $mech->get_email;
+ my $body = $mech->get_text_body_from_email($email);
+ $mech->clear_emails_ok;
+ $body =~ s/\s+/ /g;
like $body, qr/fill in our short questionnaire/i, "got questionnaire email";
- ($token) = $email->body =~ m{http://.*?/Q/(\S+)};
+ my $url = $mech->get_link_from_email($email);
+ ($token) = $url =~ m{/Q/(\S+)};
ok $token, "extracted questionnaire token '$token'";
# Test already answered the ever reported question, so not shown again
@@ -445,9 +448,10 @@ FixMyStreet::override_config {
ok $email, "got an email";
$mech->clear_emails_ok;
- 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';
+ my $plain = $mech->get_text_body_from_email($email, 1);
+ like $plain->body_str, qr/Testing \x{2013} Detail/, 'email contains encoded character from user';
+ like $plain->body_str, qr/sak p\xe5 FiksGataMi/, 'email contains encoded character from template';
+ is $plain->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 26acf7790..c8cbcf412 100644
--- a/t/app/controller/report_import.t
+++ b/t/app/controller/report_import.t
@@ -114,11 +114,8 @@ subtest "Submit a correct entry" => sub {
is $mech->content, 'SUCCESS', "Got success response";
# check that we have received the email
- $mech->email_count_is(1);
- my $email = $mech->get_email;
+ my $token_url = $mech->get_link_from_email;
$mech->clear_emails_ok;
-
- my ($token_url) = $email->body =~ m{(http://\S+)};
ok $token_url, "Found a token url $token_url";
# go to the token url
@@ -257,11 +254,8 @@ subtest "Submit a correct entry (with location)" => sub {
is $mech->content, 'SUCCESS', "Got success response";
# check that we have received the email
- $mech->email_count_is(1);
- my $email = $mech->get_email;
+ my $token_url = $mech->get_link_from_email;
$mech->clear_emails_ok;
-
- my ($token_url) = $email->body =~ m{(http://\S+)};
ok $token_url, "Found a token url $token_url";
# go to the token url
@@ -356,11 +350,8 @@ subtest "Submit a correct entry (with location) to cobrand" => sub {
is $mech->content, 'SUCCESS', "Got success response";
# check that we have received the email
- $mech->email_count_is(1);
- my $email = $mech->get_email;
+ my $token_url = $mech->get_link_from_email;
$mech->clear_emails_ok;
-
- my ($token_url) = $email->body =~ m{(http://\S+)};
ok $token_url, "Found a token url $token_url";
# go to the token url
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 2aebfa00b..6b4f40172 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -607,10 +607,9 @@ foreach my $test (
# receive token
my $email = $mech->get_email;
ok $email, "got an email";
- like $email->body, qr/confirm that you want to send your\s+report/i, "confirm the problem";
+ like $mech->get_text_body_from_email($email), qr/confirm that you want to send your\s+report/i, "confirm the problem";
- my ($url) = $email->body =~ m{(http://\S+)};
- ok $url, "extracted confirm url '$url'";
+ my $url = $mech->get_link_from_email($email);
# confirm token
$mech->get_ok($url);
@@ -949,10 +948,9 @@ subtest "test report creation for a category that is non public" => sub {
my $email = $mech->get_email;
ok $email, "got an email";
- like $email->body, qr/confirm that you want to send your\s+report/i, "confirm the problem";
+ like $mech->get_text_body_from_email($email), qr/confirm that you want to send your\s+report/i, "confirm the problem";
- my ($url) = $email->body =~ m{(http://\S+)};
- ok $url, "extracted confirm url '$url'";
+ my $url = $mech->get_link_from_email($email);
# confirm token
$mech->get_ok($url);
@@ -1145,10 +1143,9 @@ for my $test (
my $email = $mech->get_email;
ok $email, "got an email";
- like $email->body, qr/confirm that you want to send your\s+report/i, "confirm the problem";
+ like $mech->get_text_body_from_email($email), qr/confirm that you want to send your\s+report/i, "confirm the problem";
- my ($url) = $email->body =~ m{(https?://\S+)};
- ok $url, "extracted confirm url '$url'";
+ my $url = $mech->get_link_from_email($email);
# confirm token in order to update the user details
$mech->get_ok($url);
@@ -1315,17 +1312,17 @@ subtest "test Hart" => sub {
# receive token
my $email = $mech->get_email;
ok $email, "got an email";
- like $email->body, qr/to confirm that you want to send your/i, "confirm the problem";
+ my $body = $mech->get_text_body_from_email($email);
+ like $body, qr/to confirm that you want to send your/i, "confirm the problem";
# does it reference the fact that this report hasn't been sent to Hart?
if ( $test->{national} ) {
- like $email->body, qr/Hart Council is not responsible for this type/i, "mentions report hasn't gone to Hart";
+ like $body, qr/Hart Council is not responsible for this type/i, "mentions report hasn't gone to Hart";
} else {
- unlike $email->body, qr/Hart Council is not responsible for this type/i, "doesn't mention report hasn't gone to Hart";
+ unlike $body, qr/Hart Council is not responsible for this type/i, "doesn't mention report hasn't gone to Hart";
}
- my ($url) = $email->body =~ m{(http://\S+)};
- ok $url, "extracted confirm url '$url'";
+ my $url = $mech->get_link_from_email($email);
# confirm token
FixMyStreet::override_config {
@@ -1541,9 +1538,7 @@ subtest "unresponsive body handling works" => sub {
ok $report, "Found the report";
is $report->bodies_str, undef, "Report not going anywhere";
- my $email = $mech->get_email;
- ok $email, "got an email";
- like $email->body, qr/despite not being sent/i, "correct email sent";
+ like $mech->get_text_body_from_email, qr/despite not being sent/i, "correct email sent";
$user->problems->delete;
$mech->clear_emails_ok;
@@ -1577,9 +1572,7 @@ subtest "unresponsive body handling works" => sub {
ok $report, "Found the report";
is $report->bodies_str, undef, "Report not going anywhere";
- $email = $mech->get_email;
- ok $email, "got an email";
- like $email->body, qr/despite not being sent/i, "correct email sent";
+ like $mech->get_text_body_from_email, qr/despite not being sent/i, "correct email sent";
$user->problems->delete;
$mech->clear_emails_ok;
@@ -1737,10 +1730,9 @@ subtest "extra google analytics code displayed on email confirmation problem cre
my $email = $mech->get_email;
ok $email, "got an email";
- like $email->body, qr/confirm that you want to/i, "confirm the problem";
+ like $mech->get_text_body_from_email($email), qr/confirm that you want to/i, "confirm the problem";
- my ($url) = $email->body =~ m{(https?://\S+)};
- ok $url, "extracted confirm url '$url'";
+ my $url = $mech->get_link_from_email($email);
# confirm token in order to update the user details
$mech->get_ok($url);
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index e077a07c9..e1cd0da71 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -362,10 +362,11 @@ for my $test (
$mech->content_contains('Nearly done! Now check your email');
my $email = $mech->get_email;
- ok $email, "got an email";
- like $email->body, qr/confirm your update on/i, "Correct email text";
+ my $body = $mech->get_text_body_from_email($email);
+ like $body, qr/confirm your update on/i, "Correct email text";
- my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)};
+ my $url = $mech->get_link_from_email($email);
+ my ($url_token) = $url =~ m{/C/(\S+)};
ok $url, "extracted confirm url '$url'";
my $token = FixMyStreet::App->model('DB::Token')->find(
@@ -392,7 +393,7 @@ for my $test (
is $update->text, $details->{update}, 'update text';
is $add_alerts, $details->{add_alert} ? 1 : 0, 'do not sign up for alerts';
- $mech->get_ok( $url . $url_token );
+ $mech->get_ok( $url );
$mech->content_contains("/report/$report_id#update_$update_id");
my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => $details->{rznvy} } );
@@ -1000,10 +1001,11 @@ subtest 'submit an update for a registered user, creating update by email' => su
is $user->name, 'Mr Reg', 'name unchanged';
my $email = $mech->get_email;
- ok $email, "got an email";
- like $email->body, qr/confirm your update on/i, "Correct email text";
+ my $body = $mech->get_text_body_from_email($email);
+ like $body, qr/confirm your update on/i, "Correct email text";
- my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)};
+ my $url = $mech->get_link_from_email($email);
+ my ($url_token) = $url =~ m{/C/(\S+)};
ok $url, "extracted confirm url '$url'";
my $token = FixMyStreet::App->model('DB::Token')->find( {
@@ -1021,7 +1023,7 @@ subtest 'submit an update for a registered user, creating update by email' => su
is $update->user->email, 'registered@example.com', 'update email';
is $update->text, 'Update from a user', 'update text';
- $mech->get_ok( $url . $url_token );
+ $mech->get_ok( $url );
$mech->content_contains("/report/$report_id#update_$update_id");
# User should have new name and password
@@ -1514,8 +1516,6 @@ for my $test (
$mech->content_contains( 'Now check your email' );
- $mech->email_count_is(1);
-
my $results = { %{ $test->{fields} }, %{ $test->{changed} }, };
my $update = $report->comments->first;
@@ -1526,10 +1526,11 @@ for my $test (
is $update->anonymous, $test->{anonymous}, 'user anonymous';
my $email = $mech->get_email;
- ok $email, "got an email";
- like $email->body, qr/confirm your update on/i, "Correct email text";
+ my $body = $mech->get_text_body_from_email($email);
+ like $body, qr/confirm your update on/i, "Correct email text";
- my ( $url, $url_token ) = $email->body =~ m{(http://\S+/C/)(\S+)};
+ my $url = $mech->get_link_from_email($email);
+ my ($url_token) = $url =~ m{/C/(\S+)};
ok $url, "extracted confirm url '$url'";
my $token = FixMyStreet::App->model('DB::Token')->find(
diff --git a/t/app/helpers/emails/html_test.html b/t/app/helpers/emails/html_test.html
new file mode 100644
index 000000000..49f7b38d3
--- /dev/null
+++ b/t/app/helpers/emails/html_test.html
@@ -0,0 +1,15 @@
+Subject: test email ☺
+
+Hello,
+
+This is a test email where foo: [% foo %].
+
+utf8: 我们应该能够无缝处理UTF8编码
+
+ indented_text
+
+It additionally has an inline image!
+<img src="[% inline_image('t/app/helpers/grey.gif') %]">
+
+Yours,
+FixMyStreet.
diff --git a/t/app/helpers/emails/html_test.txt b/t/app/helpers/emails/html_test.txt
new file mode 100644
index 000000000..692d25ccf
--- /dev/null
+++ b/t/app/helpers/emails/html_test.txt
@@ -0,0 +1,14 @@
+Subject: test email ☺
+
+Hello,
+
+This is a test email where foo: [% foo %].
+
+utf8: 我们应该能够无缝处理UTF8编码
+
+ indented_text
+
+It additionally has an inline image!
+
+Yours,
+FixMyStreet.
diff --git a/t/app/helpers/emails/test.txt b/t/app/helpers/emails/test.txt
new file mode 100644
index 000000000..1acd4b6ca
--- /dev/null
+++ b/t/app/helpers/emails/test.txt
@@ -0,0 +1,14 @@
+Subject: test email ☺
+
+Hello,
+
+This is a test email where foo: [% foo %].
+
+utf8: 我们应该能够无缝处理UTF8编码
+
+ 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,
+FixMyStreet.
diff --git a/t/app/helpers/send_email.t b/t/app/helpers/send_email.t
index e2c8688a8..3975002fa 100644
--- a/t/app/helpers/send_email.t
+++ b/t/app/helpers/send_email.t
@@ -2,6 +2,12 @@ use strict;
use warnings;
use utf8;
+package FixMyStreet::Cobrand::Tester;
+use parent 'FixMyStreet::Cobrand::Default';
+sub path_to_email_templates { [ FixMyStreet->path_to( 't', 'app', 'helpers', 'emails') ] }
+
+package main;
+
BEGIN {
use FixMyStreet;
FixMyStreet->test_mode(1);
@@ -28,8 +34,12 @@ $c->stash->{foo} = 'bar';
Email::Send::Test->clear;
# send the test email
-ok $c->send_email( 'test.txt', { to => 'test@recipient.com' } ),
- "sent an email";
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'tester' ],
+}, sub {
+ ok $c->send_email( 'test.txt', { to => 'test@recipient.com' } ),
+ "sent an email";
+};
# check it got templated and sent correctly
my @emails = Email::Send::Test->emails;
@@ -51,9 +61,7 @@ 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;
- Email::Send::Test->clear;
- my @emails = Email::Send::Test->emails;
- is scalar(@emails), 0, "reset";
+ $mech->clear_emails_ok;
ok $c->send_email( 'test.txt',
{ to => 'test@recipient.com',
@@ -108,6 +116,20 @@ subtest 'MIME attachments' => sub {
$path->spew($email_as_string);
diag "Saved output in $path";
};
+ $mech->clear_emails_ok;
+};
+
+subtest 'Inline emails!' => sub {
+ ok $c->send_email( 'html_test.txt', { to => 'test@recipient.com' } ), "sent an email with email attachments";
+
+ my $email = $mech->get_email;
+ like $email->debug_structure, qr[
+ \+\ multipart/related.*\n
+ \ {5}\+\ multipart/alternative.*\n
+ \ {10}\+\ text/plain.*\n
+ \ {10}\+\ text/html.*\n
+ \ {5}\+\ image/gif]x;
+ $mech->clear_emails_ok;
};
done_testing;
diff --git a/t/app/model/alert_type.t b/t/app/model/alert_type.t
index e94ee8ce1..4e8817225 100644
--- a/t/app/model/alert_type.t
+++ b/t/app/model/alert_type.t
@@ -145,7 +145,7 @@ for my $test (
my @emails = $mech->get_email;
my $msg = $test->{msg};
for my $email (@emails) {
- my $body = $email->body;
+ my $body = $mech->get_text_body_from_email($email);
my $to = $email->header('To');
like $body, qr/$msg/, 'email says problem is ' . $test->{state};
@@ -193,9 +193,8 @@ subtest "correct text for title after URL" => sub {
FixMyStreet::DB->resultset('AlertType')->email_alerts();
};
- my $email = $mech->get_email;
(my $title = $report->title) =~ s/ /\\s+/;
- my $body = $email->body;
+ my $body = $mech->get_text_body_from_email;
like $body, qr#report/$report_id\s+-\s+$title#, 'email contains expected title';
};
@@ -330,8 +329,7 @@ foreach my $test (
FixMyStreet::DB->resultset('AlertType')->email_alerts();
};
- my $email = $mech->get_email;
- my $body = $email->body;
+ my $body = $mech->get_text_body_from_email;
if ( $test->{nearest} ) {
like $body, $test->{nearest}, 'correct nearest line';
@@ -439,8 +437,7 @@ subtest "check alerts from cobrand send main site url for alerts for different c
FixMyStreet::DB->resultset('AlertType')->email_alerts();
};
- my $email = $mech->get_email;
- my $body = $email->body;
+ my $body = $mech->get_text_body_from_email;
my $expected1 = FixMyStreet->config('BASE_URL') . '/report/' . $report_to_county_council->id;
my $expected3 = FixMyStreet->config('BASE_URL') . '/report/' . $report_outside_district->id;
@@ -476,8 +473,7 @@ subtest "check local alerts from cobrand send main site url for alerts for diffe
FixMyStreet::DB->resultset('AlertType')->email_alerts();
- my $email = $mech->get_email;
- my $body = $email->body;
+ my $body = $mech->get_text_body_from_email;
my $expected1 = FixMyStreet->config('BASE_URL') . '/report/' . $report_to_county_council->id;
my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('hart')->new();
@@ -505,9 +501,7 @@ subtest "correct i18n-ed summary for state of closed" => sub {
FixMyStreet::DB->resultset('AlertType')->email_alerts();
};
- $mech->email_count_is( 1 );
- my $email = $mech->get_email;
- my $body = $email->body;
+ my $body = $mech->get_text_body_from_email;
my $msg = 'Denne rapporten er for tiden markert som lukket';
like $body, qr/$msg/, 'email says problem is closed, in Norwegian';
};
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index ea45f7356..836e8a047 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -548,24 +548,25 @@ foreach my $test ( {
like $email->header('To'), $test->{ to }, 'to line looks correct';
is $email->header('From'), sprintf('"%s" <%s>', $test->{ name }, $test->{ email } ), 'from line looks correct';
like $email->header('Subject'), qr/A Title/, 'subject line looks correct';
- like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
- like $email->body, qr/Subject: A Title/, 'more email body checking';
- like $email->body, $test->{ dear }, 'Salutation looks correct';
+ my $body = $mech->get_text_body_from_email($email);
+ like $body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
+ like $body, qr/Subject: A Title/, 'more email body checking';
+ like $body, $test->{ dear }, 'Salutation looks correct';
if ($test->{longitude}) {
- like $email->body, qr{Easting/Northing \(IE\): 297279/362371};
+ like $body, qr{Easting/Northing \(IE\): 297279/362371};
} else {
- like $email->body, qr{Easting/Northing: };
+ like $body, qr{Easting/Northing: };
}
if ( $test->{multiple} ) {
- like $email->body, qr/This email has been sent to several councils /, 'multiple body text correct';
+ like $body, qr/This email has been sent to several councils /, 'multiple body text correct';
} elsif ( $test->{ missing } ) {
- like $email->body, $test->{ missing }, 'missing body information correct';
+ like $body, $test->{ missing }, 'missing body information correct';
}
if ( $test->{url} ) {
my $id = $problem->id;
- like $email->body, qr[$test->{url}fixmystreet.com/report/$id], 'URL present is correct';
+ like $body, qr[$test->{url}fixmystreet.com/report/$id], 'URL present is correct';
}
$problem->discard_changes;
@@ -655,16 +656,18 @@ subtest 'check can turn on report sent email alerts' => sub {
like $email->header('To'),qr/City of Edinburgh Council/, 'to line looks correct';
is $email->header('From'), '"Test User" <system_user@example.com>', 'from line looks correct';
like $email->header('Subject'), qr/A Title/, 'subject line looks correct';
- like $email->body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
- like $email->body, qr/Subject: A Title/, 'more email body checking';
- like $email->body, qr/Dear City of Edinburgh Council/, 'Salutation looks correct';
+ my $body = $mech->get_text_body_from_email($email);
+ like $body, qr/A user of FixMyStreet/, 'email body looks a bit like a report';
+ like $body, qr/Subject: A Title/, 'more email body checking';
+ like $body, qr/Dear City of Edinburgh Council/, 'Salutation looks correct';
$problem->discard_changes;
ok defined( $problem->whensent ), 'whensent set';
$email = $emails[1];
like $email->header('Subject'), qr/FixMyStreet Report Sent/, 'report sent email title correct';
- like $email->body, qr/to submit your report/, 'report sent body correct';
+ $body = $mech->get_text_body_from_email($email);
+ like $body, qr/to submit your report/, 'report sent body correct';
$send_confirmation_mail_override->restore();
};
diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t
index 6066c66b6..e39bcbe4c 100644
--- a/t/cobrand/bromley.t
+++ b/t/cobrand/bromley.t
@@ -103,10 +103,9 @@ for my $test (
};
$mech->content_contains('Nearly done! Now check your email');
- my $email = $mech->get_email;
- ok $email, "got an email";
- like $email->body, qr/This update will be sent to Bromley Council/i, "Email indicates problem will be sent to Bromley";
- unlike $email->body, qr/Note that we do not send updates to/i, "Email does not say updates aren't sent to Bromley";
+ my $body = $mech->get_text_body_from_email;
+ like $body, qr/This update will be sent to Bromley Council/i, "Email indicates problem will be sent to Bromley";
+ unlike $body, qr/Note that we do not send updates to/i, "Email does not say updates aren't sent to Bromley";
my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => 'unregistered@example.com' } );
diff --git a/t/cobrand/fixamingata.t b/t/cobrand/fixamingata.t
index 0cf7a31fe..2ef3c09b4 100644
--- a/t/cobrand/fixamingata.t
+++ b/t/cobrand/fixamingata.t
@@ -46,10 +46,11 @@ FixMyStreet::override_config {
FixMyStreet::DB->resultset('Problem')->send_reports();
};
my $email = $mech->get_email;
-like $email->header('Content-Type'), qr/utf-8/, 'encoding looks okay';
+my $plain = $mech->get_text_body_from_email($email, 1);
+like $plain->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_str, qr/V\xe4nligen,/, 'signature looks correct';
+like $plain->body_str, qr/V\xe4nligen,/, 'signature looks correct';
$mech->clear_emails_ok;
my $user =
@@ -89,10 +90,10 @@ FixMyStreet::override_config {
FixMyStreet::DB->resultset('AlertType')->email_alerts();
};
-$mech->email_count_is(1);
$email = $mech->get_email;
-like $email->header('Content-Type'), qr/utf-8/, 'encoding looks okay';
-like $email->body_str, qr/V\xe4nligen,/, 'signature looks correct';
+$plain = $mech->get_text_body_from_email($email, 1);
+like $plain->header('Content-Type'), qr/utf-8/, 'encoding looks okay';
+like $plain->body_str, qr/V\xe4nligen,/, 'signature looks correct';
$mech->clear_emails_ok;
subtest "Test ajax decimal points" => sub {