Refactor
This commit is contained in:
parent
3c4b053e0e
commit
4715d02ae0
2 changed files with 11 additions and 12 deletions
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\opd_presentations\Functional\Entity;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait;
|
||||
use weitzman\DrupalTestTraits\ExistingSiteBase;
|
||||
|
||||
|
@ -15,9 +14,9 @@ final class PresentationTest extends ExistingSiteBase {
|
|||
public function test_only_past_events_are_returned(): void {
|
||||
$presentation = $this->createPresentation(
|
||||
events: [
|
||||
$this->createEvent(['field_date' => (new DrupalDateTime('now'))->getTimestamp()]),
|
||||
$this->createEvent(['field_date' => (new DrupalDateTime('yesterday'))->getTimestamp()]),
|
||||
$this->createEvent(['field_date' => (new DrupalDateTime('tomorrow'))->getTimestamp()]),
|
||||
$this->createEvent(eventDate: 'now'),
|
||||
$this->createEvent(eventDate: 'yesterday'),
|
||||
$this->createEvent(eventDate: 'tomorrow'),
|
||||
],
|
||||
);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Drupal\Tests\opd_presentations\Traits;
|
||||
|
||||
use Drupal\Core\Datetime\DrupalDateTime;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
use Drupal\opd_presentations\Entity\Presentation;
|
||||
use Drupal\paragraphs\Entity\Paragraph;
|
||||
|
@ -27,14 +28,13 @@ trait PresentationCreationTrait {
|
|||
return $presentation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<non-empty-string, mixed> $values
|
||||
*/
|
||||
private function createEvent(array $values = []): ParagraphInterface {
|
||||
return Paragraph::create(array_merge(
|
||||
['type' => 'event'],
|
||||
$values,
|
||||
));
|
||||
private function createEvent(string $eventDate): ParagraphInterface {
|
||||
return Paragraph::create(
|
||||
[
|
||||
'field_date' => (new DrupalDateTime($eventDate))->getTimestamp(),
|
||||
'type' => 'event',
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue