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