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