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