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