1<?php
2
3/**
4 * @group plugin_data
5 * @group plugins
6 */
7class syntax_plugin_data_table_test extends DokuWikiTest {
8
9    protected $pluginsEnabled = array('data', 'sqlite');
10
11    private $exampleEntry = "---- datatable employees----\n"
12            . "cols    : %pageid%, employees, deadline_dt, website_url, volume\n"
13            . 'headers : Details, "Assigned Employees \#no", stuff outside quotes """Deadline, ",  Personal website, $$$'."\n"
14            . "max     : 10\n"
15            . "filter  : type=web development\n"
16            . "sort    : ^volume\n"
17            . "dynfilters: 1\n"
18            . "summarize : 1\n"
19            . "align   : c\n"
20            . "rownumbers: 1\n"
21            . "widths  : 50px, 20em, - , 10%\n"
22            . "----";
23
24    function testHandle() {
25        $plugin = new syntax_plugin_data_table();
26
27        $handler = new Doku_Handler();
28        $result = $plugin->handle($this->exampleEntry, 0, 10, $handler);
29
30        $data = array(
31            'classes' => 'employees',
32            'limit' => 10,
33            'dynfilters' => 1,
34            'summarize' => 1,
35            'rownumbers' => 1,
36            'sepbyheaders' => '',
37            'headers' => array(
38                '0' => 'Details',
39                '1' => 'Assigned Employees #no',
40                '2' => '"Deadline, ',
41                '3' => 'Personal website',
42                '4' => '$$$'
43            ),
44            'widths' => array(
45                '0' => '50px',
46                '1' => '20em',
47                '2' => '-',
48                '3' => '10%'
49            ),
50            'filter' => array(
51                '0' => array(
52                    'key' => 'type',
53                    'value' => 'web development',
54                    'compare' => '=',
55                    'colname' => 'type',
56                    'type' => '',
57                    'logic' => 'AND'
58                )
59            ),
60            'cols' => array(
61                '%pageid%' => array(
62                    'colname' => '%pageid%',
63                    'multi' => '',
64                    'key' => '%pageid%',
65                    'origkey' => '%pageid%',
66                    'title' => 'Title',
67                    'type' => 'page',
68                ),
69                'employee' => array(
70                    'colname' => 'employees',
71                    'multi' => 1,
72                    'key' => 'employee',
73                    'origkey' => 'employee',
74                    'title' => 'employee',
75                    'type' => ''
76                ),
77                'deadline' => array(
78                    'colname' => 'deadline_dt',
79                    'multi' => '',
80                    'key' => 'deadline',
81                    'origkey' => 'deadline',
82                    'title' => 'deadline',
83                    'type' => 'dt'
84                ),
85                'website' => array(
86                    'colname' => 'website_url',
87                    'multi' => '',
88                    'key' => 'website',
89                    'origkey' => 'website',
90                    'title' => 'website',
91                    'type' => 'url'
92                ),
93                'volume' => array(
94                    'colname' => 'volume',
95                    'multi' => '',
96                    'key' => 'volume',
97                    'origkey' => 'volume',
98                    'title' => 'volume',
99                    'type' => ''
100                ),
101
102            ),
103            'sort' => array(
104                '0' => 'volume',
105                '1' => 'DESC'
106            ),
107            'align' => array(
108                '0' => 'center'
109            ),
110            'sql' => "SELECT \" \" || pages.page, group_concat(\" \" || T1.value,'
111'), group_concat(\" \" || T2.value,'
112'), group_concat(\" \" || T3.value,'
113'), group_concat(\" \" || T4.value,'
114')
115                FROM (
116                    SELECT DISTINCT pages.pid AS pid
117                    FROM pages  LEFT JOIN data AS T1 ON T1.pid = pages.pid AND T1.key = 'type'
118                    WHERE 1 = 1 AND T1.value = 'web development'
119                ) AS W1
120                 LEFT JOIN data AS T1 ON T1.pid = W1.pid AND T1.key = 'employee' LEFT JOIN data AS T2 ON T2.pid = W1.pid AND T2.key = 'deadline' LEFT JOIN data AS T3 ON T3.pid = W1.pid AND T3.key = 'website' LEFT JOIN data AS T4 ON T4.pid = W1.pid AND T4.key = 'volume'
121                LEFT JOIN pages ON W1.pid=pages.pid
122                GROUP BY W1.pid
123                ORDER BY T4.value DESC LIMIT 11",
124            'cur_param' => array()
125
126);
127        $this->assertEquals($data, $result, 'Data array corrupted');
128    }
129
130}
131
132
133