BUGFIX Using standard SQL and SSDatetime::now() in SideReport_RecentlyEdited (see #4052)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@83970 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-08-06 21:41:49 +00:00
parent b087ef99c5
commit cc65638ed9
3 changed files with 47 additions and 1 deletions

View File

@ -96,7 +96,8 @@ class SideReport_RecentlyEdited extends SideReport {
return _t('SideReport.LAST2WEEKS',"Pages edited in the last 2 weeks");
}
function records() {
return DataObject::get("SiteTree", "\"SiteTree\".\"LastEdited\" > " . DB::getConn()->now() . " - INTERVAL '14 DAY'", "\"SiteTree\".\"LastEdited\" DESC");
$threshold = strtotime('-14 days', SSDatetime::now()->Format('U'));
return DataObject::get("SiteTree", "\"SiteTree\".\"LastEdited\" > '".date("Y-m-d H:i:s", $threshold)."'", "\"SiteTree\".\"LastEdited\" DESC");
}
function fieldsToShow() {
return array(

40
tests/SideReportTest.php Normal file
View File

@ -0,0 +1,40 @@
<?php
/**
* @package cms
* @subpackage tests
*/
class SideReportTest extends SapphireTest {
static $fixture_file = 'cms/tests/SideReportTest.yml';
static $daysAgo = 14;
function setUp() {
parent::setUp();
// set the dates by hand: impossible to set via yml
$afterThreshold = strtotime('-'.(SideReportTest::$daysAgo-1).' days', strtotime('31-06-2009 00:00:00'));
$beforeThreshold = strtotime('-'.(SideReportTest::$daysAgo+1).' days', strtotime('31-06-2009 00:00:00'));
$after = $this->objFromFixture('SiteTree', 'after');
$before = $this->objFromFixture('SiteTree', 'before');
DB::query("UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='".date('Y-m-d H:i:s', $afterThreshold)."' WHERE \"ID\"='".$after->ID."'");
DB::query("UPDATE \"SiteTree\" SET \"Created\"='2009-01-01 00:00:00', \"LastEdited\"='".date('Y-m-d H:i:s', $beforeThreshold)."' WHERE \"ID\"='".$before->ID."'");
}
function testRecentlyEdited() {
SSDateTime::set_mock_now('31-06-2009 00:00:00');
$after = $this->objFromFixture('SiteTree', 'after');
$before = $this->objFromFixture('SiteTree', 'before');
$r = new SideReport_RecentlyEdited();
// check if contains only elements not older than $daysAgo days
$this->assertNotNull($r->records());
$this->assertContains($after->ID, $r->records()->column('ID'));
$this->assertNotContains($before->ID, $r->records()->column('ID'));
SSDateTime::clear_mock_now();
}
}

5
tests/SideReportTest.yml Normal file
View File

@ -0,0 +1,5 @@
SiteTree:
after:
Title: after
before:
Title: before