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