1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5use dokuwiki\plugin\struct\meta\QueryBuilder;
6
7/**
8 * @group plugin_struct
9 * @group plugins
10 */
11class QueryBuilderFrom_struct_test extends StructTest
12{
13
14    public function test_join()
15    {
16        $qb = new QueryBuilder();
17
18        $qb->addTable('first', 'T1');
19        $qb->addTable('second', 'T2');
20        $qb->addTable('third', 'T3');
21
22        $qb->addLeftJoin('T2', 'fourth', 'T4', 'T2.foo=T4.foo');
23
24        $expectedSQL = '
25            SELECT FROM first AS T1, second AS T2 LEFT OUTER JOIN fourth AS T4
26            ON T2.foo = T4.foo, third AS T3 WHERE
27';
28
29        list($actual_sql, $actual_opts) = $qb->getSQL();
30        $this->assertEquals($this->cleanWS($expectedSQL), $this->cleanWS($actual_sql));
31        $this->assertEquals(array(), $actual_opts);
32    }
33
34    /**
35     * @expectedException \dokuwiki\plugin\struct\meta\StructException
36     */
37    public function test_table_alias_exception()
38    {
39        $qb = new QueryBuilder();
40
41        $qb->addTable('first', 'T1');
42        $qb->addTable('second', 'T1');
43    }
44
45    /**
46     * @expectedException \dokuwiki\plugin\struct\meta\StructException
47     */
48    public function test_leftjoin_missing_alias_exception()
49    {
50        $qb = new QueryBuilder();
51
52        $qb->addTable('first', 'T1');
53        $qb->addLeftJoin('T2', 'third', 'T3', 'T2.bar = T3.bar');
54    }
55
56    /**
57     * @expectedException \dokuwiki\plugin\struct\meta\StructException
58     */
59    public function test_leftjoin_existing_alias_exception()
60    {
61        $qb = new QueryBuilder();
62
63        $qb->addTable('first', 'T1');
64        $qb->addTable('second', 'T2');
65        $qb->addLeftJoin('T2', 'third', 'T1', 'T2.bar = T1.bar');
66    }
67}
68