xref: /plugin/struct/_test/QueryBuilderOtherTest.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\StructException;
6*8fed17f3SAndreas Gohruse dokuwiki\plugin\struct\test\mock\QueryBuilder;
7*8fed17f3SAndreas Gohr
8*8fed17f3SAndreas Gohr/**
9*8fed17f3SAndreas Gohr * @group plugin_struct
10*8fed17f3SAndreas Gohr * @group plugins
11*8fed17f3SAndreas Gohr */
12*8fed17f3SAndreas Gohrclass QueryBuilderOtherTest extends StructTest
13*8fed17f3SAndreas Gohr{
14*8fed17f3SAndreas Gohr
15*8fed17f3SAndreas Gohr    /**
16*8fed17f3SAndreas Gohr     * @noinspection SqlDialectInspection
17*8fed17f3SAndreas Gohr     * @noinspection SqlNoDataSourceInspection
18*8fed17f3SAndreas Gohr     */
19*8fed17f3SAndreas Gohr    public function test_order_by()
20*8fed17f3SAndreas Gohr    {
21*8fed17f3SAndreas Gohr        $qb = new QueryBuilder();
22*8fed17f3SAndreas Gohr
23*8fed17f3SAndreas Gohr        $qb->addTable('first', 'T1');
24*8fed17f3SAndreas Gohr        $qb->addOrderBy('Q.foo');
25*8fed17f3SAndreas Gohr
26*8fed17f3SAndreas Gohr        $expectedSQL = '
27*8fed17f3SAndreas Gohr            SELECT FROM first AS T1 WHERE ORDER BY Q.foo
28*8fed17f3SAndreas Gohr        ';
29*8fed17f3SAndreas Gohr
30*8fed17f3SAndreas Gohr        list($actual_sql, $actual_opts) = $qb->getSQL();
31*8fed17f3SAndreas Gohr        $this->assertEquals($this->cleanWS($expectedSQL), $this->cleanWS($actual_sql));
32*8fed17f3SAndreas Gohr        $this->assertEquals(array(), $actual_opts);
33*8fed17f3SAndreas Gohr
34*8fed17f3SAndreas Gohr    }
35*8fed17f3SAndreas Gohr
36*8fed17f3SAndreas Gohr    /**
37*8fed17f3SAndreas Gohr     * @noinspection SqlDialectInspection
38*8fed17f3SAndreas Gohr     * @noinspection SqlNoDataSourceInspection
39*8fed17f3SAndreas Gohr     */
40*8fed17f3SAndreas Gohr    public function test_group_by()
41*8fed17f3SAndreas Gohr    {
42*8fed17f3SAndreas Gohr        $qb = new QueryBuilder();
43*8fed17f3SAndreas Gohr
44*8fed17f3SAndreas Gohr        $qb->addTable('first', 'T1');
45*8fed17f3SAndreas Gohr        $qb->addGroupByColumn('T1', 'foo');
46*8fed17f3SAndreas Gohr        $qb->addGroupByStatement('T2.bar');
47*8fed17f3SAndreas Gohr
48*8fed17f3SAndreas Gohr        $expectedSQL = '
49*8fed17f3SAndreas Gohr            SELECT FROM first AS T1 WHERE GROUP BY T1.foo, T2.bar
50*8fed17f3SAndreas Gohr        ';
51*8fed17f3SAndreas Gohr
52*8fed17f3SAndreas Gohr        list($actual_sql, $actual_opts) = $qb->getSQL();
53*8fed17f3SAndreas Gohr        $this->assertEquals($this->cleanWS($expectedSQL), $this->cleanWS($actual_sql));
54*8fed17f3SAndreas Gohr        $this->assertEquals(array(), $actual_opts);
55*8fed17f3SAndreas Gohr    }
56*8fed17f3SAndreas Gohr
57*8fed17f3SAndreas Gohr    public function test_groupby_missing_alias()
58*8fed17f3SAndreas Gohr    {
59*8fed17f3SAndreas Gohr        $this->expectException(StructException::class);
60*8fed17f3SAndreas Gohr        $qb = new QueryBuilder();
61*8fed17f3SAndreas Gohr
62*8fed17f3SAndreas Gohr        $qb->addTable('first', 'T1');
63*8fed17f3SAndreas Gohr        $qb->addGroupByColumn('T2', 'foo');
64*8fed17f3SAndreas Gohr    }
65*8fed17f3SAndreas Gohr}
66