Add FormatTalksBundle tests
This commit is contained in:
parent
73fb39cde5
commit
a2a4528116
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -12,3 +12,4 @@ publish.sh
|
||||||
*.pyc
|
*.pyc
|
||||||
deploy_key
|
deploy_key
|
||||||
deploy_key.pub
|
deploy_key.pub
|
||||||
|
phpunit.xml
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
"wikimedia/composer-merge-plugin": "^1.4"
|
"wikimedia/composer-merge-plugin": "^1.4"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"opdavies/sculpin-content-generator-bundle": "@stable"
|
"opdavies/sculpin-content-generator-bundle": "@stable",
|
||||||
|
"phpunit/phpunit": "^5.7",
|
||||||
|
"symfony/var-dumper": "^3.3"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"sort-packages": true
|
"sort-packages": true
|
||||||
|
|
1331
composer.lock
generated
1331
composer.lock
generated
File diff suppressed because it is too large
Load diff
11
phpunit.xml.dist
Normal file
11
phpunit.xml.dist
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit
|
||||||
|
colors="true"
|
||||||
|
stopOnFailure="true"
|
||||||
|
bootstrap="./vendor/autoload.php">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Bundles">
|
||||||
|
<directory>./tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
|
@ -13,13 +13,16 @@ class FormatTalksExtension extends Twig_Extension
|
||||||
*/
|
*/
|
||||||
private $today;
|
private $today;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->today = (new \DateTime())->format('Y-m-d');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getFilters()
|
public function getFilters()
|
||||||
{
|
{
|
||||||
$this->today = (new \DateTime())->format('Y-m-d');
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
new Twig_SimpleFilter('all_talks', [$this, 'getAll']),
|
new Twig_SimpleFilter('all_talks', [$this, 'getAll']),
|
||||||
new Twig_SimpleFilter('upcoming_talks', [$this, 'getUpcoming']),
|
new Twig_SimpleFilter('upcoming_talks', [$this, 'getUpcoming']),
|
||||||
|
@ -91,7 +94,7 @@ class FormatTalksExtension extends Twig_Extension
|
||||||
// event data (e.g. event name and website).
|
// event data (e.g. event name and website).
|
||||||
return collect($talk['events'])->map(function ($event) use ($talk, $events) {
|
return collect($talk['events'])->map(function ($event) use ($talk, $events) {
|
||||||
$event = collect($event);
|
$event = collect($event);
|
||||||
$event = $event->merge($events->get($event->get('event')));
|
$event = $event->merge($events->get($event->get('event')))->all();
|
||||||
|
|
||||||
return compact('event', 'talk');
|
return compact('event', 'talk');
|
||||||
});
|
});
|
||||||
|
|
95
tests/FormatTalksBundle/Twig/FormatTalksTest.php
Normal file
95
tests/FormatTalksBundle/Twig/FormatTalksTest.php
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace FormatTalksBundle\Tests\Twig;
|
||||||
|
|
||||||
|
use DateTime;
|
||||||
|
use FormatTalksBundle\Twig\FormatTalksExtension;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
|
class FormatTalksTest extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var FormatTalksExtension
|
||||||
|
*/
|
||||||
|
private $extension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->extension = new FormatTalksExtension();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getting all events.
|
||||||
|
*/
|
||||||
|
public function testGetAll()
|
||||||
|
{
|
||||||
|
$eventA = ['date' => (new DateTime('+1 week'))->format('Y-m-d')];
|
||||||
|
$eventB = ['date' => (new DateTime('-2 weeks'))->format('Y-m-d')];
|
||||||
|
$eventC = ['date' => (new DateTime('today'))->format('Y-m-d')];
|
||||||
|
$eventD = ['date' => (new DateTime('+1 day'))->format('Y-m-d')];
|
||||||
|
$eventE = ['date' => (new DateTime('+2 weeks'))->format('Y-m-d')];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'events' => [],
|
||||||
|
'talks' => [
|
||||||
|
['events' => [$eventA, $eventB, $eventE]],
|
||||||
|
['events' => [$eventC]],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$results = $this->extension->getAll($data);
|
||||||
|
|
||||||
|
$this->assertCount(4, $results);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getting only upcoming events.
|
||||||
|
*/
|
||||||
|
public function testUpcomingEventsFilter()
|
||||||
|
{
|
||||||
|
$eventA = ['date' => (new DateTime('+1 week'))->format('Y-m-d')];
|
||||||
|
$eventB = ['date' => (new DateTime('-2 weeks'))->format('Y-m-d')];
|
||||||
|
$eventC = ['date' => (new DateTime('today'))->format('Y-m-d')];
|
||||||
|
$eventD = ['date' => (new DateTime('+1 day'))->format('Y-m-d')];
|
||||||
|
$eventE = ['date' => (new DateTime('+2 weeks'))->format('Y-m-d')];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'events' => [],
|
||||||
|
'talks' => [
|
||||||
|
['events' => [$eventA, $eventC]],
|
||||||
|
['events' => [$eventB, $eventE]]
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$results = $this->extension->getUpcoming($data);
|
||||||
|
|
||||||
|
$this->assertCount(3, $results);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getting only past events.
|
||||||
|
*/
|
||||||
|
public function testPastFilter()
|
||||||
|
{
|
||||||
|
$eventA = ['date' => (new DateTime('+1 week'))->format('Y-m-d')];
|
||||||
|
$eventB = ['date' => (new DateTime('-2 weeks'))->format('Y-m-d')];
|
||||||
|
$eventC = ['date' => (new DateTime('today'))->format('Y-m-d')];
|
||||||
|
$eventD = ['date' => (new DateTime('+1 day'))->format('Y-m-d')];
|
||||||
|
$eventE = ['date' => (new DateTime('+2 weeks'))->format('Y-m-d')];
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'events' => [],
|
||||||
|
'talks' => [
|
||||||
|
['events' => [$eventA, $eventD]],
|
||||||
|
['events' => [$eventA, $eventB, $eventC, $eventE]],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$results = $this->extension->getPast($data);
|
||||||
|
|
||||||
|
$this->assertCount(1, $results);
|
||||||
|
}
|
||||||
|
}
|
Reference in a new issue