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