Also test which events are returned

This commit is contained in:
Oliver Davies 2017-11-01 19:57:41 +00:00
parent fff3ade8a0
commit 764c4b7d67

View file

@ -29,20 +29,23 @@ class FormatTalksTest extends PHPUnit_Framework_TestCase
$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' => [$eventA, $eventB]],
['events' => [$eventC]],
],
];
$results = $this->extension->getAll($data);
$this->assertCount(4, $results);
$this->assertCount(3, $results);
$this->assertEquals(
[$eventA['date'], $eventC['date'], $eventB['date']],
$this->extractDates($results)
);
}
/**
@ -60,13 +63,18 @@ class FormatTalksTest extends PHPUnit_Framework_TestCase
'events' => [],
'talks' => [
['events' => [$eventA, $eventC]],
['events' => [$eventB, $eventE]]
['events' => [$eventB, $eventE]],
],
];
$results = $this->extension->getUpcoming($data);
$this->assertCount(3, $results);
$this->assertEquals(
[$eventE['date'], $eventA['date'], $eventC['date']],
$this->extractDates($results)
);
}
/**
@ -78,18 +86,37 @@ class FormatTalksTest extends PHPUnit_Framework_TestCase
$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')];
$eventE = ['date' => (new DateTime('-2 days'))->format('Y-m-d')];
$eventF = ['date' => (new DateTime('-2 months'))->format('Y-m-d')];
$data = [
'events' => [],
'talks' => [
['events' => [$eventA, $eventD]],
['events' => [$eventA, $eventB, $eventC, $eventE]],
['events' => [$eventD]],
['events' => [$eventA, $eventB, $eventC]],
['events' => [$eventF]],
],
];
$results = $this->extension->getPast($data);
$this->assertCount(1, $results);
$this->assertCount(2, $results);
$this->assertEquals(
[$eventB['date'], $eventF['date']],
$this->extractDates($results)
);
}
/**
* Extract the returned dates from the results.
*
* @param array $results The results returned from the filter.
*
* @return array An array of dates.
*/
private function extractDates(array $results)
{
return collect($results)->pluck('event.date')->all();
}
}