57 lines
2.0 KiB
PHP
57 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Email;
|
|
|
|
use App\Email\Mailer;
|
|
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
|
|
|
/**
|
|
* What a mail carries for the transport it goes out over, built through the real template stack.
|
|
*/
|
|
class MailerTest extends KernelTestCase
|
|
{
|
|
/**
|
|
* Mailjet would otherwise track opens and rewrite links if the account is set to. Production
|
|
* sends every mail over Mailjet, whichever transport it names, so none may be tracked.
|
|
*/
|
|
#[\PHPUnit\Framework\Attributes\TestWith([Mailer::MAILJET_TRANSPORT])]
|
|
#[\PHPUnit\Framework\Attributes\TestWith([null])]
|
|
public function testNoMailIsTracked(?string $transport): void
|
|
{
|
|
$headers = $this->create($transport)->getHeaders();
|
|
|
|
$this->assertSame('0', $headers->get('X-Mailjet-TrackOpen')?->getBodyAsString());
|
|
$this->assertSame('0', $headers->get('X-Mailjet-TrackClick')?->getBodyAsString());
|
|
}
|
|
|
|
public function testOnlyTheVolumeMailNamesItsTransport(): void
|
|
{
|
|
$this->assertSame(Mailer::MAILJET_TRANSPORT, $this->create(Mailer::MAILJET_TRANSPORT)->getHeaders()->get('X-Transport')?->getBodyAsString());
|
|
$this->assertFalse($this->create(null)->getHeaders()->has('X-Transport'));
|
|
}
|
|
|
|
/**
|
|
* Mailer::create() takes the options as createAndSendEmail() has resolved them.
|
|
*/
|
|
private function create(?string $transport): TemplatedEmail
|
|
{
|
|
self::bootKernel();
|
|
|
|
return self::getContainer()->get(Mailer::class)->create(['travels' => []], [
|
|
'from' => '[email protected]',
|
|
'to' => '[email protected]',
|
|
'subject' => 'Betreff',
|
|
'subject_parameters' => [],
|
|
'template' => 'email/reminder_pending_feedback.html.twig',
|
|
'attachments' => [],
|
|
'transport' => $transport,
|
|
'bus_transport' => null,
|
|
'reply_to' => null,
|
|
'cc' => [],
|
|
]);
|
|
}
|
|
}
|