diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2016-07-15 18:31:52 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2016-08-01 11:52:22 +0100 |
commit | 1820db45188fd62699223f63167c5f7250d1b7a6 (patch) | |
tree | 116814d9bb6ebd7f6fa015d3e492993b620ac6b1 /t/app/controller | |
parent | 0271c3fa016178f8c72b1192f1d0ed57437ec4c4 (diff) |
Add HTML email templates.
Design is all Zarino. This adds the ability to send HTML emails,
including attached inline images. When included, this is done as a
multipart/related email containing a multipart/alternative (of plain and
HTML) and any attached images, so that the images are available even if
HTML mail is not.
The alert emails list data has been improved so it can be constructed in
the templates rather than the code. Various templates have been tidied.
Various workarounds for email clients have been made, including:
* <th> is used so that the Android 4.x mail client can give them
`block` styling in the small screen media query.
* Font settings defined on every table cell (<th>) so that sans-serif
fonts are used in Outlook, rather than Times New Roman.
* A three-column wrapper table to create a 620px centred content area
that also shrinks down on narrow screens. (Outlook doesn’t like
max-width, so this is the simplest alternative.)
* Enforcing a sensible (500px) min-width for the main content area,
on clients that don’t support media queries (eg: native Gmail app).
* Giant borders on buttons so Outlook displays them
* Image alignment with align rather than float.
Diffstat (limited to 't/app/controller')
-rw-r--r-- | t/app/controller/alert_new.t | 75 | ||||
-rw-r--r-- | t/app/controller/auth.t | 19 | ||||
-rw-r--r-- | t/app/controller/auth_social.t | 12 | ||||
-rw-r--r-- | t/app/controller/contact.t | 8 | ||||
-rw-r--r-- | t/app/controller/moderate.t | 3 | ||||
-rw-r--r-- | t/app/controller/questionnaire.t | 28 | ||||
-rw-r--r-- | t/app/controller/report_import.t | 15 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 38 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 27 |
9 files changed, 95 insertions, 130 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( |