Commit | Line | Data |
---|---|---|
3e4ef323 | 1 | <?php |
92915c55 | 2 | require_once 'CiviTest/CiviUnitTestCase.php'; |
3e4ef323 | 3 | |
92915c55 TO |
4 | /** |
5 | * Class CRM_Utils_SQL_SelectTest | |
6 | */ | |
3e4ef323 | 7 | class CRM_Utils_SQL_InsertTest extends CiviUnitTestCase { |
00be9182 | 8 | public function testRow_twice() { |
3e4ef323 | 9 | $insert = CRM_Utils_SQL_Insert::into('foo') |
481a74f4 | 10 | ->row(array('first' => '1', 'second' => '2')) |
6c6e6187 | 11 | ->row(array('second' => '2b', 'first' => '1b')); |
3e4ef323 TO |
12 | $expected = ' |
13 | INSERT INTO foo (`first`,`second`) VALUES | |
14 | ("1","2"), | |
15 | ("1b","2b") | |
16 | '; | |
17 | $this->assertLike($expected, $insert->toSQL()); | |
18 | } | |
19 | ||
00be9182 | 20 | public function testRows() { |
3e4ef323 | 21 | $insert = CRM_Utils_SQL_Insert::into('foo') |
481a74f4 | 22 | ->row(array('first' => '1', 'second' => '2')) |
3e4ef323 | 23 | ->rows(array( |
92915c55 TO |
24 | array('second' => '2b', 'first' => '1b'), |
25 | array('first' => '1c', 'second' => '2c'), | |
3e4ef323 | 26 | )) |
6c6e6187 | 27 | ->row(array('second' => '2d', 'first' => '1d')); |
3e4ef323 TO |
28 | $expected = ' |
29 | INSERT INTO foo (`first`,`second`) VALUES | |
30 | ("1","2"), | |
31 | ("1b","2b"), | |
32 | ("1c","2c"), | |
33 | ("1d","2d") | |
34 | '; | |
35 | $this->assertLike($expected, $insert->toSQL()); | |
36 | } | |
37 | ||
38 | /** | |
39 | * @param $expected | |
40 | * @param $actual | |
41 | * @param string $message | |
42 | */ | |
00be9182 | 43 | public function assertLike($expected, $actual, $message = '') { |
3e4ef323 TO |
44 | $expected = trim((preg_replace('/[ \r\n\t]+/', ' ', $expected))); |
45 | $actual = trim((preg_replace('/[ \r\n\t]+/', ' ', $actual))); | |
46 | $this->assertEquals($expected, $actual, $message); | |
47 | } | |
96025800 | 48 | |
ef10e0b5 | 49 | } |