1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5use dokuwiki\plugin\struct\meta\StructException;
6use dokuwiki\plugin\struct\test\mock\QueryBuilder;
7
8/**
9 * @group plugin_struct
10 * @group plugins
11 */
12class QueryBuilder_struct_test extends StructTest
13{
14
15    public function test_join()
16    {
17        $qb = new QueryBuilder();
18
19        $qb->addTable('first');
20        $qb->addTable('second');
21        $qb->addTable('third');
22
23        $qb->addLeftJoin('second', 'fourth', 'fourth', 'second.foo=fourth.foo');
24        $this->assertEquals(array('first', 'second', 'fourth', 'third'), array_keys($qb->from));
25    }
26
27    public function test_placeholders()
28    {
29        $qb = new QueryBuilder();
30
31
32        $foo = $qb->addValue('foo');
33        $bar = $qb->addValue('bar');
34
35        $input = "this is $foo and $bar and $foo again";
36        $expect = "this is ? and ? and ? again";
37        $values = array('foo', 'bar', 'foo');
38
39        $output = $qb->fixPlaceholders($input);
40
41        $this->assertEquals($expect, $output[0]);
42        $this->assertEquals($values, $output[1]);
43    }
44
45    public function test_placeholderfail()
46    {
47        $this->expectException(StructException::class);
48        $qb = new QueryBuilder();
49        $qb->fixPlaceholders('this has unknown placeholder :!!val7!!:');
50    }
51}
52