From c879bccfc8650372d3c9a93265caa38c40095dd0 Mon Sep 17 00:00:00 2001 From: Tim Geisendoerfer Date: Mon, 27 Nov 2023 13:41:01 +0100 Subject: [PATCH] Added test to verify overwriting of mail sender --- tests/MicrosoftGraphTransportTest.php | 91 ++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/tests/MicrosoftGraphTransportTest.php b/tests/MicrosoftGraphTransportTest.php index db7f6af..3192c5f 100644 --- a/tests/MicrosoftGraphTransportTest.php +++ b/tests/MicrosoftGraphTransportTest.php @@ -318,7 +318,7 @@ 'subject' => 'Dev Test', 'body' => [ 'contentType' => 'HTML', - 'content' => 'Test'.PHP_EOL, + 'content' => 'Test'.PHP_EOL, ], 'toRecipients' => [ [ @@ -372,3 +372,92 @@ return true; }); }); + +test('the configured mail sender can be overwritten', function () { + Config::set('mail.mailers.microsoft-graph', [ + 'transport' => 'microsoft-graph', + 'client_id' => 'foo_client_id', + 'client_secret' => 'foo_client_secret', + 'tenant_id' => 'foo_tenant_id', + 'from' => [ + 'address' => 'taylor@laravel.com', + 'name' => 'Taylor Otwell', + ], + ]); + Config::set('mail.default', 'microsoft-graph'); + + Cache::set('microsoft-graph-api-access-token', 'foo_access_token', 3600); + + Http::fake(); + + $mailable = new TestMail(false); + $mailable->from('other-mail@laravel.com', 'Other Mail'); + + Mail::to('caleb@livewire.com') + ->bcc('tim@innoge.de') + ->cc('nuno@laravel.com') + ->send($mailable); + + Http::assertSent(function (Request $value) { + expect($value) + ->url()->toBe('https://graph.microsoft.com/v1.0/users/taylor@laravel.com/sendMail') + ->hasHeader('Authorization', 'Bearer foo_access_token')->toBeTrue() + ->body()->json()->toBe([ + 'message' => [ + 'subject' => 'Dev Test', + 'body' => [ + 'contentType' => 'Text', + 'content' => 'Test'.PHP_EOL, + ], + 'toRecipients' => [ + [ + 'emailAddress' => [ + 'address' => 'caleb@livewire.com', + ], + ], + ], + 'ccRecipients' => [ + [ + 'emailAddress' => [ + 'address' => 'nuno@laravel.com', + ], + ], + ], + 'bccRecipients' => [ + [ + 'emailAddress' => [ + 'address' => 'tim@innoge.de', + ], + ], + ], + 'replyTo' => [], + 'sender' => [ + 'emailAddress' => [ + 'address' => 'other-mail@laravel.com', + ], + ], + 'attachments' => [ + [ + '@odata.type' => '#microsoft.graph.fileAttachment', + 'name' => 'test-file-1.txt', + 'contentType' => 'text', + 'contentBytes' => 'Zm9vCg==', + 'contentId' => 'test-file-1.txt', + 'isInline' => false, + ], + [ + '@odata.type' => '#microsoft.graph.fileAttachment', + 'name' => 'test-file-2.txt', + 'contentType' => 'text', + 'contentBytes' => 'Zm9vCg==', + 'contentId' => 'test-file-2.txt', + 'isInline' => false, + ], + ], + ], + 'saveToSentItems' => false, + ]); + + return true; + }); +});