1<?php
2
3namespace dokuwiki\plugin\struct\test;
4
5use dokuwiki\plugin\struct\meta\QueryBuilder;
6use dokuwiki\plugin\struct\meta\QueryBuilderWhere;
7
8/**
9 * @group plugin_struct
10 * @group plugins
11 */
12class QueryBuilderWhere_struct_test extends StructTest
13{
14
15    public function test_sql()
16    {
17        $QB = new QueryBuilder();
18        $where = new QueryBuilderWhere($QB);
19
20        $where->whereAnd('foo = foo');
21        $this->assertEquals(
22            $this->cleanWS('(foo = foo)'),
23            $this->cleanWS($where->toSQL())
24        );
25
26        $where->whereAnd('bar = bar');
27        $this->assertEquals(
28            $this->cleanWS('(foo = foo AND bar = bar)'),
29            $this->cleanWS($where->toSQL())
30        );
31
32        $sub = $where->whereSubAnd();
33        $this->assertEquals(
34            $this->cleanWS('(foo = foo AND bar = bar)'),
35            $this->cleanWS($where->toSQL())
36        );
37
38        $sub->whereAnd('zab = zab');
39        $this->assertEquals(
40            $this->cleanWS('(foo = foo AND bar = bar AND (zab = zab))'),
41            $this->cleanWS($where->toSQL())
42        );
43
44        $sub->whereOr('fab = fab');
45        $this->assertEquals(
46            $this->cleanWS('(foo = foo AND bar = bar AND (zab = zab OR fab = fab))'),
47            $this->cleanWS($where->toSQL())
48        );
49    }
50
51    public function test_orsql()
52    {
53        $QB = new QueryBuilder();
54        $where = new QueryBuilderWhere($QB);
55
56        $where->whereAnd("foo = ''");
57        $this->assertEquals(
58            $this->cleanWS("(foo = '')"),
59            $this->cleanWS($where->toSQL())
60        );
61
62        $sub = $where->whereSubOr();
63        $sub->whereAnd('bar = bar');
64        $sub->whereAnd('baz = baz');
65        $this->assertEquals(
66            $this->cleanWS("(foo = '' OR (bar = bar AND baz = baz))"),
67            $this->cleanWS($where->toSQL())
68        );
69    }
70}
71