From 5bc815a2b4956890230bb9318722c3ed069e6692 Mon Sep 17 00:00:00 2001 From: Dumazeau Date: Mon, 15 Jan 2024 16:41:06 +0100 Subject: [PATCH] Add OriginalToListHeader in Email when use bcc transformation modifier --- .github/workflows/tests.yml | 2 +- src/Domain/Header/OriginalToListHeader.php | 29 +++++++++++++++++++ .../Updater/BccTransformerEmailUpdater.php | 2 ++ tests/SendEmailTest.php | 12 ++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/Domain/Header/OriginalToListHeader.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1bdac33..491b367 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,7 +3,7 @@ on: [push, pull_request] jobs: build-and-test: - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 steps: - name: Checkout 🛎️ uses: actions/checkout@v2 diff --git a/src/Domain/Header/OriginalToListHeader.php b/src/Domain/Header/OriginalToListHeader.php new file mode 100644 index 0000000..fbfaad0 --- /dev/null +++ b/src/Domain/Header/OriginalToListHeader.php @@ -0,0 +1,29 @@ +toList = $toList; + + parent::__construct(self::NAME, ''); + } + + /** @return string[] */ + public function getToList(): array + { + return $this->toList; + } +} diff --git a/src/Domain/Updater/BccTransformerEmailUpdater.php b/src/Domain/Updater/BccTransformerEmailUpdater.php index de0836e..fbba423 100644 --- a/src/Domain/Updater/BccTransformerEmailUpdater.php +++ b/src/Domain/Updater/BccTransformerEmailUpdater.php @@ -4,6 +4,7 @@ namespace RichId\MailerBundle\Domain\Updater; +use RichId\MailerBundle\Domain\Header\OriginalToListHeader; use RichId\MailerBundle\Domain\Port\ConfigurationInterface; use RichId\MailerBundle\Domain\Port\TemplatingInterface; use RichId\MailerBundle\Infrastructure\DependencyInjection\Configuration; @@ -44,6 +45,7 @@ public function __invoke(Email $email): void ); $email->html($head . ($email->getHtmlBody() ?? '')); + $email->getHeaders()->add(new OriginalToListHeader($toList)); $email->to($bccAddress); $email->cc(); diff --git a/tests/SendEmailTest.php b/tests/SendEmailTest.php index 3c3592c..aa45a0e 100644 --- a/tests/SendEmailTest.php +++ b/tests/SendEmailTest.php @@ -7,6 +7,7 @@ use RichCongress\TestFramework\TestConfiguration\Annotation\TestConfig; use RichCongress\TestSuite\TestCase\TestCase; use RichId\MailerBundle\Domain\Email; +use RichId\MailerBundle\Domain\Header\OriginalToListHeader; use RichId\MailerBundle\Infrastructure\TestCase\MailerAssertionsTrait; use RichId\MailerBundle\Tests\Resources\Stub\ParameterBagStub; use Symfony\Component\Mailer\MailerInterface; @@ -70,6 +71,7 @@ public function testSendEmailMinimumConfiguration(): void self::assertEmpty($email->getCc()); self::assertEmpty($email->getBcc()); self::assertEmpty($email->getAttachments()); + self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME)); } public function testSendEmailWithReturnPath(): void @@ -96,6 +98,7 @@ public function testSendEmailWithReturnPath(): void self::assertEmpty($email->getCc()); self::assertEmpty($email->getBcc()); self::assertEmpty($email->getAttachments()); + self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME)); } public function testSendEmailWithBcc(): void @@ -122,6 +125,7 @@ public function testSendEmailWithBcc(): void self::assertNull($email->getReturnPath()); self::assertEmpty($email->getCc()); self::assertEmpty($email->getAttachments()); + self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME)); } public function testSendEmailWithYopmailTransformer(): void @@ -149,6 +153,7 @@ public function testSendEmailWithYopmailTransformer(): void self::assertNull($email->getReturnPath()); self::assertEmpty($email->getCc()); self::assertEmpty($email->getAttachments()); + self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME)); } public function testSendEmailWithBccTransformer(): void @@ -181,6 +186,10 @@ public function testSendEmailWithBccTransformer(): void self::assertNull($email->getReturnPath()); self::assertEmpty($email->getCc()); self::assertEmpty($email->getAttachments()); + + $originalToListHeader = $email->getHeaders()->get(OriginalToListHeader::NAME); + self::assertInstanceOf(OriginalToListHeader::class, $originalToListHeader); + self::assertSame(['test@test.test'], $originalToListHeader->getToList()); } public function testSendEmailWithSubjectPrefix(): void @@ -208,6 +217,7 @@ public function testSendEmailWithSubjectPrefix(): void self::assertEmpty($email->getCc()); self::assertEmpty($email->getBcc()); self::assertEmpty($email->getAttachments()); + self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME)); } public function testSendEmailWithFooter(): void @@ -229,6 +239,7 @@ public function testSendEmailWithFooter(): void self::assertEmpty($email->getCc()); self::assertEmpty($email->getBcc()); self::assertEmpty($email->getAttachments()); + self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME)); } public function testSendEmailWithFooterButDisabled(): void @@ -251,5 +262,6 @@ public function testSendEmailWithFooterButDisabled(): void self::assertEmpty($email->getCc()); self::assertEmpty($email->getBcc()); self::assertEmpty($email->getAttachments()); + self::assertNull($email->getHeaders()->get(OriginalToListHeader::NAME)); } }