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