jsonParser_plugin_prosemirror_test::test_parser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 5
rs 10
c 1
b 0
f 0
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