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