Add the Chronological

This commit is contained in:
2026-02-16 13:39:26 +01:00
parent c091ed1371
commit f1ac693fe8
162 changed files with 25868 additions and 1 deletions

138
_test/ChronoIDTest.php Normal file
View File

@@ -0,0 +1,138 @@
<?php
namespace dokuwiki\plugin\luxtools\test;
use dokuwiki\plugin\luxtools\ChronoID;
use DokuWikiTest;
require_once(__DIR__ . '/../autoload.php');
/**
* Chronological ID helper tests.
*
* @group plugin_luxtools
* @group plugins
*/
class ChronoIDTest extends DokuWikiTest
{
protected function assertBool(bool $expected, bool $actual, string $message): void
{
if ($expected !== $actual) {
throw new \Exception($message);
}
}
protected function assertStringOrNull(?string $expected, ?string $actual, string $message): void
{
if ($expected !== $actual) {
throw new \Exception($message . ' expected=' . var_export($expected, true) . ' actual=' . var_export($actual, true));
}
}
public function testIsIsoDateValidCases(): void
{
$valid = [
'2024-10-24',
'2024-02-29',
];
foreach ($valid as $date) {
$this->assertBool(true, ChronoID::isIsoDate($date), 'Expected valid ISO date: ' . $date);
}
}
public function testIsIsoDateInvalidCases(): void
{
$invalid = [
'2023-02-29',
'2024-13-01',
'2024-00-10',
'24-10-2024',
'2024/10/24',
'2024-10-24 12:00:00',
'2024-10-24T12:00:00',
'0000-01-01',
];
foreach ($invalid as $date) {
$this->assertBool(false, ChronoID::isIsoDate($date), 'Expected invalid ISO date: ' . $date);
}
}
public function testDateToDayId(): void
{
$this->assertStringOrNull('chronological:2024:10:24', ChronoID::dateToDayId('2024-10-24'), 'dateToDayId failed');
$this->assertStringOrNull('journal:chrono:2024:10:24', ChronoID::dateToDayId('2024-10-24', 'journal:chrono'), 'dateToDayId with custom namespace failed');
$this->assertStringOrNull(null, ChronoID::dateToDayId('2024-10-24T12:00:00'), 'datetime should be rejected');
$this->assertStringOrNull(null, ChronoID::dateToDayId('2024-13-01'), 'invalid month should be rejected');
$this->assertStringOrNull(null, ChronoID::dateToDayId('2024-10-24', ''), 'empty namespace should be rejected');
$this->assertStringOrNull(null, ChronoID::dateToDayId('2024-10-24', 'bad namespace!'), 'invalid namespace should be rejected');
}
public function testCanonicalIdChecks(): void
{
$this->assertBool(true, ChronoID::isDayId('chronological:2024:10:24'), 'valid day ID should be accepted');
$this->assertBool(true, ChronoID::isMonthId('chronological:2024:10'), 'valid month ID should be accepted');
$this->assertBool(true, ChronoID::isYearId('chronological:2024'), 'valid year ID should be accepted');
$this->assertBool(false, ChronoID::isDayId('2024:10:24'), 'missing namespace should be rejected as day ID');
$this->assertBool(false, ChronoID::isDayId('chronological:2024-10-24'), 'hyphen date in ID should be rejected as day ID');
$this->assertBool(false, ChronoID::isDayId('chronological:2023:02:29'), 'invalid Gregorian day should be rejected');
$this->assertBool(false, ChronoID::isMonthId('chronological:2024:13'), 'invalid month 13 should be rejected');
$this->assertBool(false, ChronoID::isMonthId('chronological:2024:00'), 'invalid month 00 should be rejected');
$this->assertBool(false, ChronoID::isMonthId('chronological:2024-10'), 'invalid month format should be rejected');
$this->assertBool(false, ChronoID::isYearId('chronological:0000'), 'year 0000 should be rejected');
$this->assertBool(false, ChronoID::isYearId('chronological:24'), 'short year should be rejected');
$this->assertBool(false, ChronoID::isYearId('chronological:2024:10'), 'month ID should not pass as year ID');
}
public function testConversions(): void
{
$this->assertStringOrNull('chronological:2024:10', ChronoID::dayIdToMonthId('chronological:2024:10:24'), 'dayIdToMonthId failed');
$this->assertStringOrNull('chronological:2024', ChronoID::monthIdToYearId('chronological:2024:10'), 'monthIdToYearId failed');
$this->assertStringOrNull(null, ChronoID::dayIdToMonthId('chronological:2024:13:24'), 'invalid day ID should map to null month ID');
$this->assertStringOrNull(null, ChronoID::dayIdToMonthId('chronological:2024:10'), 'month ID should not map via dayIdToMonthId');
$this->assertStringOrNull(null, ChronoID::monthIdToYearId('chronological:2024:13'), 'invalid month ID should map to null year ID');
$this->assertStringOrNull(null, ChronoID::monthIdToYearId('chronological:2024:10:24'), 'day ID should not map via monthIdToYearId');
}
/**
* Integration-style smoke test for canonical ID matrix acceptance/rejection.
*/
public function testCanonicalPageIdSmokeMatrix(): void
{
$accepted = [
['day', 'chronological:2024:10:24'],
['month', 'chronological:2024:10'],
['year', 'chronological:2024'],
];
foreach ($accepted as [$kind, $id]) {
if ($kind === 'day') {
$this->assertBool(true, ChronoID::isDayId($id), 'Expected accepted day ID: ' . $id);
} elseif ($kind === 'month') {
$this->assertBool(true, ChronoID::isMonthId($id), 'Expected accepted month ID: ' . $id);
} else {
$this->assertBool(true, ChronoID::isYearId($id), 'Expected accepted year ID: ' . $id);
}
}
$rejected = [
'2024:10:24',
'chronological:2024-10-24',
'chronological:2024:13:01',
'chronological:2024:00',
'chronological:0000',
];
foreach ($rejected as $id) {
$this->assertBool(false, ChronoID::isDayId($id), 'Unexpected day ID acceptance: ' . $id);
$this->assertBool(false, ChronoID::isMonthId($id), 'Unexpected month ID acceptance: ' . $id);
$this->assertBool(false, ChronoID::isYearId($id), 'Unexpected year ID acceptance: ' . $id);
}
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace dokuwiki\plugin\luxtools\test;
use dokuwiki\plugin\luxtools\ChronologicalDateAutoLinker;
use DokuWikiTest;
require_once(__DIR__ . '/../autoload.php');
/**
* Tests for extracted chronological auto-linker.
*
* @group plugin_luxtools
* @group plugins
*/
class ChronologicalDateAutoLinkerTest extends DokuWikiTest
{
public function testLinksPlainTextDate(): void
{
$html = '<p>Meeting on 2024-10-24</p>';
$out = ChronologicalDateAutoLinker::linkHtml($html);
$decoded = urldecode($out);
if (strpos($decoded, 'chronological:2024:10:24') === false) {
throw new \Exception('Expected canonical link target not found');
}
}
public function testSkipsCodeContent(): void
{
$html = '<p>Outside 2024-10-25</p><code>Inside 2024-10-24</code>';
$out = ChronologicalDateAutoLinker::linkHtml($html);
$decoded = urldecode($out);
if (strpos($decoded, 'chronological:2024:10:25') === false) {
throw new \Exception('Expected outside date link not found');
}
if (strpos($decoded, 'chronological:2024:10:24') !== false) {
throw new \Exception('Date inside code block should not be auto-linked');
}
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace dokuwiki\plugin\luxtools\test;
use dokuwiki\plugin\luxtools\ChronologicalDayTemplate;
use DokuWikiTest;
require_once(__DIR__ . '/../autoload.php');
/**
* Tests for German day template generation.
*
* @group plugin_luxtools
* @group plugins
*/
class ChronologicalDayTemplateTest extends DokuWikiTest
{
public function testBuildForDayIdGermanHeading(): void
{
$tpl = ChronologicalDayTemplate::buildForDayId('chronological:2026:02:13');
if (!is_string($tpl) || $tpl === '') {
throw new \Exception('Expected non-empty day template');
}
if (strpos($tpl, '====== Freitag, 13. Februar 2026 ======') === false) {
throw new \Exception('Expected German formatted heading not found');
}
}
public function testBuildForDayIdRejectsInvalid(): void
{
$tpl = ChronologicalDayTemplate::buildForDayId('chronological:2026:02');
if ($tpl !== null) {
throw new \Exception('Expected null for non-day ID');
}
}
}

View File

@@ -0,0 +1,222 @@
<?php
namespace dokuwiki\plugin\luxtools\test;
use dokuwiki\plugin\luxtools\ChronologicalIcsEvents;
use DokuWikiTest;
require_once(__DIR__ . '/../autoload.php');
/**
* Tests for local ICS event parsing.
*
* @group plugin_luxtools
* @group plugins
*/
class ChronologicalIcsEventsTest extends DokuWikiTest
{
public function testEventsForDateParsesAllDayAndTimedEntries(): void
{
$dir = TMP_DIR . '/chrono_ics/' . uniqid('case_', true);
@mkdir($dir, 0777, true);
$ics = $dir . '/calendar.ics';
$content = "BEGIN:VCALENDAR\n"
. "BEGIN:VEVENT\n"
. "DTSTART;VALUE=DATE:20260216\n"
. "SUMMARY:Ganztag Event\n"
. "END:VEVENT\n"
. "BEGIN:VEVENT\n"
. "DTSTART:20260216T134500\n"
. "SUMMARY:Termin A\n"
. "END:VEVENT\n"
. "BEGIN:VEVENT\n"
. "DTSTART:20260217T090000\n"
. "SUMMARY:Anderer Tag\n"
. "END:VEVENT\n"
. "END:VCALENDAR\n";
@file_put_contents($ics, $content);
$events = ChronologicalIcsEvents::eventsForDate($ics, '2026-02-16');
if (count($events) !== 2) {
throw new \Exception('Expected 2 events for 2026-02-16, got ' . count($events));
}
$summaries = array_map(static fn(array $e): string => (string)$e['summary'], $events);
if (!in_array('Ganztag Event', $summaries, true)) {
throw new \Exception('Missing all-day event summary');
}
if (!in_array('Termin A', $summaries, true)) {
throw new \Exception('Missing timed event summary');
}
$timed = null;
foreach ($events as $event) {
if ((string)($event['summary'] ?? '') === 'Termin A') {
$timed = $event;
break;
}
}
if (!is_array($timed)) {
throw new \Exception('Timed event payload missing');
}
if (trim((string)($timed['startIso'] ?? '')) === '') {
throw new \Exception('Timed event should expose startIso for client-side timezone conversion');
}
}
public function testEventsForDateReadsMultipleConfiguredFiles(): void
{
$dir = TMP_DIR . '/chrono_ics/' . uniqid('multi_', true);
@mkdir($dir, 0777, true);
$ics1 = $dir . '/one.ics';
$ics2 = $dir . '/two.ics';
@file_put_contents($ics1, "BEGIN:VCALENDAR\nBEGIN:VEVENT\nDTSTART:20260218T100000\nSUMMARY:Eins\nEND:VEVENT\nEND:VCALENDAR\n");
@file_put_contents($ics2, "BEGIN:VCALENDAR\nBEGIN:VEVENT\nDTSTART:20260218T110000\nSUMMARY:Zwei\nEND:VEVENT\nEND:VCALENDAR\n");
$config = $ics1 . "\n" . $ics2;
$events = ChronologicalIcsEvents::eventsForDate($config, '2026-02-18');
if (count($events) !== 2) {
throw new \Exception('Expected 2 events from two files, got ' . count($events));
}
}
public function testEventsForDateSupportsWeeklyRecurrence(): void
{
$dir = TMP_DIR . '/chrono_ics/' . uniqid('rrule_', true);
@mkdir($dir, 0777, true);
$ics = $dir . '/recurring.ics';
$content = "BEGIN:VCALENDAR\n"
. "BEGIN:VEVENT\n"
. "UID:weekly-1\n"
. "DTSTART:20260205T090000\n"
. "RRULE:FREQ=WEEKLY;INTERVAL=1\n"
. "SUMMARY:Wiederkehrender Termin\n"
. "END:VEVENT\n"
. "END:VCALENDAR\n";
@file_put_contents($ics, $content);
$events = ChronologicalIcsEvents::eventsForDate($ics, '2026-02-12');
if (count($events) < 1) {
throw new \Exception('Expected recurring event on 2026-02-12, got none');
}
$summaries = array_map(static fn(array $e): string => (string)$e['summary'], $events);
if (!in_array('Wiederkehrender Termin', $summaries, true)) {
throw new \Exception('Recurring summary not found on matching date');
}
}
public function testEventsForDateRespectsExdateForRecurringEvent(): void
{
$dir = TMP_DIR . '/chrono_ics/' . uniqid('exdate_', true);
@mkdir($dir, 0777, true);
$ics = $dir . '/recurring-exdate.ics';
$content = "BEGIN:VCALENDAR\n"
. "BEGIN:VEVENT\n"
. "UID:weekly-2\n"
. "DTSTART:20260205T090000\n"
. "RRULE:FREQ=WEEKLY;COUNT=4\n"
. "EXDATE:20260212T090000\n"
. "SUMMARY:Termin mit Ausnahme\n"
. "END:VEVENT\n"
. "END:VCALENDAR\n";
@file_put_contents($ics, $content);
$events = ChronologicalIcsEvents::eventsForDate($ics, '2026-02-12');
$summaries = array_map(static fn(array $e): string => (string)$e['summary'], $events);
if (in_array('Termin mit Ausnahme', $summaries, true)) {
throw new \Exception('Recurring event with EXDATE should not appear on excluded day');
}
}
public function testEventsForDateKeepsUtcDateAndTimeAsIs(): void
{
$previousTimezone = date_default_timezone_get();
date_default_timezone_set('Europe/Berlin');
try {
$dir = TMP_DIR . '/chrono_ics/' . uniqid('tz_', true);
@mkdir($dir, 0777, true);
$ics = $dir . '/timezone.ics';
$content = "BEGIN:VCALENDAR\n"
. "BEGIN:VEVENT\n"
. "UID:utc-shift\n"
. "DTSTART:20260216T233000Z\n"
. "SUMMARY:UTC Spaet\n"
. "END:VEVENT\n"
. "END:VCALENDAR\n";
@file_put_contents($ics, $content);
$eventsOn16 = ChronologicalIcsEvents::eventsForDate($ics, '2026-02-16');
$eventsOn17 = ChronologicalIcsEvents::eventsForDate($ics, '2026-02-17');
$summaries16 = array_map(static fn(array $e): string => (string)$e['summary'], $eventsOn16);
$summaries17 = array_map(static fn(array $e): string => (string)$e['summary'], $eventsOn17);
if (!in_array('UTC Spaet', $summaries16, true)) {
throw new \Exception('UTC event should stay on its own UTC date');
}
if (in_array('UTC Spaet', $summaries17, true)) {
throw new \Exception('UTC event should not be shifted to next day by server timezone');
}
$utcEvent = null;
foreach ($eventsOn16 as $entry) {
if ((string)($entry['summary'] ?? '') === 'UTC Spaet') {
$utcEvent = $entry;
break;
}
}
if (!is_array($utcEvent)) {
throw new \Exception('UTC event payload missing after day match');
}
if ((string)($utcEvent['time'] ?? '') !== '23:30') {
throw new \Exception('UTC event time should remain unchanged (expected 23:30)');
}
} finally {
date_default_timezone_set($previousTimezone);
}
}
public function testEventsForDateShowsMultiDayAllDayEventOnOverlappingDays(): void
{
$dir = TMP_DIR . '/chrono_ics/' . uniqid('multiday_', true);
@mkdir($dir, 0777, true);
$ics = $dir . '/multiday.ics';
$content = "BEGIN:VCALENDAR\n"
. "BEGIN:VEVENT\n"
. "UID:multi-day-1\n"
. "DTSTART;VALUE=DATE:20260216\n"
. "DTEND;VALUE=DATE:20260218\n"
. "SUMMARY:Mehrtagesereignis\n"
. "END:VEVENT\n"
. "END:VCALENDAR\n";
@file_put_contents($ics, $content);
$eventsOn16 = ChronologicalIcsEvents::eventsForDate($ics, '2026-02-16');
$eventsOn17 = ChronologicalIcsEvents::eventsForDate($ics, '2026-02-17');
$eventsOn18 = ChronologicalIcsEvents::eventsForDate($ics, '2026-02-18');
$summaries16 = array_map(static fn(array $e): string => (string)$e['summary'], $eventsOn16);
$summaries17 = array_map(static fn(array $e): string => (string)$e['summary'], $eventsOn17);
$summaries18 = array_map(static fn(array $e): string => (string)$e['summary'], $eventsOn18);
if (!in_array('Mehrtagesereignis', $summaries16, true)) {
throw new \Exception('Multi-day all-day event should appear on start day');
}
if (!in_array('Mehrtagesereignis', $summaries17, true)) {
throw new \Exception('Multi-day all-day event should appear on overlapping day');
}
if (in_array('Mehrtagesereignis', $summaries18, true)) {
throw new \Exception('Multi-day all-day event should respect exclusive DTEND day');
}
}
}

View File

@@ -404,4 +404,121 @@ class plugin_luxtools_test extends DokuWikiTest
// Directory row should trigger the same behaviour as {{open>...}} for that folder
$this->assertStringContainsString('data-path="/Scape/exampledir"', $xhtml);
}
/**
* Strict ISO dates in plain text should be auto-linked to canonical day IDs.
*/
public function test_auto_link_iso_date_plain_text()
{
$instructions = p_get_instructions('Meeting with John on 2024-10-24.');
$xhtml = p_render('xhtml', $instructions, $info);
if (strpos($xhtml, '>2024-10-24</a>') === false) {
throw new \Exception('Auto-link text for 2024-10-24 not found');
}
if (strpos(urldecode($xhtml), 'chronological:2024:10:24') === false) {
throw new \Exception('Auto-link target chronological:2024:10:24 not found');
}
}
/**
* Auto-linking must not run inside code blocks.
*/
public function test_auto_link_skips_code_blocks()
{
$syntax = 'Outside date 2024-10-25.' . "\n\n" . '<code>Inside code 2024-10-24</code>';
$instructions = p_get_instructions($syntax);
$xhtml = p_render('xhtml', $instructions, $info);
if (strpos($xhtml, '>2024-10-25</a>') === false) {
throw new \Exception('Outside date 2024-10-25 was not auto-linked');
}
if (strpos(urldecode($xhtml), 'chronological:2024:10:25') === false) {
throw new \Exception('Outside auto-link target chronological:2024:10:25 not found');
}
if (strpos(urldecode($xhtml), 'chronological:2024:10:24') !== false) {
throw new \Exception('Date inside code block was incorrectly auto-linked');
}
if (strpos($xhtml, 'Inside code 2024-10-24') === false) {
throw new \Exception('Code block content was unexpectedly altered');
}
}
/**
* Calendar widget should render links to canonical day IDs.
*/
public function test_calendar_widget_links_canonical_day_ids()
{
$instructions = p_get_instructions('{{calendar>2024-10}}');
$xhtml = p_render('xhtml', $instructions, $info);
if (strpos($xhtml, 'luxtools-calendar') === false) {
throw new \Exception('Calendar container not rendered');
}
$decoded = urldecode($xhtml);
if (strpos($decoded, 'chronological:2024:10:01') === false) {
throw new \Exception('Expected canonical day link for 2024-10-01 not found');
}
if (strpos($decoded, 'chronological:2024:10:31') === false) {
throw new \Exception('Expected canonical day link for 2024-10-31 not found');
}
if (strpos($decoded, 'chronological:2024:10') === false) {
throw new \Exception('Expected month link chronological:2024:10 not found in header');
}
if (strpos($decoded, 'chronological:2024') === false) {
throw new \Exception('Expected year link chronological:2024 not found in header');
}
if (strpos($decoded, 'chronological:2024:09') === false) {
throw new \Exception('Expected previous month canonical ID chronological:2024:09 not found');
}
if (strpos($decoded, 'chronological:2024:11') === false) {
throw new \Exception('Expected next month canonical ID chronological:2024:11 not found');
}
if (strpos($xhtml, 'luxtools-calendar-nav') === false) {
throw new \Exception('Calendar navigation container not rendered');
}
if (strpos($xhtml, 'luxtools-calendar-nav-button') === false) {
throw new \Exception('Calendar navigation buttons not rendered');
}
if (strpos($xhtml, 'data-luxtools-calendar="1"') === false) {
throw new \Exception('Calendar JS state attribute not rendered');
}
if (strpos($xhtml, 'data-luxtools-ajax-url=') === false) {
throw new \Exception('Calendar AJAX endpoint metadata not rendered');
}
if (strpos($xhtml, 'luxtools-calendar-day') === false || strpos($xhtml, '<td class="luxtools-calendar-day') === false) {
throw new \Exception('Calendar day cells not rendered as expected');
}
}
/**
* Empty calendar target should default to current month rendering.
*/
public function test_calendar_widget_defaults_to_current_month()
{
$instructions = p_get_instructions('{{calendar>}}');
$xhtml = p_render('xhtml', $instructions, $info);
if (strpos($xhtml, 'luxtools-calendar-table') === false) {
throw new \Exception('Calendar table not rendered for default month');
}
$today = date('Y-m-d');
$parts = explode('-', $today);
$expected = 'chronological:' . $parts[0] . ':' . $parts[1] . ':' . $parts[2];
if (strpos(urldecode($xhtml), $expected) === false) {
throw new \Exception('Expected canonical link for current date not found: ' . $expected);
}
}
}