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

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);
}
}
}