-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[9.x] Fix mails with tags and metadata are not queuable (#41028)
* fix: mails with tags and metadata could not be queued * test: add test cases for tags en metadata for mail * fix: mail could have multiple tags * style: fix issues from style linter * formatting Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information
1 parent
8e15796
commit 8ac224f
Showing
5 changed files
with
152 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -445,6 +445,48 @@ public function testMailablePriorityGetsSent() | |
$this->assertSame('[email protected]', $sentMessage->getEnvelope()->getRecipients()[0]->getAddress()); | ||
$this->assertStringContainsString('X-Priority: 1 (Highest)', $sentMessage->toString()); | ||
} | ||
|
||
public function testMailableMetadataGetsSent() | ||
{ | ||
$view = m::mock(Factory::class); | ||
|
||
$mailer = new Mailer('array', $view, new ArrayTransport); | ||
|
||
$mailable = new WelcomeMailableStub; | ||
$mailable->to('[email protected]'); | ||
$mailable->from('[email protected]'); | ||
$mailable->html('test content'); | ||
|
||
$mailable->metadata('origin', 'test-suite'); | ||
$mailable->metadata('user_id', 1); | ||
|
||
$sentMessage = $mailer->send($mailable); | ||
|
||
$this->assertSame('[email protected]', $sentMessage->getEnvelope()->getRecipients()[0]->getAddress()); | ||
$this->assertStringContainsString('X-Metadata-origin: test-suite', $sentMessage->toString()); | ||
$this->assertStringContainsString('X-Metadata-user_id: 1', $sentMessage->toString()); | ||
} | ||
|
||
public function testMailableTagGetsSent() | ||
{ | ||
$view = m::mock(Factory::class); | ||
|
||
$mailer = new Mailer('array', $view, new ArrayTransport); | ||
|
||
$mailable = new WelcomeMailableStub; | ||
$mailable->to('[email protected]'); | ||
$mailable->from('[email protected]'); | ||
$mailable->html('test content'); | ||
|
||
$mailable->tag('test'); | ||
$mailable->tag('foo'); | ||
|
||
$sentMessage = $mailer->send($mailable); | ||
|
||
$this->assertSame('[email protected]', $sentMessage->getEnvelope()->getRecipients()[0]->getAddress()); | ||
$this->assertStringContainsString('X-Tag: test', $sentMessage->toString()); | ||
$this->assertStringContainsString('X-Tag: foo', $sentMessage->toString()); | ||
} | ||
} | ||
|
||
class WelcomeMailableStub extends Mailable | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,26 @@ public function testReplyToIsSetCorrectly() | |
$this->assertSame([['[email protected]', null], ['[email protected]', 'Test']], $message->replyTo); | ||
} | ||
|
||
public function testMetadataIsSetCorrectly() | ||
{ | ||
$message = new MailMessage; | ||
$message->metadata('origin', 'test-suite'); | ||
$message->metadata('user_id', 1); | ||
|
||
$this->assertArrayHasKey('origin', $message->metadata); | ||
$this->assertSame('test-suite', $message->metadata['origin']); | ||
$this->assertArrayHasKey('user_id', $message->metadata); | ||
$this->assertSame(1, $message->metadata['user_id']); | ||
} | ||
|
||
public function testTagIsSetCorrectly() | ||
{ | ||
$message = new MailMessage; | ||
$message->tag('test'); | ||
|
||
$this->assertContains('test', $message->tags); | ||
} | ||
|
||
public function testCallbackIsSetCorrectly() | ||
{ | ||
$callback = function () { | ||
|