Add test for same day filter

This commit is contained in:
Jeremy Benoist 2015-08-23 22:06:27 +02:00
parent 7d6c3edcdd
commit f90af145ca
2 changed files with 14 additions and 5 deletions

View file

@ -8,7 +8,7 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
* This custom class override the default behavior of LexikFilterBundle on `filter_date_range` * This custom class override the default behavior of LexikFilterBundle on `filter_date_range`
* It converts a date_range to date_time_range to add hour to be able to grab a whole day (from 00:00:00 to 23:59:59) * It converts a date_range to date_time_range to add hour to be able to grab a whole day (from 00:00:00 to 23:59:59).
*/ */
class CustomDoctrineORMSubscriber extends DoctrineORMSubscriber implements EventSubscriberInterface class CustomDoctrineORMSubscriber extends DoctrineORMSubscriber implements EventSubscriberInterface
{ {
@ -22,12 +22,12 @@ class CustomDoctrineORMSubscriber extends DoctrineORMSubscriber implements Event
$value = $values['value']; $value = $values['value'];
// left date should start at midnight // left date should start at midnight
if (isset($value['left_date'][0]) && $value['left_date'][0] instanceOf \DateTime) { if (isset($value['left_date'][0]) && $value['left_date'][0] instanceof \DateTime) {
$value['left_date'][0]->setTime(0, 0, 0); $value['left_date'][0]->setTime(0, 0, 0);
} }
// right adte should end one second before midnight // right adte should end one second before midnight
if (isset($value['right_date'][0]) && $value['right_date'][0] instanceOf \DateTime) { if (isset($value['right_date'][0]) && $value['right_date'][0] instanceof \DateTime) {
$value['right_date'][0]->setTime(23, 59, 59); $value['right_date'][0]->setTime(23, 59, 59);
} }

View file

@ -278,6 +278,15 @@ class EntryControllerTest extends WallabagCoreTestCase
$this->assertCount(5, $crawler->filter('div[class=entry]')); $this->assertCount(5, $crawler->filter('div[class=entry]'));
$data = array(
'entry_filter[createdAt][left_date]' => date('d/m/Y'),
'entry_filter[createdAt][right_date]' => date('d/m/Y'),
);
$crawler = $client->submit($form, $data);
$this->assertCount(5, $crawler->filter('div[class=entry]'));
$data = array( $data = array(
'entry_filter[createdAt][left_date]' => '01/01/1970', 'entry_filter[createdAt][left_date]' => '01/01/1970',
'entry_filter[createdAt][right_date]' => '01/01/1970', 'entry_filter[createdAt][right_date]' => '01/01/1970',