jsonParser_plugin_prosemirror_test   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 34
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rendererProvider() 0 13 2
A test_parser() 0 5 1
1
<?php
2
3
use dokuwiki\plugin\prosemirror\parser\SyntaxTreeBuilder;
4
5
/**
6
 * Node tests for the prosemirror plugin
7
 *
8
 * @group plugin_prosemirror
9
 * @group plugins
10
 */
11
class jsonParser_plugin_prosemirror_test extends DokuWikiTest
12
{
13
    protected $pluginsEnabled = ['prosemirror', 'wrap'];
14
15
    /**
16
     * @dataProvider rendererProvider
17
     *
18
     * @param string $json
19
     * @param string $expectedDokuWikiMarkup
20
     * @param string $msg
21
     */
22
    public function test_parser($json, $expectedDokuWikiMarkup, $msg)
23
    {
24
        $rootNode = SyntaxTreeBuilder::parseDataIntoTree(json_decode($json, true));
25
        $actualMarkup = $rootNode->toSyntax();
26
        $this->assertEquals(rtrim($expectedDokuWikiMarkup), rtrim($actualMarkup), $msg);
27
    }
28
29
    /**
30
     * @return array
31
     */
32
    public function rendererProvider()
33
    {
34
        $data = [];
35
36
        $files = glob(__DIR__ . '/json/*.json');
37
        foreach ($files as $file) {
38
            $name = basename($file, '.json');
39
            $json = file_get_contents(__DIR__ . '/json/' . $name . '.json');
40
            $wiki = file_get_contents(__DIR__ . '/json/' . $name . '.txt');
41
            $data[] = [$json, $wiki, $name];
42
        }
43
44
        return $data;
45
    }
46
}
47