xref: /plugin/dwtimeline/_test/GeneralTest.php (revision 545c554be65100e9bb5eff6d4aa54c829680442a)
1<?php
2
3namespace dokuwiki\plugin\dwtimeline\test;
4
5use DokuWikiTest;
6
7/**
8 * General tests for the dwtimeline plugin
9 *
10 * @group plugin_dwtimeline
11 * @group plugins
12 */
13class 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('dwtimeline', $info['base']);
34        $this->assertRegExp('/^https?:\/\//', $info['url']);
35        $this->assertTrue(mail_isvalid($info['email']));
36        $this->assertRegExp('/^\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 . 'dwtimeline/conf/default.php and ' .
64            DOKU_PLUGIN . 'dwtimeline/conf/metadata.php have to exist and contain the same keys.'
65        );
66
67        if ($conf !== null && $meta !== null) {
68            foreach ($conf as $key => $value) {
69                $this->assertArrayHasKey(
70                    $key,
71                    $meta,
72                    'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'dwtimeline/conf/metadata.php'
73                );
74            }
75
76            foreach ($meta as $key => $value) {
77                $this->assertArrayHasKey(
78                    $key,
79                    $conf,
80                    'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'dwtimeline/conf/default.php'
81                );
82            }
83        }
84    }
85}
86