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