summaryrefslogtreecommitdiffstats
path: root/tests/Builder/DeleteStatementTest.php
blob: 0327e038799490f485f7e210dca69922a96ffbab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
declare(strict_types=1);

namespace PhpMyAdmin\SqlParser\Tests\Builder;

use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Tests\TestCase;

class DeleteStatementTest extends TestCase
{
    public function testBuilderSingleTable()
    {
        /* Assertion 1 */
        $query = 'DELETE IGNORE FROM t1';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals($query, $stmt->build());

        /* Assertion 2 */
        $query = 'DELETE IGNORE FROM t1 WHERE 1=1';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals($query, $stmt->build());

        /* Assertion 3 */
        $query = 'DELETE IGNORE FROM t1 WHERE 1=1 ORDER BY id ASC';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals($query, $stmt->build());

        /* Assertion 4 */
        $query = 'DELETE IGNORE FROM t1 WHERE 1=1 ORDER BY id ASC LIMIT 0, 25';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals($query, $stmt->build());

        /* Assertion 5 */
        $query = 'DELETE IGNORE FROM t1';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals($query, $stmt->build());

        /* Assertion 6 */
        $query = 'DELETE LOW_PRIORITY FROM `test`.users '
            . 'WHERE `id`<3 AND (username="Dan" OR username="Paul") ORDER BY id ASC';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals($query, $stmt->build());
    }

    public function testBuilderMultiTable()
    {
        /* Assertion 1 */
        $query = 'DELETE QUICK table1, table2.* FROM table1 AS `t1`, table2 AS `t2`';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals($query, $stmt->build());

        /* Assertion 2 */
        $query = 'DELETE QUICK table1, table2.* FROM table1 AS `t1`, table2 AS `t2` WHERE 1=1';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals($query, $stmt->build());

        /* Assertion 3 */
        $query = 'DELETE QUICK FROM table1, table2.* USING table1 AS `t1`, table2 AS `t2` WHERE 1=1';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals($query, $stmt->build());

        /* Assertion 4 */
        $query = 'DELETE LOW_PRIORITY t1, t2 FROM t1 INNER JOIN t2 '
            . 'INNER JOIN t3 WHERE t1.id=t2.id AND t2.id=t3.id';

        $parser = new Parser($query);
        $stmt = $parser->statements[0];

        $this->assertEquals($query, $stmt->build());
    }
}