Skip to content

Commit c13b196

Browse files
authored
Merge pull request dokufreaks#363 from dokufreaks/tests
Update Test Framework and fix strftime deprecations
2 parents 887d547 + 34bf252 commit c13b196

File tree

4 files changed

+103
-57
lines changed

4 files changed

+103
-57
lines changed

.github/workflows/dokuwiki.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: DokuWiki Default Tasks
2+
on:
3+
push:
4+
pull_request:
5+
schedule:
6+
- cron: '58 6 5 * *'
7+
8+
9+
jobs:
10+
all:
11+
uses: dokuwiki/github-action/.github/workflows/all.yml@main

.github/workflows/phpTestLinux.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

_test/GeneralTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace dokuwiki\plugin\include\test;
4+
5+
use DokuWikiTest;
6+
7+
/**
8+
* General tests for the include plugin
9+
*
10+
* @group plugin_include
11+
* @group plugins
12+
*/
13+
class GeneralTest extends DokuWikiTest
14+
{
15+
/**
16+
* Simple test to make sure the plugin.info.txt is in correct format
17+
*/
18+
public function testPluginInfo(): void
19+
{
20+
$file = __DIR__ . '/../plugin.info.txt';
21+
$this->assertFileExists($file);
22+
23+
$info = confToHash($file);
24+
25+
$this->assertArrayHasKey('base', $info);
26+
$this->assertArrayHasKey('author', $info);
27+
$this->assertArrayHasKey('email', $info);
28+
$this->assertArrayHasKey('date', $info);
29+
$this->assertArrayHasKey('name', $info);
30+
$this->assertArrayHasKey('desc', $info);
31+
$this->assertArrayHasKey('url', $info);
32+
33+
$this->assertEquals('include', $info['base']);
34+
$this->assertMatchesRegularExpression('/^https?:\/\//', $info['url']);
35+
$this->assertTrue(mail_isvalid($info['email']));
36+
$this->assertMatchesRegularExpression('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
37+
$this->assertTrue(false !== strtotime($info['date']));
38+
}
39+
40+
/**
41+
* Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
42+
* conf/metadata.php.
43+
*/
44+
public function testPluginConf(): void
45+
{
46+
$conf_file = __DIR__ . '/../conf/default.php';
47+
$meta_file = __DIR__ . '/../conf/metadata.php';
48+
49+
if (!file_exists($conf_file) && !file_exists($meta_file)) {
50+
self::markTestSkipped('No config files exist -> skipping test');
51+
}
52+
53+
if (file_exists($conf_file)) {
54+
include($conf_file);
55+
}
56+
if (file_exists($meta_file)) {
57+
include($meta_file);
58+
}
59+
60+
$this->assertEquals(
61+
gettype($conf),
62+
gettype($meta),
63+
'Both ' . DOKU_PLUGIN . 'include/conf/default.php and ' . DOKU_PLUGIN . 'include/conf/metadata.php have to exist and contain the same keys.'
64+
);
65+
66+
if ($conf !== null && $meta !== null) {
67+
foreach ($conf as $key => $value) {
68+
$this->assertArrayHasKey(
69+
$key,
70+
$meta,
71+
'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'include/conf/metadata.php'
72+
);
73+
}
74+
75+
foreach ($meta as $key => $value) {
76+
$this->assertArrayHasKey(
77+
$key,
78+
$conf,
79+
'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'include/conf/default.php'
80+
);
81+
}
82+
}
83+
}
84+
}

syntax/footer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class syntax_plugin_include_footer extends DokuWiki_Syntax_Plugin {
1111
function getType() {
1212
return 'formatting';
1313
}
14-
14+
1515
function getSort() {
1616
return 300;
1717
}
@@ -22,14 +22,14 @@ function handle($match, $state, $pos, Doku_Handler $handler) {
2222

2323
/**
2424
* Renders a permalink header.
25-
*
25+
*
2626
* Code heavily copied from the header renderer from inc/parser/xhtml.php, just
2727
* added an href parameter to the anchor tag linking to the wikilink.
2828
*/
2929
function render($mode, Doku_Renderer $renderer, $data) {
3030

3131
list($page, $sect, $sect_title, $flags, $redirect_id, $footer_lvl) = $data;
32-
32+
3333
if ($mode == 'xhtml') {
3434
$renderer->doc .= $this->html_footer($page, $sect, $sect_title, $flags, $footer_lvl, $renderer);
3535
return true;
@@ -72,18 +72,18 @@ function html_footer($page, $sect, $sect_title, $flags, $footer_lvl, &$renderer)
7272
if ($flags['date'] && $exists) {
7373
$date = $meta['date']['created'];
7474
if ($date) {
75-
$xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $date).'">'
76-
. strftime($conf['dformat'], $date)
75+
$xhtml[] = '<abbr class="published" title="'.dformat($date, '%Y-%m-%dT%H:%M:%SZ').'">'
76+
. dformat($date)
7777
. '</abbr>';
7878
}
7979
}
80-
80+
8181
// modified date
8282
if ($flags['mdate'] && $exists) {
8383
$mdate = $meta['date']['modified'];
8484
if ($mdate) {
85-
$xhtml[] = '<abbr class="published" title="'.strftime('%Y-%m-%dT%H:%M:%SZ', $mdate).'">'
86-
. strftime($conf['dformat'], $mdate)
85+
$xhtml[] = '<abbr class="published" title="'.dformat($mdate, '%Y-%m-%dT%H:%M:%SZ').'">'
86+
. dformat($mdate)
8787
. '</abbr>';
8888
}
8989
}

0 commit comments

Comments
 (0)