Ensure that only future events can be retrieved

This commit is contained in:
Oliver Davies 2019-01-18 21:44:21 +00:00
parent 306082d17b
commit fddaa56ed2
2 changed files with 30 additions and 8 deletions

View file

@ -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();
}
/**

View file

@ -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 */