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