Ensure that only future events can be retrieved
This commit is contained in:
parent
306082d17b
commit
fddaa56ed2
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue