Create and use DailyEmailTestTrait
This commit is contained in:
parent
37e0964b53
commit
88ec3d9e51
3 changed files with 29 additions and 17 deletions
|
@ -3,14 +3,13 @@
|
|||
namespace Drupal\Tests\opd_daily_emails\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
use Drupal\Tests\opd_daily_emails\Traits\DailyEmailTestTrait;
|
||||
use Drupal\Tests\token\Functional\TokenTestTrait;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class DailyEmailTokenTest extends BrowserTestBase {
|
||||
|
||||
use NodeCreationTrait;
|
||||
use DailyEmailTestTrait;
|
||||
use TokenTestTrait;
|
||||
|
||||
public $defaultTheme = 'stark';
|
||||
|
@ -33,13 +32,4 @@ class DailyEmailTokenTest extends BrowserTestBase {
|
|||
);
|
||||
}
|
||||
|
||||
private function createDailyEmailNode(array $options): NodeInterface {
|
||||
return $this->createNode(array_merge(
|
||||
$options,
|
||||
[
|
||||
'type' => 'daily_email',
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,13 +6,14 @@ namespace Drupal\Tests\opd_daily_emails\Kernel\Repository;
|
|||
|
||||
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\Repository\DailyEmailNodeRepository;
|
||||
use Drupal\opd_daily_emails\Repository\DailyEmailRepositoryInterface;
|
||||
|
||||
final class DailyEmailNodeRepositoryTest extends EntityKernelTestBase {
|
||||
|
||||
use NodeCreationTrait;
|
||||
use DailyEmailTestTrait;
|
||||
|
||||
public static $modules = [
|
||||
'node',
|
||||
|
@ -20,16 +21,14 @@ final class DailyEmailNodeRepositoryTest extends EntityKernelTestBase {
|
|||
];
|
||||
|
||||
public function test_get_all_published_daily_emails(): void {
|
||||
$this->createNode([
|
||||
$this->createDailyEmailNode([
|
||||
'status' => NodeInterface::PUBLISHED,
|
||||
'title' => 'A published daily email',
|
||||
'type' => 'daily_email',
|
||||
]);
|
||||
|
||||
$this->createNode([
|
||||
$this->createDailyEmailNode([
|
||||
'status' => NodeInterface::NOT_PUBLISHED,
|
||||
'title' => 'An unpublished daily email',
|
||||
'type' => 'daily_email',
|
||||
]);
|
||||
|
||||
$repository = $this->container->get(DailyEmailNodeRepository::class);
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\Tests\opd_daily_emails\Traits;
|
||||
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
trait DailyEmailTestTrait {
|
||||
|
||||
use NodeCreationTrait;
|
||||
|
||||
protected function createDailyEmailNode(array $options): NodeInterface {
|
||||
return $this->createNode(array_merge(
|
||||
$options,
|
||||
[
|
||||
'type' => 'daily_email',
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue