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