2 namespace TYPO3\CMS\Core\Tests\Unit\Database
;
4 /***************************************************************
7 * (c) 2011 Patrick Schriner <patrick.schriner@diemedialen.de>
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
27 * Testcase for TYPO3\CMS\Core\Database\SqlParser
29 * @author Patrick Schriner <patrick.schriner@diemedialen.de>
31 class SqlParserTest
extends \TYPO3\CMS\Core\Tests\UnitTestCase
{
34 * @var \TYPO3\CMS\Core\Database\SqlParser|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
38 public function setUp() {
39 $this->fixture
= $this->getAccessibleMock('\\TYPO3\\CMS\\Core\\Database\\SqlParser', array('dummy'));
42 public function tearDown() {
43 unset($this->fixture
);
51 public function compileWhereClauseDoesNotDropClauses() {
56 'field' => 'fe_group',
81 'field' => 'fe_group',
93 'type' => 'FIND_IN_SET',
107 'type' => 'FIND_IN_SET',
113 'field' => 'fe_group'
118 $output = $this->fixture
->compileWhereClause($clauses);
119 $parts = explode(' OR ', $output);
120 $this->assertSame(count($clauses), count($parts));
121 $this->assertContains('IFNULL', $output);
125 * Data provider for trimSqlReallyTrimsAllWhitespace
127 * @see trimSqlReallyTrimsAllWhitespace
129 public function trimSqlReallyTrimsAllWhitespaceDataProvider() {
131 'Nothing to trim' => array('SELECT * FROM test WHERE 1=1;', 'SELECT * FROM test WHERE 1=1 '),
132 'Space after ;' => array('SELECT * FROM test WHERE 1=1; ', 'SELECT * FROM test WHERE 1=1 '),
133 'Space before ;' => array('SELECT * FROM test WHERE 1=1 ;', 'SELECT * FROM test WHERE 1=1 '),
134 'Space before and after ;' => array('SELECT * FROM test WHERE 1=1 ; ', 'SELECT * FROM test WHERE 1=1 '),
135 'Linefeed after ;' => array('SELECT * FROM test WHERE 1=1' . LF
. ';', 'SELECT * FROM test WHERE 1=1 '),
136 'Linefeed before ;' => array('SELECT * FROM test WHERE 1=1;' . LF
, 'SELECT * FROM test WHERE 1=1 '),
137 'Linefeed before and after ;' => array('SELECT * FROM test WHERE 1=1' . LF
. ';' . LF
, 'SELECT * FROM test WHERE 1=1 '),
138 'Tab after ;' => array('SELECT * FROM test WHERE 1=1' . TAB
. ';', 'SELECT * FROM test WHERE 1=1 '),
139 'Tab before ;' => array('SELECT * FROM test WHERE 1=1;' . TAB
, 'SELECT * FROM test WHERE 1=1 '),
140 'Tab before and after ;' => array('SELECT * FROM test WHERE 1=1' . TAB
. ';' . TAB
, 'SELECT * FROM test WHERE 1=1 '),
146 * @dataProvider trimSqlReallyTrimsAllWhitespaceDataProvider
147 * @param string $sql The SQL to trim
148 * @param string $expected The expected trimmed SQL with single space at the end
150 public function trimSqlReallyTrimsAllWhitespace($sql, $expected) {
151 $result = $this->fixture
->_call('trimSQL', $sql);
152 $this->assertSame($expected, $result);