Give the feed of an empty site the current date.
The feed passed NULL to strtotime() when there were no stories.
This commit is contained in:
@@ -18,6 +18,8 @@ $query = "SELECT MAX(`date`) FROM $table;";
|
|||||||
$result = $db->query($query) or db_fail();
|
$result = $db->query($query) or db_fail();
|
||||||
$most_recent = $result->fetch_row();
|
$most_recent = $result->fetch_row();
|
||||||
$now = date("D, d M Y H:i:s O");
|
$now = date("D, d M Y H:i:s O");
|
||||||
|
// The date of the newest story, or now if there is none
|
||||||
|
$last_date = $most_recent[0] ? date("D, d M Y H:i:s O", strtotime($most_recent[0])) : $now;
|
||||||
|
|
||||||
echo '<?xml version="1.0"?>'."\n";
|
echo '<?xml version="1.0"?>'."\n";
|
||||||
echo '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">'."\n";
|
echo '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">'."\n";
|
||||||
@@ -27,14 +29,14 @@ echo '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom=
|
|||||||
echo '<description>Most recent articles from '.xml_text(site_host()).'</description>'."\n";
|
echo '<description>Most recent articles from '.xml_text(site_host()).'</description>'."\n";
|
||||||
echo '<language>en-za</language>'."\n";
|
echo '<language>en-za</language>'."\n";
|
||||||
echo '<pubDate>'.$now.'</pubDate>'."\n";
|
echo '<pubDate>'.$now.'</pubDate>'."\n";
|
||||||
echo '<lastBuildDate>'.date("D, d M Y H:i:s O", strtotime($most_recent[0])).'</lastBuildDate>'."\n";
|
echo '<lastBuildDate>'.$last_date.'</lastBuildDate>'."\n";
|
||||||
echo '<managingEditor>'.hidden_email(site_email('editor')).' (Editors)</managingEditor>'."\n";
|
echo '<managingEditor>'.hidden_email(site_email('editor')).' (Editors)</managingEditor>'."\n";
|
||||||
echo '<webMaster>'.hidden_email(site_email('webmaster')).' (Webmasters)</webMaster>'."\n";
|
echo '<webMaster>'.hidden_email(site_email('webmaster')).' (Webmasters)</webMaster>'."\n";
|
||||||
echo '<atom:link href="'.$site.'/feed" rel="self" type="application/rss+xml" />'."\n";
|
echo '<atom:link href="'.$site.'/feed" rel="self" type="application/rss+xml" />'."\n";
|
||||||
echo '<item>'."\n";
|
echo '<item>'."\n";
|
||||||
echo '<title>Front Page</title>'."\n";
|
echo '<title>Front Page</title>'."\n";
|
||||||
echo '<link>'.$site.'/</link>'."\n";
|
echo '<link>'.$site.'/</link>'."\n";
|
||||||
echo '<pubDate>'.date("D, d M Y H:i:s O", strtotime($most_recent[0])).'</pubDate>'."\n";
|
echo '<pubDate>'.$last_date.'</pubDate>'."\n";
|
||||||
echo '<guid>'.$site.'/</guid>'."\n";
|
echo '<guid>'.$site.'/</guid>'."\n";
|
||||||
echo '</item>'."\n";
|
echo '</item>'."\n";
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,17 @@ class FeedAndImageTest extends PageTestCase {
|
|||||||
$this->assertSame(date('D, d M Y H:i:s O', strtotime('2021-01-03 10:00:00')), (string)$xml->channel->lastBuildDate);
|
$this->assertSame(date('D, d M Y H:i:s O', strtotime('2021-01-03 10:00:00')), (string)$xml->channel->lastBuildDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Without stories, the feed dates are the time of the request
|
||||||
|
public function testTheFeedOfAnEmptySite(): void {
|
||||||
|
$this->setTables(array());
|
||||||
|
$xml = simplexml_load_string($this->get('/feed')['body']);
|
||||||
|
$this->assertNotFalse($xml);
|
||||||
|
$now = (string)$xml->channel->pubDate;
|
||||||
|
$this->assertSame($now, (string)$xml->channel->lastBuildDate);
|
||||||
|
$this->assertSame($now, (string)$xml->channel->item[0]->pubDate);
|
||||||
|
$this->assertCount(1, $xml->channel->item);
|
||||||
|
}
|
||||||
|
|
||||||
public function testAnImageIsServedWithItsRealType(): void {
|
public function testAnImageIsServedWithItsRealType(): void {
|
||||||
$image = $this->get('/display?id=2');
|
$image = $this->get('/display?id=2');
|
||||||
$this->assertSame(200, $image['status']);
|
$this->assertSame(200, $image['status']);
|
||||||
|
|||||||
Reference in New Issue
Block a user