48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Entity;
|
|
|
|
use App\Entity\NewsletterConsent;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class NewsletterConsentTest extends TestCase
|
|
{
|
|
public function testConfirmationAndRevocationAreListScoped(): void
|
|
{
|
|
$consent = new NewsletterConsent(' [email protected] ', 123, ' Mia ', ' Muster ');
|
|
|
|
self::assertSame('[email protected]', $consent->getEmail());
|
|
self::assertSame(123, $consent->getMailjetListId());
|
|
self::assertSame('Mia', $consent->getFirstName());
|
|
self::assertSame('Muster', $consent->getLastName());
|
|
self::assertFalse($consent->isConfirmed());
|
|
|
|
$consent->markConfirmed(new \DateTimeImmutable('2026-04-29 10:00:00'), 'New', null);
|
|
|
|
self::assertTrue($consent->isConfirmed());
|
|
self::assertFalse($consent->isRevoked());
|
|
self::assertSame('New', $consent->getFirstName());
|
|
self::assertSame('Muster', $consent->getLastName());
|
|
|
|
$consent->markRevoked(new \DateTimeImmutable('2026-04-29 11:00:00'));
|
|
|
|
self::assertFalse($consent->isConfirmed());
|
|
self::assertTrue($consent->isRevoked());
|
|
|
|
$consent->markConfirmed(new \DateTimeImmutable('2026-04-29 12:00:00'));
|
|
|
|
self::assertTrue($consent->isConfirmed());
|
|
self::assertFalse($consent->isRevoked());
|
|
}
|
|
|
|
public function testRejectsInvalidMailjetListId(): void
|
|
{
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('Mailjet list ID must be a positive integer.');
|
|
|
|
new NewsletterConsent('[email protected]', 0);
|
|
}
|
|
}
|