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