Skip to content
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

[10.x] Add test for Message ID, References and Custom Headers for Mailables #47791

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Changes from all commits
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
38 changes: 38 additions & 0 deletions tests/Mail/MailMailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Mail\Attachment;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailables\Headers;
use Illuminate\Mail\Mailer;
use Illuminate\Mail\Transport\ArrayTransport;
use Mockery as m;
Expand Down Expand Up @@ -1077,6 +1078,43 @@ public function build()
public function testAssertHasSubject()
{
}

public function testMailableHeadersGetSent()
{
$view = m::mock(Factory::class);

$mailer = new Mailer('array', $view, new ArrayTransport);

$mailable = new MailableHeadersStub;
$mailable->to('[email protected]');
$mailable->from('[email protected]');
$mailable->html('test content');

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

$this->assertSame('[email protected]', $sentMessage->getMessageId());

$this->assertTrue($sentMessage->getOriginalMessage()->getHeaders()->has('references'));
$this->assertEquals('References', $sentMessage->getOriginalMessage()->getHeaders()->get('references')->getName());
$this->assertEquals('<[email protected]>', $sentMessage->getOriginalMessage()->getHeaders()->get('references')->getValue());

$this->assertTrue($sentMessage->getOriginalMessage()->getHeaders()->has('x-custom-header'));
$this->assertEquals('X-Custom-Header', $sentMessage->getOriginalMessage()->getHeaders()->get('x-custom-header')->getName());
$this->assertEquals('Custom Value', $sentMessage->getOriginalMessage()->getHeaders()->get('x-custom-header')->getValue());
}

}

class MailableHeadersStub extends Mailable
{
public function headers()
{
return new Headers('[email protected]', [
'[email protected]',
], [
'X-Custom-Header' => 'Custom Value',
]);
}
}

class WelcomeMailableStub extends Mailable
Expand Down