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