This commit is contained in:
Oliver Davies 2025-06-12 02:10:09 +01:00
parent 413f5a889d
commit 75e7af85b5
3 changed files with 34 additions and 22 deletions

View file

@ -3,13 +3,14 @@
namespace Drupal\Tests\opd_daily_emails\Functional; namespace Drupal\Tests\opd_daily_emails\Functional;
use Drupal\Tests\BrowserTestBase; use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\RandomGeneratorTrait;
use Drupal\Tests\opd_daily_emails\Traits\DailyEmailTestTrait; use Drupal\Tests\opd_daily_emails\Traits\DailyEmailTestTrait;
use Drupal\Tests\token\Functional\TokenTestTrait; use Drupal\Tests\token\Functional\TokenTestTrait;
use Drupal\node\NodeInterface;
class DailyEmailTokenTest extends BrowserTestBase { class DailyEmailTokenTest extends BrowserTestBase {
use DailyEmailTestTrait; use DailyEmailTestTrait;
use RandomGeneratorTrait;
use TokenTestTrait; use TokenTestTrait;
public $defaultTheme = 'stark'; public $defaultTheme = 'stark';
@ -20,9 +21,20 @@ class DailyEmailTokenTest extends BrowserTestBase {
]; ];
public function test_the_token_returns_the_number_of_sent_daily_emails(): void { public function test_the_token_returns_the_number_of_sent_daily_emails(): void {
$this->createDailyEmailNode(['status' => NodeInterface::PUBLISHED]); $this->createDailyEmailNode(
$this->createDailyEmailNode(['status' => NodeInterface::NOT_PUBLISHED]); isPublished: TRUE,
$this->createDailyEmailNode(['status' => NodeInterface::PUBLISHED]); title: $this->randomString(),
);
$this->createDailyEmailNode(
isPublished: FALSE,
title: $this->randomString(),
);
$this->createDailyEmailNode(
isPublished: TRUE,
title: $this->randomString(),
);
$this->assertToken( $this->assertToken(
data: [], data: [],

View file

@ -5,9 +5,7 @@ declare(strict_types=1);
namespace Drupal\Tests\opd_daily_emails\Kernel; namespace Drupal\Tests\opd_daily_emails\Kernel;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\opd_daily_emails\Traits\DailyEmailTestTrait; use Drupal\Tests\opd_daily_emails\Traits\DailyEmailTestTrait;
use Drupal\node\NodeInterface;
use Drupal\opd_daily_emails\DailyEmailNodeRepository; use Drupal\opd_daily_emails\DailyEmailNodeRepository;
use Drupal\opd_daily_emails\DailyEmailRepositoryInterface; use Drupal\opd_daily_emails\DailyEmailRepositoryInterface;
@ -21,15 +19,15 @@ final class DailyEmailNodeRepositoryTest extends EntityKernelTestBase {
]; ];
public function test_get_all_published_daily_emails(): void { public function test_get_all_published_daily_emails(): void {
$this->createDailyEmailNode([ $this->createDailyEmailNode(
'status' => NodeInterface::PUBLISHED, isPublished: TRUE,
'title' => 'A published daily email', title: 'A published daily email',
]); );
$this->createDailyEmailNode([ $this->createDailyEmailNode(
'status' => NodeInterface::NOT_PUBLISHED, isPublished: FALSE,
'title' => 'An unpublished daily email', title: 'An unpublished daily email',
]); );
$repository = $this->container->get(DailyEmailNodeRepository::class); $repository = $this->container->get(DailyEmailNodeRepository::class);
assert($repository instanceof DailyEmailRepositoryInterface); assert($repository instanceof DailyEmailRepositoryInterface);

View file

@ -12,15 +12,17 @@ trait DailyEmailTestTrait {
use NodeCreationTrait; use NodeCreationTrait;
/** /**
* @param array<non-empty-string, non-empty-string|int> $options * @param non-empty-string $title
*/ */
protected function createDailyEmailNode(array $options): NodeInterface { protected function createDailyEmailNode(
return $this->createNode(array_merge( string $title,
$options, bool $isPublished,
[ ): NodeInterface {
return $this->createNode([
'status' => $isPublished,
'title' => $title,
'type' => 'daily_email', 'type' => 'daily_email',
] ]);
));
} }
} }