From 4f5c6d95c23f753cc1a0dae54d857451e2a30b6a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 18 Aug 2020 14:02:49 -0300 Subject: [PATCH] Bug 22343: Explicit testing of charset This patch tests content type and charset separatedly. This is done to avoid assuming the underlying library will always return the data structured in the same way, which is not to be guaranteed on the spec. This way the tests don't fail if things are ordered in another way, or if some more attributes are passed in the content type header (respecting the RFC for the format). Signed-off-by: Tomas Cohen Arazi --- t/Koha/Email.t | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/t/Koha/Email.t b/t/Koha/Email.t index b76959d99e..54b5cd126d 100644 --- a/t/Koha/Email.t +++ b/t/Koha/Email.t @@ -25,7 +25,7 @@ use_ok('Koha::Email'); subtest 'create() tests' => sub { - plan tests => 21; + plan tests => 23; t::lib::Mocks::mock_preference( 'SendAllEmailsTo', undef ); @@ -56,7 +56,8 @@ subtest 'create() tests' => sub { is( $email->email->header('Subject'), 'Some subject', 'Value set correctly' ); is( $email->email->header('X-Mailer'), 'Koha', 'Value set correctly' ); is( $email->email->body, $html_body, "Body set correctly" ); - is( $email->email->content_type, 'text/html; charset="utf-8"', "Content type set correctly"); + like( $email->email->content_type, qr|text/html|, "Content type set correctly"); + like( $email->email->content_type, qr|charset="utf-8"|, "Charset set correctly"); like( $email->email->header('Message-ID'), qr/\<.*@.*\>/, 'Value set correctly' ); t::lib::Mocks::mock_preference( 'SendAllEmailsTo', 'catchall@example.com' ); @@ -81,6 +82,7 @@ subtest 'create() tests' => sub { is( $email->email->header('ReplyTo'), 'replytodefault@example.com', 'ReplytoDefault picked when replyto not passed' ); is( $email->email->header('Sender'), 'returnpathdefault@example.com', 'ReturnpathDefault picked when sender not passed' ); is( $email->email->body, $text_body, "Body set correctly" ); - is( $email->email->content_type, 'text/plain; charset="utf-8"; format="flowed"', "Content type set correctly"); + like( $email->email->content_type, qr|text/plain|, "Content type set correctly"); + like( $email->email->content_type, qr|charset="utf-8"|, "Charset set correctly"); }; -- 2.28.0