Fix issue where the last mod timestamp of the sitemap index file wasnt using the most recently last edited timestamp, but the last item in the stack. Update test to check this, and include test for changeset bbd5e29

This commit is contained in:
Nick 2014-09-02 00:35:23 +12:00
parent e67f807f8a
commit 92bcb27cac
2 changed files with 27 additions and 10 deletions

View File

@ -283,11 +283,12 @@ class GoogleSitemap {
$neededForPage = ceil($count / $countPerFile);
for($i = 1; $i <= $neededForPage; $i++) {
$sliced = $instances
->limit($countPerFile, ($i - 1) * $countPerFile)
->last();
$lastModified = ($sliced) ? $sliced->dbObject('LastEdited')->Format('Y-m-d') : date('Y-m-d');
$lastEdited = $instances
->limit($countPerFile, ($i - 1) * $countPerFile)
->max('LastEdited');
$lastModified = ($lastEdited) ? date('Y-m-d', strtotime($lastEdited)) : date('Y-m-d');
$sitemaps->push(new ArrayData(array(
'ClassName' => 'SiteTree',

View File

@ -92,17 +92,29 @@ class GoogleSitemapTest extends FunctionalTest {
}
public function testLastModifiedDateOnRootXML() {
GoogleSitemap::register_dataobject("GoogleSitemapTest_DataObject");
Config::inst()->update('GoogleSitemap', 'enabled', true);
DB::query("
UPDATE GoogleSitemapTest_DataObject SET LastEdited = '2012-01-14'"
);
if(!class_exists('Page')) {
$this->markTestIncomplete('No cms module installed, page related test skipped');
}
$page = $this->objFromFixture('Page', 'Page1');
$page->publish('Stage', 'Live');
$page->flushCache();
$page2 = $this->objFromFixture('Page', 'Page2');
$page2->publish('Stage', 'Live');
$page2->flushCache();
DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-03-14 00:00:00' WHERE \"ID\"='".$page->ID."'");
DB::query("UPDATE \"SiteTree_Live\" SET \"LastEdited\"='2014-01-01 00:00:00' WHERE \"ID\"='".$page2->ID."'");
$response = $this->get('sitemap.xml');
$body = $response->getBody();
$expected = "<lastmod>2012-01-14</lastmod>";
$this->assertEquals(1, substr_count($body, $expected));
$expected = '<lastmod>2014-03-14</lastmod>';
$this->assertEquals(1, substr_count($body, $expected) , 'The last mod date should use most recent LastEdited date');
}
public function testIndexFilePaginatedSitemapFiles() {
@ -227,6 +239,10 @@ class GoogleSitemapTest extends FunctionalTest {
// invalid field doesn't break google
$page->Priority = 'foo';
$this->assertEquals(0.5, $page->getGooglePriority());
// custom value (set as string as db field is varchar)
$page->Priority = '0.2';
$this->assertEquals(0.2, $page->getGooglePriority());
// -1 indicates that we should not index this
$page->Priority = -1;