1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5use dokuwiki\plugin\struct\meta\Search;
6
7/**
8 * Tests for the building of SQL-Queries for the struct plugin
9 *
10 * @group plugin_struct
11 * @group plugins
12 *
13 */
14class AccessTableDataSQL_struct_test extends StructTest {
15
16    /**
17     * Testdata for @see schemaDataSQL_struct_test::test_buildGetDataSQL
18     *
19     * @return array
20     */
21    public static function buildGetDataSQL_testdata() {
22        $schemadata = new mock\AccessTableDataNoDB('testtable', 'pagename', 27);
23
24        /** @noinspection SqlResolve */
25        return array(
26            array(
27                array(
28                    'obj' => $schemadata,
29                    'singles' => array('dokuwiki\\plugin\\struct\\types\\Text', 'dokuwiki\\plugin\\struct\\types\\Text'),
30                    'multis' => array(),
31                ),
32                "SELECT DATA.pid AS PID,
33                        DATA.col1 AS out1,
34                        DATA.col2 AS out2
35                   FROM data_testtable AS DATA
36                  WHERE (DATA.pid = ?
37                    AND DATA.rev = ?)
38               GROUP BY DATA.pid,out1,out2",
39                array('pagename', 27),
40                'no multis, with ts',
41            ),
42            array(
43                array(
44                    'obj' => $schemadata,
45                    'singles' => array('dokuwiki\\plugin\\struct\\types\\Text','dokuwiki\\plugin\\struct\\types\\Text'),
46                    'multis' => array('dokuwiki\\plugin\\struct\\types\\Text'),
47                ),
48                "SELECT DATA.pid AS PID,
49                        DATA.col1 AS out1,
50                        DATA.col2 AS out2,
51                        GROUP_CONCAT(M3.value,'".Search::CONCAT_SEPARATOR."') AS out3
52                   FROM data_testtable AS DATA
53                   LEFT OUTER JOIN multi_testtable AS M3
54                     ON DATA.pid = M3.pid
55                    AND DATA.rev = M3.rev
56                    AND M3.colref = 3
57                  WHERE (DATA.pid = ?
58                    AND DATA.rev = ?)
59               GROUP BY DATA.pid,out1,out2",
60                array('pagename', 27,),
61                'one multi, with ts',
62            ),
63            array(
64                array(
65                    'obj' => $schemadata,
66                    'singles' => array(),
67                    'multis' => array('dokuwiki\\plugin\\struct\\types\\Text','dokuwiki\\plugin\\struct\\types\\Text')
68                ),
69                "SELECT DATA.pid AS PID,
70                        GROUP_CONCAT(M1.value,'".Search::CONCAT_SEPARATOR."') AS out1,
71                        GROUP_CONCAT(M2.value,'".Search::CONCAT_SEPARATOR."') AS out2
72                   FROM data_testtable AS DATA
73                   LEFT OUTER JOIN multi_testtable AS M2
74                     ON DATA.pid = M2.pid
75                    AND DATA.rev = M2.rev
76                    AND M2.colref = 2
77                   LEFT OUTER JOIN multi_testtable AS M1
78                     ON DATA.pid = M1.pid
79                    AND DATA.rev = M1.rev
80                    AND M1.colref = 1
81                  WHERE (DATA.pid = ?
82                    AND DATA.rev = ?)
83               GROUP BY DATA.pid",
84                array('pagename', 27,),
85                "only two multis"
86            )
87        );
88    }
89
90    /**
91     * @dataProvider buildGetDataSQL_testdata
92     *
93     * @covers       dokuwiki\plugin\struct\meta\SchemaData::buildGetDataSQL
94     *
95     * @param $testvals
96     * @param string $expected_sql
97     * @param array $expected_opt
98     * @param string $msg
99     */
100    public function test_buildGetDataSQL($testvals, $expected_sql, $expected_opt, $msg) {
101        /** @var mock\AccessTableDataNoDB $obj */
102        $obj = $testvals['obj'];
103        $obj->setColumns($testvals['singles'], $testvals['multis']);
104
105        list($actual_sql, $actual_opt) = $obj->buildGetDataSQL();
106
107        $this->assertSame($this->cleanWS($expected_sql), $this->cleanWS($actual_sql), $msg);
108        $this->assertEquals($expected_opt, $actual_opt, $msg);
109    }
110
111}
112