From 894e15db266bc148092a011b414234e1cefec14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=CC=81s=CC=8C=20Br=CC=8Cec=CC=8Cka?= Date: Tue, 10 Apr 2018 10:03:46 +0200 Subject: [PATCH 1/2] Messages: allow to manage headers --- DotBlue/Mandrill/AbstractMessage.php | 20 +++++++++++++++++++ DotBlue/Mandrill/IBasicMessage.php | 6 ++++++ tests/DotBlueTests/Mandrill/MessageTest.phpt | 13 ++++++++++++ .../Mandrill/TemplateMessageTest.phpt | 13 ++++++++++++ 4 files changed, 52 insertions(+) diff --git a/DotBlue/Mandrill/AbstractMessage.php b/DotBlue/Mandrill/AbstractMessage.php index 4effce2..c0e6bab 100644 --- a/DotBlue/Mandrill/AbstractMessage.php +++ b/DotBlue/Mandrill/AbstractMessage.php @@ -405,4 +405,24 @@ public function removeImage(IAttachment $toBeRemoved) /** @var string[] */ public $metadata = []; + + + /** + * @return [] + */ + public function getHeaders() + { + return $this->headers; + } + + + /** + * @param string $header + * @param string $value + */ + public function addHeader($header, $value) + { + $this->headers[$header] = $value; + } + } diff --git a/DotBlue/Mandrill/IBasicMessage.php b/DotBlue/Mandrill/IBasicMessage.php index 6e4aa67..eaefc9f 100644 --- a/DotBlue/Mandrill/IBasicMessage.php +++ b/DotBlue/Mandrill/IBasicMessage.php @@ -55,6 +55,12 @@ function getMergeVars(); function getAttachments(); + /** + * @return [] + */ + function getHeaders(); + + /** * @return IAttachment[] */ diff --git a/tests/DotBlueTests/Mandrill/MessageTest.phpt b/tests/DotBlueTests/Mandrill/MessageTest.phpt index fcc3b7c..8919498 100644 --- a/tests/DotBlueTests/Mandrill/MessageTest.phpt +++ b/tests/DotBlueTests/Mandrill/MessageTest.phpt @@ -32,6 +32,19 @@ class MessageTest extends \Tester\TestCase Assert::same('HTML!', $message->getHtml()); Assert::same('HTML!', $message->getText()); } + + + public function testHeaders() + { + $message = new Message('dummy'); + $message->addHeader('header1', 'value1'); + $message->addHeader('header2', 'value2'); + + Assert::same([ + 'header1' => 'value1', + 'header2' => 'value2', + ], $message->getHeaders()); + } } (new MessageTest())->run(); diff --git a/tests/DotBlueTests/Mandrill/TemplateMessageTest.phpt b/tests/DotBlueTests/Mandrill/TemplateMessageTest.phpt index 5f5f73d..0c135ce 100644 --- a/tests/DotBlueTests/Mandrill/TemplateMessageTest.phpt +++ b/tests/DotBlueTests/Mandrill/TemplateMessageTest.phpt @@ -50,6 +50,19 @@ class TemplateMessageTest extends \Tester\TestCase 'secondRegion' => 'yabadabadooo', ], $message->getEditableRegions()); } + + + public function testHeaders() + { + $message = new TemplateMessage('dummy'); + $message->addHeader('header1', 'value1'); + $message->addHeader('header2', 'value2'); + + Assert::same([ + 'header1' => 'value1', + 'header2' => 'value2', + ], $message->getHeaders()); + } } (new TemplateMessageTest())->run(); From 8a989b8e3e9b1d4751e2f785a848b9fc2990a7aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=CC=81s=CC=8C=20Br=CC=8Cec=CC=8Cka?= Date: Tue, 10 Apr 2018 10:05:29 +0200 Subject: [PATCH 2/2] Exporters: export message headers --- DotBlue/Mandrill/Exporters/MessageExporter.php | 3 +++ tests/DotBlueTests/Mandrill/Exporters/MessageExporterTest.phpt | 2 ++ 2 files changed, 5 insertions(+) diff --git a/DotBlue/Mandrill/Exporters/MessageExporter.php b/DotBlue/Mandrill/Exporters/MessageExporter.php index 07cb200..595b137 100644 --- a/DotBlue/Mandrill/Exporters/MessageExporter.php +++ b/DotBlue/Mandrill/Exporters/MessageExporter.php @@ -72,6 +72,9 @@ private function exportMessage(\DotBlue\Mandrill\IBasicMessage $message) // Attachments 'attachments' => $this->exportAttachments($message->getAttachments()), 'images' => $this->exportAttachments($message->getImages()), + + // Headers + 'headers' => $message->getHeaders(), ], ]); } diff --git a/tests/DotBlueTests/Mandrill/Exporters/MessageExporterTest.phpt b/tests/DotBlueTests/Mandrill/Exporters/MessageExporterTest.phpt index fac60ce..ac63817 100644 --- a/tests/DotBlueTests/Mandrill/Exporters/MessageExporterTest.phpt +++ b/tests/DotBlueTests/Mandrill/Exporters/MessageExporterTest.phpt @@ -186,6 +186,8 @@ class MessageExporterTest extends \Tester\TestCase 'inline_css' => TRUE, 'preserve_recipients' => FALSE, + + 'headers' => [], ], 'async' => TRUE, 'ip_pool' => 'IP pool',