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