From 3eefd65f7ce213a7facf443671fce504632c578c Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Thu, 24 Jul 2014 14:34:06 +1200 Subject: [PATCH] BUG: Narrowing site tree search to one date shows no pages It turns out that the search doesn't work if you put the same date into both start and end date. Adding time to the query seems to fix this issue. --- code/controllers/CMSSiteTreeFilter.php | 4 ++-- tests/controller/CMSSiteTreeFilterTest.php | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/code/controllers/CMSSiteTreeFilter.php b/code/controllers/CMSSiteTreeFilter.php index bac1a858..16944856 100644 --- a/code/controllers/CMSSiteTreeFilter.php +++ b/code/controllers/CMSSiteTreeFilter.php @@ -153,12 +153,12 @@ abstract class CMSSiteTreeFilter extends Object { case 'LastEditedFrom': $fromDate = new DateField(null, null, $val); - $query = $query->filter("LastEdited:GreaterThanOrEqual", $fromDate->dataValue()); + $query = $query->filter("LastEdited:GreaterThanOrEqual", $fromDate->dataValue().' 00:00:00'); break; case 'LastEditedTo': $toDate = new DateField(null, null, $val); - $query = $query->filter("LastEdited:LessThanOrEqual", $toDate->dataValue()); + $query = $query->filter("LastEdited:LessThanOrEqual", $toDate->dataValue().' 23:59:59'); break; case 'ClassName': diff --git a/tests/controller/CMSSiteTreeFilterTest.php b/tests/controller/CMSSiteTreeFilterTest.php index e364fcd3..fce3ca38 100644 --- a/tests/controller/CMSSiteTreeFilterTest.php +++ b/tests/controller/CMSSiteTreeFilterTest.php @@ -114,7 +114,19 @@ class CMSSiteTreeFilterTest extends SapphireTest { $f = new CMSSiteTreeFilter_StatusDraftPages(); $draftPage->delete(); $this->assertEmpty($f->isPageIncluded($draftPage)); - } + } + + public function testDateFromToLastSameDate() { + $draftPage = $this->objFromFixture('Page', 'page4'); + // Grab the date + $date = substr($draftPage->LastEdited, 0, 10); + // Filter with that date + $filter = New CMSSiteTreeFilter_Search(array( + 'LastEditedFrom' => $date, + 'LastEditedTo' => $date + )); + $this->assertTrue($filter->isPageIncluded($draftPage), 'Using the same date for from and to should show find that page'); + } public function testStatusRemovedFromDraftFilter() { $removedDraftPage = $this->objFromFixture('Page', 'page6');