Show no date for a story without one.
Such a story showed the date of the story before it, or caused a warning when it came first.
This commit is contained in:
+4
-2
@@ -18,6 +18,7 @@ function display_stories($id = NULL) {
|
||||
$page = '';
|
||||
$nolink = NULL;
|
||||
$posted = FALSE;
|
||||
$date = '';
|
||||
|
||||
if ($action == 'preview') {
|
||||
global $file_src;
|
||||
@@ -65,8 +66,9 @@ searches the title, author, date, and the text of each article.</p>'."\n";
|
||||
$entry_id = (int)$entry['id'];
|
||||
$queue_url = $entry['queue_url'] ? 1 : 0;
|
||||
$title = h($entry['title']);
|
||||
$entry_date = $date;
|
||||
if ($entry['date'])
|
||||
$date = '<time datetime="'.date("Y-m-d\TH:i:sP", strtotime($entry['date'])).'">' .
|
||||
$entry_date = '<time datetime="'.date("Y-m-d\TH:i:sP", strtotime($entry['date'])).'">' .
|
||||
date("Y-m-d H:i", strtotime($entry['date'])) . '</time>';
|
||||
$page .= '<li class="box">';
|
||||
$page .= '<article>';
|
||||
@@ -90,7 +92,7 @@ date("Y-m-d H:i", strtotime($entry['date'])) . '</time>';
|
||||
if ($entry['hidden'])
|
||||
$page .= '<span class="right red">[hidden]</span>';
|
||||
$page .= '<dt class="author">By</dt> <dd class="author">' . h($entry['author']) . '</dd>';
|
||||
$page .= '<dt class="date">Posted</dt> <dd class="date">' . $date . '</dd>';
|
||||
$page .= '<dt class="date">Posted</dt> <dd class="date">' . $entry_date . '</dd>';
|
||||
$page .= '</dl>';
|
||||
if (isset($file_src)) {
|
||||
$page .= '<img src="'.h($file_src).'" alt="'.$title.'" />';
|
||||
|
||||
@@ -46,6 +46,19 @@ class DisplayStoriesTest extends TestCase {
|
||||
$this->assertStringContainsString('<time datetime="' . $datetime . '">2020-01-02 03:04</time>', $page);
|
||||
}
|
||||
|
||||
// A story without a date shows no date, not the date of the story before it
|
||||
public function testAStoryWithoutADateShowsNone(): void {
|
||||
SiteData::install(array('xxx' => array(
|
||||
array('id' => 1, 'title' => 'Dated', 'date' => '2020-01-02 03:04:05'),
|
||||
array('id' => 2, 'title' => 'Undated', 'date' => NULL),
|
||||
)));
|
||||
$GLOBALS['num_stories'] = 5;
|
||||
$page = display_stories();
|
||||
$this->assertSame(1, substr_count($page, '<time '));
|
||||
$this->assertStringContainsString('<dd class="date"></dd>', $page);
|
||||
$this->assertStringContainsString('<dd class="date"></dd>', display_stories('2'));
|
||||
}
|
||||
|
||||
public function testHiddenStoriesAreLeftOutForVisitors(): void {
|
||||
$this->assertStringNotContainsString('Picture', display_stories());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user