Ensure that talks are sorted by the nearest event date
This commit is contained in:
parent
18e6d2e32f
commit
303162e65d
|
@ -46,7 +46,9 @@ class TalksExtension extends Twig_Extension
|
||||||
*/
|
*/
|
||||||
public function getAll($talks, array $eventData = []): Collection
|
public function getAll($talks, array $eventData = []): Collection
|
||||||
{
|
{
|
||||||
return collect($talks);
|
return collect($talks)->sortBy(function ($talk) {
|
||||||
|
return collect($talk['events'])->pluck('date')->sort()->last();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,7 +46,32 @@ class TalksExtensionTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function talks_are_ordered_by_the_most_recent_event_date()
|
public function talks_are_ordered_by_the_most_recent_event_date()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
$talkA = [
|
||||||
|
'title' => 'Talk A',
|
||||||
|
'events' => [
|
||||||
|
['event' => 'event_a', 'date' => (new DateTime('-5 days'))->format(TalksExtension::DATE_FORMAT)],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$talkB = [
|
||||||
|
'title' => 'Talk B',
|
||||||
|
'events' => [
|
||||||
|
['event' => 'event_a', 'date' => (new DateTime('-20 days'))->format(TalksExtension::DATE_FORMAT)],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$talkC = [
|
||||||
|
'title' => 'Talk C',
|
||||||
|
'events' => [
|
||||||
|
['event' => 'event_a', 'date' => (new DateTime('-3 days'))->format(TalksExtension::DATE_FORMAT)],
|
||||||
|
['event' => 'event_b', 'date' => (new DateTime('-10 days'))->format(TalksExtension::DATE_FORMAT)],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$unorderedTalks = [$talkC, $talkA, $talkB];
|
||||||
|
$orderedTalks = $this->extension->getAll($unorderedTalks);
|
||||||
|
|
||||||
|
$this->assertEquals([$talkC, $talkA, $talkB], $orderedTalks->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
|
Loading…
Reference in a new issue