Slim daily: minor bugfix with empty data

This commit is contained in:
ArthurHoaro 2020-05-17 11:29:17 +02:00
parent 07f99432b7
commit e3d28be967
2 changed files with 10 additions and 12 deletions

View file

@ -30,10 +30,13 @@ class DailyController extends ShaarliController
$nbAvailableDates = count($availableDates);
$index = array_search($day, $availableDates);
if ($index === false && $nbAvailableDates > 0) {
if ($index === false) {
// no bookmarks for day, but at least one day with bookmarks
$index = $nbAvailableDates - 1;
$day = $availableDates[$index];
$day = $availableDates[$nbAvailableDates - 1] ?? $day;
$previousDay = $availableDates[$nbAvailableDates - 2] ?? '';
} else {
$previousDay = $availableDates[$index - 1] ?? '';
$nextDay = $availableDates[$index + 1] ?? '';
}
if ($day === date('Ymd')) {
@ -42,15 +45,6 @@ class DailyController extends ShaarliController
$this->assignView('dayDesc', t('Yesterday'));
}
if ($index !== false) {
if ($index >= 1) {
$previousDay = $availableDates[$index - 1];
}
if ($index < $nbAvailableDates - 1) {
$nextDay = $availableDates[$index + 1];
}
}
try {
$linksToDisplay = $this->container->bookmarkService->filterDay($day);
} catch (\Exception $exc) {

View file

@ -112,6 +112,8 @@ class DailyControllerTest extends TestCase
'Daily - '. format_date($currentDay, false, true) .' - Shaarli',
$assignedVariables['pagetitle']
);
static::assertEquals($currentDay, $assignedVariables['dayDate']);
static::assertEquals($currentDay->getTimestamp(), $assignedVariables['day']);
static::assertCount(3, $assignedVariables['linksToDisplay']);
$link = $assignedVariables['linksToDisplay'][0];
@ -358,6 +360,8 @@ class DailyControllerTest extends TestCase
static::assertSame('daily', (string) $result->getBody());
static::assertCount(0, $assignedVariables['linksToDisplay']);
static::assertSame('Today', $assignedVariables['dayDesc']);
static::assertEquals((new \DateTime())->setTime(0, 0)->getTimestamp(), $assignedVariables['day']);
static::assertEquals((new \DateTime())->setTime(0, 0), $assignedVariables['dayDate']);
}
protected function createValidContainerMockSet(): void