2019-01-18 18:06:31 +00:00
|
|
|
<?php
|
|
|
|
|
2019-09-30 17:33:28 +00:00
|
|
|
namespace App\Tests\Talk;
|
2019-01-18 18:06:31 +00:00
|
|
|
|
2019-10-24 23:07:02 +00:00
|
|
|
use App\Talk\TwigExtension\TalksExtension;
|
2019-04-14 07:23:57 +00:00
|
|
|
use DateTime;
|
2019-01-18 18:06:31 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-05-20 00:03:44 +00:00
|
|
|
use Tightenco\Collect\Support\Collection;
|
2019-01-18 18:06:31 +00:00
|
|
|
|
2019-05-20 07:25:31 +00:00
|
|
|
class RetrievingTalksTest extends TestCase
|
2019-01-18 18:06:31 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var TalksExtension
|
|
|
|
*/
|
|
|
|
private $extension;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2019-10-05 18:17:58 +00:00
|
|
|
public function setUp(): void
|
2019-01-18 18:06:31 +00:00
|
|
|
{
|
|
|
|
$this->extension = new TalksExtension();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function talks_given_multiple_times_are_only_returned_once()
|
|
|
|
{
|
2019-01-18 20:27:50 +00:00
|
|
|
$talkA = [
|
|
|
|
'title' => 'Talk A',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['event' => 'event_a', 'date' => (new DateTime('-1 days'))->getTimestamp()],
|
|
|
|
['event' => 'event_b', 'date' => (new DateTime('+1 days'))->getTimestamp()],
|
2019-01-18 20:27:50 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$talkB = [
|
|
|
|
'title' => 'Talk B',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['event' => 'event_a', 'date' => (new DateTime('-3 days'))->getTimestamp()],
|
2019-01-18 20:27:50 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2019-05-20 01:00:00 +00:00
|
|
|
$this->assertCount(2, $this->extension->getTalks([$talkA, $talkB]));
|
2019-01-18 18:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function talks_are_ordered_by_the_most_recent_event_date()
|
|
|
|
{
|
2019-01-18 20:38:58 +00:00
|
|
|
$talkA = [
|
|
|
|
'title' => 'Talk A',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['event' => 'event_a', 'date' => (new DateTime('-5 days'))->getTimestamp()],
|
2019-01-18 20:38:58 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$talkB = [
|
|
|
|
'title' => 'Talk B',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['event' => 'event_a', 'date' => (new DateTime('-20 days'))->getTimestamp()],
|
2019-01-18 20:38:58 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$talkC = [
|
|
|
|
'title' => 'Talk C',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['event' => 'event_a', 'date' => (new DateTime('-3 days'))->getTimestamp()],
|
|
|
|
['event' => 'event_b', 'date' => (new DateTime('-10 days'))->getTimestamp()],
|
2019-01-18 20:38:58 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$unorderedTalks = [$talkC, $talkA, $talkB];
|
2019-05-20 01:00:00 +00:00
|
|
|
$orderedTalks = $this->extension->getTalks($unorderedTalks);
|
2019-01-18 20:38:58 +00:00
|
|
|
|
|
|
|
$this->assertEquals([$talkC, $talkA, $talkB], $orderedTalks->toArray());
|
2019-01-18 18:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
2019-01-18 21:27:03 +00:00
|
|
|
public function only_past_talks_can_be_retrieved()
|
2019-01-18 18:06:31 +00:00
|
|
|
{
|
2019-01-18 21:27:03 +00:00
|
|
|
$pastTalk = [
|
|
|
|
'title' => 'Past talk',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['date' => (new DateTime('-1 day'))->getTimestamp()],
|
2019-01-18 21:27:03 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$futureTalk = [
|
|
|
|
'title' => 'Future talk',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['date' => (new DateTime('+1 day'))->getTimestamp()],
|
2019-01-18 21:27:03 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2019-05-20 01:00:00 +00:00
|
|
|
$talks = $this->extension->getTalks([$pastTalk, $futureTalk]);
|
2019-05-20 19:36:23 +00:00
|
|
|
$filtered = $this->extension->filterPastTalks($talks);
|
2019-01-18 21:27:03 +00:00
|
|
|
|
2019-05-20 00:58:36 +00:00
|
|
|
$this->assertCount(1, $filtered);
|
2019-09-27 00:51:32 +00:00
|
|
|
$this->assertSame($pastTalk, $filtered->first());
|
2019-01-18 18:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @test */
|
2019-01-18 21:44:21 +00:00
|
|
|
public function only_current_and_future_talks_can_be_retrieved()
|
2019-01-18 18:06:31 +00:00
|
|
|
{
|
2019-01-18 21:44:21 +00:00
|
|
|
$pastTalk = [
|
|
|
|
'title' => 'Past talk',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['date' => (new DateTime('-1 day'))->getTimestamp()],
|
2019-01-18 21:44:21 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
$todayTalk = [
|
|
|
|
'title' => 'A talk that it happening today',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['date' => (new DateTime('now'))->getTimestamp()],
|
2019-01-18 21:44:21 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$futureTalk = [
|
|
|
|
'title' => 'Future talk',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['date' => (new DateTime('+1 day'))->getTimestamp()],
|
2019-01-18 21:44:21 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2019-05-20 01:00:00 +00:00
|
|
|
$talks = $this->extension->getTalks([$pastTalk, $todayTalk, $futureTalk]);
|
2019-05-20 19:36:23 +00:00
|
|
|
$filtered = $this->extension->filterUpcomingTalks($talks);
|
2019-01-18 21:44:21 +00:00
|
|
|
|
2019-09-27 00:51:32 +00:00
|
|
|
$this->assertSame(2, $filtered->count());
|
|
|
|
$this->assertSame([$todayTalk, $futureTalk], $filtered->toArray());
|
2019-01-18 18:06:31 +00:00
|
|
|
}
|
2019-01-18 21:30:29 +00:00
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function if_a_talk_is_both_upcoming_and_past_then_it_is_only_shown_as_upcoming()
|
|
|
|
{
|
2019-01-18 22:04:53 +00:00
|
|
|
$talk = [
|
|
|
|
'title' => 'An upcoming talk that has been given before',
|
|
|
|
'events' => [
|
2019-02-13 06:55:18 +00:00
|
|
|
['date' => (new DateTime('-1 week'))->getTimestamp()],
|
|
|
|
['date' => (new DateTime('+1 week'))->getTimestamp()],
|
2019-01-18 22:04:53 +00:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2019-05-20 01:00:00 +00:00
|
|
|
$talks = $this->extension->getTalks([$talk]);
|
2019-05-20 00:58:36 +00:00
|
|
|
|
2019-05-20 19:36:23 +00:00
|
|
|
$this->assertCount(1, $this->extension->filterUpcomingTalks($talks));
|
|
|
|
$this->assertEmpty($this->extension->filterPastTalks($talks));
|
2019-01-18 21:30:29 +00:00
|
|
|
}
|
2019-05-19 23:58:36 +00:00
|
|
|
|
|
|
|
/** @test */
|
|
|
|
public function get_events_from_talks()
|
|
|
|
{
|
|
|
|
$talkA = [
|
|
|
|
'title' => 'Talk A',
|
|
|
|
'events' => [
|
|
|
|
['event' => 'event_a', 'date' => (new DateTime('-1 days'))->getTimestamp()],
|
|
|
|
['event' => 'event_b', 'date' => (new DateTime('+1 days'))->getTimestamp()],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
$talkB = [
|
|
|
|
'title' => 'Talk B',
|
|
|
|
'events' => [
|
|
|
|
['event' => 'event_a', 'date' => (new DateTime('-3 days'))->getTimestamp()],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2019-09-30 17:33:28 +00:00
|
|
|
$talks = new Collection([$talkA, $talkB]);
|
2019-10-16 13:58:23 +00:00
|
|
|
$events = $this->extension->getAllEvents($talks);
|
2019-05-20 00:05:59 +00:00
|
|
|
|
2019-10-16 13:58:23 +00:00
|
|
|
$this->assertCount(3, $events);
|
|
|
|
$this->assertSame(['event_a', 'event_b', 'event_a'], $events->pluck('event')->toArray());
|
|
|
|
$this->assertSame(3, $events->pluck('date')->unique()->count());
|
2019-05-19 23:58:36 +00:00
|
|
|
}
|
2019-01-18 18:06:31 +00:00
|
|
|
}
|