1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
4
|
|
|
use HexMakina\Crudites\Grammar\Clause\Join; |
5
|
|
|
use HexMakina\Crudites\Grammar\Predicate; |
6
|
|
|
|
7
|
|
|
class JoinTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
public function testConstructor() |
10
|
|
|
{ |
11
|
|
|
$join = new Join('cbx_order', 'Orders'); |
12
|
|
|
$this->assertEquals('cbx_order', $join->table()); |
13
|
|
|
$this->assertEquals('Orders', $join->alias()); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function testConstructorWithDefaultAlias() |
17
|
|
|
{ |
18
|
|
|
$join = new Join('cbx_order'); |
19
|
|
|
$this->assertEquals('cbx_order', $join->table()); |
20
|
|
|
$this->assertEquals('cbx_order', $join->alias()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testType() |
24
|
|
|
{ |
25
|
|
|
$join = new Join('cbx_order', 'Orders'); |
26
|
|
|
$join->type('LEFT'); |
27
|
|
|
$this->assertEquals('LEFT JOIN `cbx_order` `Orders` ON', (string)$join); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testOn() |
31
|
|
|
{ |
32
|
|
|
$join = new Join('cbx_order', 'Orders'); |
33
|
|
|
$join->on('user_id', 'User', 'id'); |
34
|
|
|
$this->assertEquals('JOIN `cbx_order` `Orders` ON `Orders`.`user_id` = `User`.`id`', (string)$join); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testChainingTypeAndOn() |
38
|
|
|
{ |
39
|
|
|
$join = new Join('cbx_order', 'Orders'); |
40
|
|
|
$join->type('LEFT')->on('user_id', 'User', 'id'); |
41
|
|
|
$expectedString = sprintf('LEFT JOIN `%s` `%s` ON `Orders`.`user_id` = `User`.`id`', 'cbx_order', 'Orders'); |
42
|
|
|
$this->assertEquals($expectedString, (string)$join); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testName() |
46
|
|
|
{ |
47
|
|
|
$join = new Join('cbx_order', 'Orders'); |
48
|
|
|
$this->assertEquals('JOIN', $join->name()); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|