-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathDeleteQueryTest.php
More file actions
65 lines (53 loc) · 2.09 KB
/
Copy pathDeleteQueryTest.php
File metadata and controls
65 lines (53 loc) · 2.09 KB
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
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
require_once "..".DIRECTORY_SEPARATOR."autoload.php";
require_once 'PHPUnit/Framework.php';
class DeleteQueryTest extends PHPUnit_Framework_TestCase
{
public function testSimple()
{
$q = new DeleteQuery(array('test'));
$this->assertEquals('DELETE FROM `test`', $q->sql()); // aliases are NOT supported in one-table delete queries
}
public function testOneOfMultiple()
{
$q = new DeleteQuery(array('test', 'test2', 'test3'));
$this->assertEquals('DELETE FROM `t0` USING `test` AS `t0`, `test2` AS `t1`, `test3` AS `t2`', $q->sql());
}
public function testSeveralOfMultiple()
{
$q = new DeleteQuery(array('test', 'test2', 'test3'), array(0, 2));
$this->assertEquals('DELETE FROM `t0`, `t2` USING `test` AS `t0`, `test2` AS `t1`, `test3` AS `t2`', $q->sql());
}
public function testWhere()
{
$q = new DeleteQuery(array('test'));
$q->setWhere(new AndOp(array(
new Condition('=', new Field('group'), 'test'),
new Condition('=', new Field('author'), null)
)));
$this->assertEquals('DELETE FROM `test` WHERE (`test`.`group` = :p1 AND `test`.`author` IS NULL)', $q->sql());
}
public function testOrderLimit()
{
$q = new DeleteQuery(array('test'));
$q->setLimit(10);
$q->setOrderBy(array(new Field('field1')));
$this->assertEquals('DELETE FROM `test` ORDER BY `test`.`field1` ASC LIMIT 10', $q->sql());
}
public function testOrderLimitOnMultiple()
{
try {
$q = new DeleteQuery(array('test', 'test2', 'test3'));
$q->setLimit(10);
$this->fail('LIMIT should not be allowed on multi-table queries');
} catch (LogicException $e) {
}
try {
$q = new DeleteQuery(array('test', 'test2', 'test3'));
$q->setOrderBy(array(new Field('field1')));
$this->fail('ORDER BY should not be allowed on multi-table queries');
} catch (LogicException $e) {
}
}
}