xref: /plugin/annotations/_test/GeneralTest.php (revision da56206cc13612db0df36be97c0f01d8f3c5e9f4)
1<?php
2
3namespace dokuwiki\plugin\annotations\test;
4
5use DokuWikiTest;
6
7/**
8 * General tests for the annotations plugin
9 *
10 * @group plugin_annotations
11 * @group plugins
12 */
13class GeneralTest extends DokuWikiTest
14{
15    /**
16     * Make sure plugin.info.txt is present and well-formed.
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('annotations', $info['base']);
34        $this->assertMatchesRegularExpression('/^https?:\/\//', $info['url']);
35        $this->assertMatchesRegularExpression('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
36        $this->assertTrue(false !== strtotime($info['date']));
37    }
38
39    /**
40     * Every $conf entry in conf/default.php must have a matching $meta entry in
41     * conf/metadata.php (and vice versa). The plugin currently ships no config,
42     * so this self-skips — it guards the invariant if config is added later.
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 conf/default.php and 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($key, $meta, 'Key $meta[\'' . $key . '\'] missing in conf/metadata.php');
69            }
70            foreach ($meta as $key => $value) {
71                $this->assertArrayHasKey($key, $conf, 'Key $conf[\'' . $key . '\'] missing in conf/default.php');
72            }
73        }
74    }
75}
76