diff --git a/src/TalksBundle/TwigExtension/TalksExtension.php b/src/TalksBundle/TwigExtension/TalksExtension.php index ea381eb9..0bdee6dd 100644 --- a/src/TalksBundle/TwigExtension/TalksExtension.php +++ b/src/TalksBundle/TwigExtension/TalksExtension.php @@ -61,11 +61,9 @@ class TalksExtension extends Twig_Extension */ public function getUpcoming($talks, array $eventData = []) { - return $this->format($talks, $eventData) - ->filter(function ($talk) { - return $talk['event']['date'] >= $this->today; - }) - ->sortBy('event.date'); + return $this->getAll($talks)->filter(function ($talk) { + return collect($talk['events'])->pluck('date')->sort()->last() >= $this->today; + })->values(); } /** @@ -80,7 +78,7 @@ class TalksExtension extends Twig_Extension { return $this->getAll($talks)->filter(function ($talk) { return collect($talk['events'])->pluck('date')->sort()->last() < $this->today; - }); + })->values(); } /** diff --git a/tests/TalksBundle/TwigExtension/TalksExtensionTest.php b/tests/TalksBundle/TwigExtension/TalksExtensionTest.php index eb07025e..a1aece41 100644 --- a/tests/TalksBundle/TwigExtension/TalksExtensionTest.php +++ b/tests/TalksBundle/TwigExtension/TalksExtensionTest.php @@ -98,9 +98,33 @@ class TalksExtensionTest extends TestCase } /** @test */ - public function only_future_events_can_be_retrieved() + public function only_current_and_future_talks_can_be_retrieved() { - $this->markTestIncomplete(); + $pastTalk = [ + 'title' => 'Past talk', + 'events' => [ + 'date' => (new DateTime('-1 day'))->format(TalksExtension::DATE_FORMAT), + ] + ]; + + $todayTalk = [ + 'title' => 'A talk that it happening today', + 'events' => [ + ['date' => (new DateTime('now'))->format(TalksExtension::DATE_FORMAT)], + ], + ]; + + $futureTalk = [ + 'title' => 'Future talk', + 'events' => [ + ['date' => (new DateTime('+1 day'))->format(TalksExtension::DATE_FORMAT)], + ], + ]; + + $result = $this->extension->getUpcoming([$pastTalk, $todayTalk, $futureTalk]); + + $this->assertCount(2, $result); + $this->assertSame([$todayTalk, $futureTalk], $result->toArray()); } /** @test */