From 08fc6c66be9e33e45934124a45e9af3cf5afd7d0 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 11 Jun 2025 09:54:18 +0100 Subject: [PATCH] Ensure the correct event is returned --- .../src/Collection/EventCollection.php | 4 +++ .../Functional/Entity/PresentationTest.php | 26 ++++++++++++++++--- .../src/Traits/PresentationCreationTrait.php | 3 ++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/modules/opd_presentations/src/Collection/EventCollection.php b/modules/opd_presentations/src/Collection/EventCollection.php index 2a4c62318..3cbf64a8e 100644 --- a/modules/opd_presentations/src/Collection/EventCollection.php +++ b/modules/opd_presentations/src/Collection/EventCollection.php @@ -17,6 +17,10 @@ readonly final class EventCollection implements \IteratorAggregate { public function __construct(private array $events) { } + public function first(): ParagraphInterface { + return array_values($this->events)[0]; + } + public function getIterator(): \Traversable { return new \ArrayIterator($this->events); } diff --git a/modules/opd_presentations/tests/src/Functional/Entity/PresentationTest.php b/modules/opd_presentations/tests/src/Functional/Entity/PresentationTest.php index a6f54ca00..c28902337 100644 --- a/modules/opd_presentations/tests/src/Functional/Entity/PresentationTest.php +++ b/modules/opd_presentations/tests/src/Functional/Entity/PresentationTest.php @@ -14,15 +14,33 @@ final class PresentationTest extends ExistingSiteBase { public function test_only_past_events_are_returned(): void { $presentation = $this->createPresentation( events: [ - $this->createEvent(eventDate: 'now'), - $this->createEvent(eventDate: 'yesterday'), - $this->createEvent(eventDate: 'tomorrow'), + $this->createEvent( + eventDate: 'now', + eventName: 'now', + ), + + $this->createEvent( + eventDate: 'yesterday', + eventName: 'yesterday', + ), + + $this->createEvent( + eventDate: 'tomorrow', + eventName: 'tomorrow', + ), ], ); + $events = $presentation->getPastEvents(); + $this->assertCount( expectedCount: 1, - haystack: $presentation->getPastEvents(), + haystack: $events, + ); + + $this->assertSame( + actual: $events->first()->get('field_event_name')->value, + expected: 'yesterday', ); } diff --git a/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php b/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php index 561c7681b..605309c07 100644 --- a/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php +++ b/modules/opd_presentations/tests/src/Traits/PresentationCreationTrait.php @@ -28,10 +28,11 @@ trait PresentationCreationTrait { return $presentation; } - private function createEvent(string $eventDate): ParagraphInterface { + private function createEvent(string $eventName, string $eventDate): ParagraphInterface { return Paragraph::create( [ 'field_date' => (new DrupalDateTime($eventDate))->getTimestamp(), + 'field_event_name' => $eventName, 'type' => 'event', ], );