GeneralTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 39
dl 0
loc 68
rs 10
c 1
b 0
f 0
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testPluginInfo() 0 20 1
B testPluginConf() 0 36 9
1
<?php
2
3
namespace dokuwiki\plugin\prosemirror\test;
4
5
use DokuWikiTest;
6
7
/**
8
 * General tests for the prosemirror plugin
9
 *
10
 * @group plugin_prosemirror
11
 * @group plugins
12
 */
13
class GeneralTest extends DokuWikiTest
14
{
15
16
    /**
17
     * Simple test to make sure the plugin.info.txt is in correct format
18
     */
19
    public function testPluginInfo(): void
20
    {
21
        $file = __DIR__ . '/../plugin.info.txt';
22
        $this->assertFileExists($file);
23
24
        $info = confToHash($file);
25
26
        $this->assertArrayHasKey('base', $info);
27
        $this->assertArrayHasKey('author', $info);
28
        $this->assertArrayHasKey('email', $info);
29
        $this->assertArrayHasKey('date', $info);
30
        $this->assertArrayHasKey('name', $info);
31
        $this->assertArrayHasKey('desc', $info);
32
        $this->assertArrayHasKey('url', $info);
33
34
        $this->assertEquals('prosemirror', $info['base']);
35
        $this->assertRegExp('/^https?:\/\//', $info['url']);
36
        $this->assertTrue(mail_isvalid($info['email']));
37
        $this->assertRegExp('/^\d\d\d\d-\d\d-\d\d$/', $info['date']);
38
        $this->assertTrue(false !== strtotime($info['date']));
39
    }
40
41
    /**
42
     * Test to ensure that every conf['...'] entry in conf/default.php has a corresponding meta['...'] entry in
43
     * conf/metadata.php.
44
     */
45
    public function testPluginConf(): void
46
    {
47
        $conf_file = __DIR__ . '/../conf/default.php';
48
        $meta_file = __DIR__ . '/../conf/metadata.php';
49
50
        if (!file_exists($conf_file) && !file_exists($meta_file)) {
51
            self::markTestSkipped('No config files exist -> skipping test');
52
        }
53
54
        if (file_exists($conf_file)) {
55
            include($conf_file);
56
        }
57
        if (file_exists($meta_file)) {
58
            include($meta_file);
59
        }
60
61
        $this->assertEquals(
62
            gettype($conf),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $conf seems to be never defined.
Loading history...
63
            gettype($meta),
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $meta seems to be never defined.
Loading history...
64
            'Both ' . DOKU_PLUGIN . 'prosemirror/conf/default.php and ' . DOKU_PLUGIN . 'prosemirror/conf/metadata.php have to exist and contain the same keys.'
0 ignored issues
show
Bug introduced by
The constant dokuwiki\plugin\prosemirror\test\DOKU_PLUGIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
65
        );
66
67
        if ($conf !== null && $meta !== null) {
68
            foreach ($conf as $key => $value) {
69
                $this->assertArrayHasKey(
70
                    $key,
71
                    $meta,
72
                    'Key $meta[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'prosemirror/conf/metadata.php'
73
                );
74
            }
75
76
            foreach ($meta as $key => $value) {
77
                $this->assertArrayHasKey(
78
                    $key,
79
                    $conf,
80
                    'Key $conf[\'' . $key . '\'] missing in ' . DOKU_PLUGIN . 'prosemirror/conf/default.php'
81
                );
82
            }
83
        }
84
85
    }
86
}
87