diff --git a/app/src/Talk/TwigExtension/TalksExtension.php b/app/src/Talk/TwigExtension/TalksExtension.php index 5bedc97e..69755629 100644 --- a/app/src/Talk/TwigExtension/TalksExtension.php +++ b/app/src/Talk/TwigExtension/TalksExtension.php @@ -99,6 +99,8 @@ class TalksExtension extends AbstractExtension { return (new Collection($talks))->flatMap(function ($talk): array { return $talk['events']; + })->filter(function ($event): bool { + return !empty($event['date']); }); } } diff --git a/app/tests/Talk/TwigExtension/RetrievingEventsTest.php b/app/tests/Talk/TwigExtension/RetrievingEventsTest.php index 3160dc0d..b2af666a 100644 --- a/app/tests/Talk/TwigExtension/RetrievingEventsTest.php +++ b/app/tests/Talk/TwigExtension/RetrievingEventsTest.php @@ -57,4 +57,30 @@ class RetrievingEventsTest extends TestCase $this->assertCount(2, $events); } + + /** @test */ + public function events_with_no_date_are_not_returned() + { + $talks = [ + [ + 'title' => 'Deploying PHP applications with Ansible, Ansible Vault and Ansistrano', + 'events' => [ + [ + 'event' => 'php_south_wales', + 'date' => (new DateTime('-1 days'))->getTimestamp(), + ], + [ + 'event' => 'drupal_edinburgh', + 'date' => '', + ], + ], + ], + ]; + + $this->assertSame(1, $this->extension->getPastTalkCount($talks)); + + $pastEvents = $this->extension->getPastEvents($talks); + $this->assertCount(1, $pastEvents); + $this->assertSame('php_south_wales', $pastEvents[0]['event']); + } }