8000 [9.x] Fix mails with tags and metadata are not queuable by joostdebruijn · Pull Request #41028 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[9.x] Fix mails with tags and metadata are not queuable #41028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: add test cases for tags en metadata for mail
  • Loading branch information
joostdebruijn committed Feb 15, 2022
commit bf32f80e4d0267b2bc4d5289416fbf7ca6e889fd
40 changes: 40 additions & 0 deletions tests/Mail/MailMailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,46 @@ public function testMailablePriorityGetsSent()
$this->assertSame('hello@laravel.com', $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('hello@laravel.com');
$mailable->from('taylor@laravel.com');
$mailable->html('test content');

$mailable->metadata('origin', 'test-suite');
$mailable->metadata('user_id', 1);

8000 $sentMessage = $mailer->send($mailable);

$this->assertSame('hello@laravel.com', $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('hello@laravel.com');
$mailable->from('taylor@laravel.com');
$mailable->html('test content');

$mailable->tag('test');

$sentMessage = $mailer->send($mailable);

$this->assertSame('hello@laravel.com', $sentMessage->getEnvelope()->getRecipients()[0]->getAddress());
$this->assertStringContainsString('X-Tag: test', $sentMessage->toString());
}
}

class WelcomeMailableStub extends Mailable
Expand Down
20 changes: 20 additions & 0 deletions tests/Notifications/NotificationMailMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ public function testReplyToIsSetCorrectly()
$this->assertSame([['test@example.com', null], ['test@example.com', '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->assertSame('test', $message->tag);
}

public function testCallbackIsSetCorrectly()
{
$callback = function () {
Expand Down
0