This commit is contained in:
Oliver Davies 2025-06-11 09:46:17 +01:00
parent 3c4b053e0e
commit 4715d02ae0
2 changed files with 11 additions and 12 deletions

View file

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Drupal\opd_presentations\Functional\Entity; namespace Drupal\opd_presentations\Functional\Entity;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait; use Drupal\Tests\opd_presentations\Traits\PresentationCreationTrait;
use weitzman\DrupalTestTraits\ExistingSiteBase; use weitzman\DrupalTestTraits\ExistingSiteBase;
@ -15,9 +14,9 @@ final class PresentationTest extends ExistingSiteBase {
public function test_only_past_events_are_returned(): void { public function test_only_past_events_are_returned(): void {
$presentation = $this->createPresentation( $presentation = $this->createPresentation(
events: [ events: [
$this->createEvent(['field_date' => (new DrupalDateTime('now'))->getTimestamp()]), $this->createEvent(eventDate: 'now'),
$this->createEvent(['field_date' => (new DrupalDateTime('yesterday'))->getTimestamp()]), $this->createEvent(eventDate: 'yesterday'),
$this->createEvent(['field_date' => (new DrupalDateTime('tomorrow'))->getTimestamp()]), $this->createEvent(eventDate: 'tomorrow'),
], ],
); );

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Drupal\Tests\opd_presentations\Traits; namespace Drupal\Tests\opd_presentations\Traits;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\opd_presentations\Entity\Presentation; use Drupal\opd_presentations\Entity\Presentation;
use Drupal\paragraphs\Entity\Paragraph; use Drupal\paragraphs\Entity\Paragraph;
@ -27,14 +28,13 @@ trait PresentationCreationTrait {
return $presentation; return $presentation;
} }
/** private function createEvent(string $eventDate): ParagraphInterface {
* @param array<non-empty-string, mixed> $values return Paragraph::create(
*/ [
private function createEvent(array $values = []): ParagraphInterface { 'field_date' => (new DrupalDateTime($eventDate))->getTimestamp(),
return Paragraph::create(array_merge( 'type' => 'event',
['type' => 'event'], ],
$values, );
));
} }
} }