xref: /plugin/dev/skel/_test/GeneralTest.php (revision 711b11c1771b3c591ff8bcfcae07bf36e29e0a1a)
170316b84SAndreas Gohr<?php
270316b84SAndreas Gohr
370316b84SAndreas Gohrnamespace dokuwiki\@@PLUGIN_TYPE@@\@@PLUGIN_NAME@@\test;
470316b84SAndreas Gohr
570316b84SAndreas Gohruse DokuWikiTest;
670316b84SAndreas Gohr
770316b84SAndreas Gohr/**
870316b84SAndreas Gohr * General tests for the @@PLUGIN_NAME@@ @@PLUGIN_TYPE@@
970316b84SAndreas Gohr *
1070316b84SAndreas Gohr * @group @@PLUGIN_TYPE@@_@@PLUGIN_NAME@@
1170316b84SAndreas Gohr * @group @@PLUGIN_TYPE@@s
1270316b84SAndreas Gohr */
1370316b84SAndreas Gohrclass GeneralTest extends DokuWikiTest
1470316b84SAndreas Gohr{
1570316b84SAndreas Gohr    /**
1670316b84SAndreas Gohr     * Simple test to make sure the @@PLUGIN_TYPE@@.info.txt is in correct format
1770316b84SAndreas Gohr     */
1870316b84SAndreas Gohr    public function testPluginInfo(): void
1970316b84SAndreas Gohr    {
2070316b84SAndreas Gohr        $file = __DIR__ . '/../@@PLUGIN_TYPE@@.info.txt';
2170316b84SAndreas Gohr        $this->assertFileExists($file);
2270316b84SAndreas Gohr
2370316b84SAndreas Gohr        $info = confToHash($file);
2470316b84SAndreas Gohr
2570316b84SAndreas Gohr        $this->assertArrayHasKey('base', $info);
2670316b84SAndreas Gohr        $this->assertArrayHasKey('author', $info);
2770316b84SAndreas Gohr        $this->assertArrayHasKey('email', $info);
2870316b84SAndreas Gohr        $this->assertArrayHasKey('date', $info);
2970316b84SAndreas Gohr        $this->assertArrayHasKey('name', $info);
3070316b84SAndreas Gohr        $this->assertArrayHasKey('desc', $info);
3170316b84SAndreas Gohr        $this->assertArrayHasKey('url', $info);
3270316b84SAndreas Gohr
3370316b84SAndreas Gohr        $this->assertEquals('@@PLUGIN_NAME@@', $info['base']);
34*711b11c1SAndreas Gohr        $this->assertMatchesRegularExpression('/^https?:\/\//', $info['url']);
3570316b84SAndreas Gohr        $this->assertTrue(mail_isvalid($info['email']));
36*711b11c1SAndreas Gohr        $this->assertMatchesRegularExpression('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
3770316b84SAndreas Gohr        $this->assertTrue(false !== strtotime($info['date']));
3870316b84SAndreas Gohr    }
3970316b84SAndreas Gohr
4070316b84SAndreas Gohr    /**
4170316b84SAndreas Gohr     * Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
4270316b84SAndreas Gohr     * conf/metadata.php.
4370316b84SAndreas Gohr     */
4470316b84SAndreas Gohr    public function testPluginConf(): void
4570316b84SAndreas Gohr    {
4670316b84SAndreas Gohr        $conf_file = __DIR__ . '/../conf/default.php';
4770316b84SAndreas Gohr        $meta_file = __DIR__ . '/../conf/metadata.php';
4870316b84SAndreas Gohr
4970316b84SAndreas Gohr        if (!file_exists($conf_file) && !file_exists($meta_file)) {
5070316b84SAndreas Gohr            self::markTestSkipped('No config files exist -> skipping test');
5170316b84SAndreas Gohr        }
5270316b84SAndreas Gohr
5370316b84SAndreas Gohr        if (file_exists($conf_file)) {
5470316b84SAndreas Gohr            include($conf_file);
5570316b84SAndreas Gohr        }
5670316b84SAndreas Gohr        if (file_exists($meta_file)) {
5770316b84SAndreas Gohr            include($meta_file);
5870316b84SAndreas Gohr        }
5970316b84SAndreas Gohr
6070316b84SAndreas Gohr        $this->assertEquals(
6170316b84SAndreas Gohr            gettype($conf),
6270316b84SAndreas Gohr            gettype($meta),
6370316b84SAndreas 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.'
6470316b84SAndreas Gohr        );
6570316b84SAndreas Gohr
6670316b84SAndreas Gohr        if ($conf !== null && $meta !== null) {
6770316b84SAndreas Gohr            foreach ($conf as $key => $value) {
6870316b84SAndreas Gohr                $this->assertArrayHasKey(
6970316b84SAndreas Gohr                    $key,
7070316b84SAndreas Gohr                    $meta,
7170316b84SAndreas Gohr                    'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . '@@PLUGIN_NAME@@/conf/metadata.php'
7270316b84SAndreas Gohr                );
7370316b84SAndreas Gohr            }
7470316b84SAndreas Gohr
7570316b84SAndreas Gohr            foreach ($meta as $key => $value) {
7670316b84SAndreas Gohr                $this->assertArrayHasKey(
7770316b84SAndreas Gohr                    $key,
7870316b84SAndreas Gohr                    $conf,
7970316b84SAndreas Gohr                    'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . '@@PLUGIN_NAME@@/conf/default.php'
8070316b84SAndreas Gohr                );
8170316b84SAndreas Gohr            }
8270316b84SAndreas Gohr        }
8370316b84SAndreas Gohr    }
8470316b84SAndreas Gohr}
85