1<?php
2
3/**
4 * Tests for the function buildSyntaxFromJSON of the tablelayout plugin
5 *
6 * @group plugin_tablelayout
7 * @group plugins
8 *
9 */
10class buildSyntaxFromJSON_plugin_tablelayout_test extends DokuWikiTest
11{
12
13    protected $pluginsEnabled = array('tablelayout');
14
15
16    /**
17     * Testdata for @see buildSyntaxFromJSON_plugin_tablelayout_test::test_buildSyntaxFromJSON
18     *
19     * @return array Array of testcases
20     */
21    public static function dataBuildSyntaxFromJSON()
22    {
23        return array(
24            array(
25                '{"colwidth":["2px","3px"]}',
26                '{{tablelayout?colwidth="2px,3px"}}',
27                'Simple column widths'
28            ),
29            array(
30                '{"colwidth":["2px",null,"3px"]}',
31                '{{tablelayout?colwidth="2px,,3px"}}',
32                'One undefined column-width in between'
33            ),
34            array(
35                '{"rowsHeaderSource":2,"rowsVisible":10}',
36                '{{tablelayout?rowsHeaderSource=2&rowsVisible=10}}',
37                '2 fixed and 10 visible rows'
38            ),
39            array(
40                '{"colwidth":["2px",null,"3px"],"rowsHeaderSource":2,"rowsVisible":10}',
41                '{{tablelayout?rowsHeaderSource=2&rowsVisible=10&colwidth="2px,,3px"}}',
42                '2 fixed and 10 visible rows and col-widths'
43            ),
44            array(
45                '{"rowsHeaderSource":2,"colwidth":["2px",null,"3px"],"rowsVisible":10}',
46                '{{tablelayout?rowsHeaderSource=2&rowsVisible=10&colwidth="2px,,3px"}}',
47                '2 fixed and 10 visible rows and col-widths, differently sorted'
48            ),
49            array(
50                '{"rowsHeaderSource":2,"colwidth":["2px",null,"3px"],"rowsVisible":10,"tableSort":1}',
51                '{{tablelayout?rowsHeaderSource=2&rowsVisible=10&colwidth="2px,,3px"&tableSort=1}}',
52                '2 fixed and 10 visible rows and col-widths, set tableSort to true'
53            )
54        );
55    }
56
57    /**
58     * @dataProvider dataBuildSyntaxFromJSON
59     *
60     * @param string $json
61     * @param array $expected_syntax
62     * @param string $msg
63     */
64    public function testBuildSyntaxFromJSON($json, $expected_syntax, $msg)
65    {
66        /** @var helper_plugin_tablelayout $helper */
67        $helper = plugin_load('helper', 'tablelayout');
68
69        $actual_syntax = $helper->buildSyntaxFromJSON($json);
70
71        $this->assertSame($expected_syntax, $actual_syntax, $msg);
72    }
73}
74