Ensure that only past events can be retrieved
This commit is contained in:
parent
303162e65d
commit
a48d748942
|
@ -78,11 +78,9 @@ class TalksExtension extends Twig_Extension
|
||||||
*/
|
*/
|
||||||
public function getPast($talks, array $eventData = [])
|
public function getPast($talks, array $eventData = [])
|
||||||
{
|
{
|
||||||
return $this->format($talks, $eventData)
|
return $this->getAll($talks)->filter(function ($talk) {
|
||||||
->filter(function ($talk) {
|
return collect($talk['events'])->pluck('date')->sort()->last() < $this->today;
|
||||||
return $talk['event']['date'] < $this->today;
|
});
|
||||||
})
|
|
||||||
->sortByDesc('event.date');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,9 +75,26 @@ class TalksExtensionTest extends TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function only_past_events_can_be_retrieved()
|
public function only_past_talks_can_be_retrieved()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$pastTalk = [
|
||||||
|
'title' => 'Past talk',
|
||||||
|
'events' => [
|
||||||
|
'date' => (new DateTime('-1 day'))->format(TalksExtension::DATE_FORMAT),
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$futureTalk = [
|
||||||
|
'title' => 'Future talk',
|
||||||
|
'events' => [
|
||||||
|
['date' => (new DateTime('+1 day'))->format(TalksExtension::DATE_FORMAT)],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$result = $this->extension->getPast([$pastTalk, $futureTalk]);
|
||||||
|
|
||||||
|
$this->assertCount(1, $result);
|
||||||
|
$this->assertSame($pastTalk, $result->first());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
Reference in a new issue