This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
oliverdavies.uk-old-sculpin/app/tests/Talk/TwigExtension/RetrievingEventsTest.php

97 lines
2.6 KiB
PHP
Raw Normal View History

2019-05-20 07:28:28 +00:00
<?php
2019-10-24 23:07:02 +00:00
namespace App\Tests\Talk\TwigExtension;
2019-05-20 07:28:28 +00:00
2019-10-24 23:07:02 +00:00
use App\Talk\TwigExtension\TalksExtension;
2019-05-20 07:28:28 +00:00
use DateTime;
use PHPUnit\Framework\TestCase;
use Tightenco\Collect\Support\Collection;
class RetrievingEventsTest extends TestCase
{
/**
* @var TalksExtension
*/
private $extension;
/**
* {@inheritdoc}
*/
public function setUp(): void
2019-05-20 07:28:28 +00:00
{
$this->extension = new TalksExtension();
}
/** @test */
public function get_past_events()
{
$talkA = [
'title' => 'Test Driven Drupal',
'events' => [
[
'event' => 'php_south_wales',
'date' => (new DateTime('+1 days'))->getTimestamp(),
],
[
'event' => 'drupalcamp_london',
'date' => (new DateTime('-1 days'))->getTimestamp(),
],
],
];
$talkB = [
'title' => 'Taking Flight with Tailwind CSS',
'events' => [
[
'event' => 'blue_conf_2019',
'date' => (new DateTime('-2 days'))->getTimestamp(),
],
],
];
2019-12-27 12:42:05 +00:00
$talks = $this->extension->getAllTalks([$talkA, $talkB]);
2019-05-20 19:36:23 +00:00
$events = $this->extension->filterPastEvents($talks);
$this->assertInstanceOf(Collection::class, $talks);
2019-09-27 00:51:32 +00:00
$this->assertInstanceOf(Collection::class, $events);
2019-05-20 19:36:23 +00:00
$this->assertCount(2, $events);
}
/** @test */
public function get_current_or_upcoming_events()
{
$talkA = [
'title' => 'Test Driven Drupal',
'events' => [
[
'event' => 'php_south_wales',
'date' => (new DateTime('+0 days'))->getTimestamp(),
],
[
'event' => 'drupalcamp_london',
'date' => (new DateTime('-1 days'))->getTimestamp(),
],
],
];
$talkB = [
'title' => 'Taking Flight with Tailwind CSS',
'events' => [
[
'event' => 'blue_conf_2019',
'date' => (new DateTime('+2 days'))->getTimestamp(),
],
],
];
2019-12-27 12:42:05 +00:00
$talks = $this->extension->getAllTalks([$talkA, $talkB]);
2019-05-20 19:36:23 +00:00
$events = $this->extension->filterUpcomingEvents($talks);
$this->assertInstanceOf(Collection::class, $talks);
2019-09-27 00:51:32 +00:00
$this->assertInstanceOf(Collection::class, $events);
2019-05-20 19:36:23 +00:00
$this->assertCount(2, $events);
2019-05-20 07:28:28 +00:00
}
}