Ensure that talks given multiple times are only returned once

This commit is contained in:
Oliver Davies 2019-01-18 20:27:50 +00:00
parent 22b70033c5
commit 18e6d2e32f
2 changed files with 28 additions and 11 deletions

View file

@ -9,6 +9,8 @@ use Twig_SimpleFunction;
class TalksExtension extends Twig_Extension
{
const DATE_FORMAT = 'Y-m-d';
/**
* @var string The current date.
*/
@ -34,17 +36,17 @@ class TalksExtension extends Twig_Extension
];
}
/**
* Get all upcoming and previous talks.
*
* @param ProxySourceCollection|array $talks All talk nodes.
* @param array $eventData Shared event data.
*
* @return Collection A sorted collection of talks.
*/
public function getAll($talks, array $eventData = [])
/**
* Get all upcoming and previous talks.
*
* @param ProxySourceCollection|array $talks All talk nodes.
* @param array $eventData Shared event data.
*
* @return Collection A sorted collection of talks.
*/
public function getAll($talks, array $eventData = []): Collection
{
return $this->format($talks, $eventData)->sortBy('event.date');
return collect($talks);
}
/**

View file

@ -25,7 +25,22 @@ class TalksExtensionTest extends TestCase
/** @test */
public function talks_given_multiple_times_are_only_returned_once()
{
$this->markTestIncomplete();
$talkA = [
'title' => 'Talk A',
'events' => [
['event' => 'event_a', 'date' => (new DateTime('-1 days'))->format(TalksExtension::DATE_FORMAT)],
['event' => 'event_b', 'date' => (new DateTime('+1 days'))->format(TalksExtension::DATE_FORMAT)],
],
];
$talkB = [
'title' => 'Talk B',
'events' => [
['event' => 'event_a', 'date' => (new DateTime('-3 days'))->format(TalksExtension::DATE_FORMAT)],
],
];
$this->assertCount(2, $this->extension->getAll([$talkA, $talkB]));
}
/** @test */