Refactor
This commit is contained in:
parent
413f5a889d
commit
75e7af85b5
3 changed files with 34 additions and 22 deletions
|
@ -3,13 +3,14 @@
|
|||
namespace Drupal\Tests\opd_daily_emails\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\RandomGeneratorTrait;
|
||||
use Drupal\Tests\opd_daily_emails\Traits\DailyEmailTestTrait;
|
||||
use Drupal\Tests\token\Functional\TokenTestTrait;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
class DailyEmailTokenTest extends BrowserTestBase {
|
||||
|
||||
use DailyEmailTestTrait;
|
||||
use RandomGeneratorTrait;
|
||||
use TokenTestTrait;
|
||||
|
||||
public $defaultTheme = 'stark';
|
||||
|
@ -20,9 +21,20 @@ class DailyEmailTokenTest extends BrowserTestBase {
|
|||
];
|
||||
|
||||
public function test_the_token_returns_the_number_of_sent_daily_emails(): void {
|
||||
$this->createDailyEmailNode(['status' => NodeInterface::PUBLISHED]);
|
||||
$this->createDailyEmailNode(['status' => NodeInterface::NOT_PUBLISHED]);
|
||||
$this->createDailyEmailNode(['status' => NodeInterface::PUBLISHED]);
|
||||
$this->createDailyEmailNode(
|
||||
isPublished: TRUE,
|
||||
title: $this->randomString(),
|
||||
);
|
||||
|
||||
$this->createDailyEmailNode(
|
||||
isPublished: FALSE,
|
||||
title: $this->randomString(),
|
||||
);
|
||||
|
||||
$this->createDailyEmailNode(
|
||||
isPublished: TRUE,
|
||||
title: $this->randomString(),
|
||||
);
|
||||
|
||||
$this->assertToken(
|
||||
data: [],
|
||||
|
|
|
@ -5,9 +5,7 @@ declare(strict_types=1);
|
|||
namespace Drupal\Tests\opd_daily_emails\Kernel;
|
||||
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
use Drupal\Tests\opd_daily_emails\Traits\DailyEmailTestTrait;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\opd_daily_emails\DailyEmailNodeRepository;
|
||||
use Drupal\opd_daily_emails\DailyEmailRepositoryInterface;
|
||||
|
||||
|
@ -21,15 +19,15 @@ final class DailyEmailNodeRepositoryTest extends EntityKernelTestBase {
|
|||
];
|
||||
|
||||
public function test_get_all_published_daily_emails(): void {
|
||||
$this->createDailyEmailNode([
|
||||
'status' => NodeInterface::PUBLISHED,
|
||||
'title' => 'A published daily email',
|
||||
]);
|
||||
$this->createDailyEmailNode(
|
||||
isPublished: TRUE,
|
||||
title: 'A published daily email',
|
||||
);
|
||||
|
||||
$this->createDailyEmailNode([
|
||||
'status' => NodeInterface::NOT_PUBLISHED,
|
||||
'title' => 'An unpublished daily email',
|
||||
]);
|
||||
$this->createDailyEmailNode(
|
||||
isPublished: FALSE,
|
||||
title: 'An unpublished daily email',
|
||||
);
|
||||
|
||||
$repository = $this->container->get(DailyEmailNodeRepository::class);
|
||||
assert($repository instanceof DailyEmailRepositoryInterface);
|
||||
|
|
|
@ -12,15 +12,17 @@ trait DailyEmailTestTrait {
|
|||
use NodeCreationTrait;
|
||||
|
||||
/**
|
||||
* @param array<non-empty-string, non-empty-string|int> $options
|
||||
* @param non-empty-string $title
|
||||
*/
|
||||
protected function createDailyEmailNode(array $options): NodeInterface {
|
||||
return $this->createNode(array_merge(
|
||||
$options,
|
||||
[
|
||||
'type' => 'daily_email',
|
||||
]
|
||||
));
|
||||
protected function createDailyEmailNode(
|
||||
string $title,
|
||||
bool $isPublished,
|
||||
): NodeInterface {
|
||||
return $this->createNode([
|
||||
'status' => $isPublished,
|
||||
'title' => $title,
|
||||
'type' => 'daily_email',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue