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