feat: offer a newsletter opt-in for the other participants

addresses #869etn6c5
This commit is contained in:
fromme committed 2026-09-26 13:53:10 +02:00
1 parent 96b7b3f451
commit 876e69e62c
10 files changed
+598 -71

No files matched your search

+64 -9
View File
@@ -7,6 +7,7 @@ namespace App\Tests\Service;
use App\Email\Mailer;
use App\Entity\NewsletterConsent;
use App\Entity\NewsletterOptInRequest;
use App\Enum\NewsletterOptInContext;
use App\Exception\NewsletterListNotAllowedException;
use App\Mailjet\ApiClient;
use App\Model\NewsletterConfirmationResult;
@@ -16,7 +17,6 @@ use App\Repository\NewsletterOptInRequestRepository;
use App\Service\NewsletterManager;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
@@ -439,14 +439,69 @@ class NewsletterManagerTest extends TestCase
yield 'boolean' => [true];
}
/**
* @param MockObject&NewsletterOptInRequestRepository $repository
* @param MockObject&NewsletterConsentRepository $consents
* @param MockObject&EntityManagerInterface $entityManager
* @param MockObject&ApiClient $mailjet
* @param MockObject&Mailer $mailer
* @param array<int, string> $mailjetLists
*/
public function testRequestConfirmationUsesOwnWordingByDefault(): void
{
$repository = $this->createStub(NewsletterOptInRequestRepository::class);
$consents = $this->createStub(NewsletterConsentRepository::class);
$entityManager = $this->createStub(EntityManagerInterface::class);
$mailjet = $this->createStub(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$repository->method('deleteExpiredPendingByEmail')->willReturn(0);
$repository->method('findPendingByEmail')->willReturn(null);
$mailer
->expects(self::once())
->method('createAndSendEmail')
->with(
self::callback(static function (array $context): bool {
self::assertNull($context['requestedByName']);
return true;
}),
self::callback(static function (array $options): bool {
self::assertSame('Deine Anmeldung zum E&P Newsletter', $options['subject']);
self::assertSame('email/newsletter_opt_in.html.twig', $options['template']);
return true;
}),
);
$this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestConfirmation('[email protected]', 'Mia', 'Muster');
}
public function testRequestConfirmationUsesCompanionWordingAndNamesTheRequester(): void
{
$repository = $this->createStub(NewsletterOptInRequestRepository::class);
$consents = $this->createStub(NewsletterConsentRepository::class);
$entityManager = $this->createStub(EntityManagerInterface::class);
$mailjet = $this->createStub(ApiClient::class);
$mailer = $this->createMock(Mailer::class);
$repository->method('deleteExpiredPendingByEmail')->willReturn(0);
$repository->method('findPendingByEmail')->willReturn(null);
$mailer
->expects(self::once())
->method('createAndSendEmail')
->with(
self::callback(static function (array $context): bool {
self::assertSame('Tim', $context['recipientFirstName']);
self::assertSame('Mia Muster', $context['requestedByName']);
return true;
}),
self::callback(static function (array $options): bool {
self::assertSame('Möchtest du den E&P Newsletter erhalten?', $options['subject']);
self::assertSame('email/newsletter_opt_in_companion.html.twig', $options['template']);
return true;
}),
);
$this->createManager($repository, $consents, $entityManager, $mailjet, $mailer)
->requestConfirmation('[email protected]', 'Tim', 'Teiler', NewsletterOptInContext::Companion, 'Mia Muster');
}
private function createManager(
NewsletterOptInRequestRepository $repository,
NewsletterConsentRepository $consents,