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