commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / tests / phpunit / CRM / Utils / SQL / InsertTest.php
1 <?php
2 require_once 'CiviTest/CiviUnitTestCase.php';
3
4 /**
5 * Class CRM_Utils_SQL_SelectTest
6 */
7 class CRM_Utils_SQL_InsertTest extends CiviUnitTestCase {
8 public function testRow_twice() {
9 $insert = CRM_Utils_SQL_Insert::into('foo')
10 ->row(array('first' => '1', 'second' => '2'))
11 ->row(array('second' => '2b', 'first' => '1b'));
12 $expected = '
13 INSERT INTO foo (`first`,`second`) VALUES
14 ("1","2"),
15 ("1b","2b")
16 ';
17 $this->assertLike($expected, $insert->toSQL());
18 }
19
20 public function testRows() {
21 $insert = CRM_Utils_SQL_Insert::into('foo')
22 ->row(array('first' => '1', 'second' => '2'))
23 ->rows(array(
24 array('second' => '2b', 'first' => '1b'),
25 array('first' => '1c', 'second' => '2c'),
26 ))
27 ->row(array('second' => '2d', 'first' => '1d'));
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 */
43 public function assertLike($expected, $actual, $message = '') {
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 }
48
49 }