[TASK] Reduce memory footprint of unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Database / SqlParserTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Database;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2013 Patrick Schriner <patrick.schriner@diemedialen.de>
8 * All rights reserved
9 *
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.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
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.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Testcase for TYPO3\CMS\Core\Database\SqlParser
28 *
29 * @author Patrick Schriner <patrick.schriner@diemedialen.de>
30 */
31 class SqlParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
32
33 /**
34 * @var \TYPO3\CMS\Core\Database\SqlParser|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
35 */
36 protected $fixture;
37
38 public function setUp() {
39 $this->fixture = $this->getAccessibleMock('\\TYPO3\\CMS\\Core\\Database\\SqlParser', array('dummy'));
40 }
41
42 /**
43 * Regression test
44 *
45 * @test
46 */
47 public function compileWhereClauseDoesNotDropClauses() {
48 $clauses = array(
49 0 => array(
50 'modifier' => '',
51 'table' => 'pages',
52 'field' => 'fe_group',
53 'calc' => '',
54 'comparator' => '=',
55 'value' => array(
56 0 => '',
57 1 => '\''
58 )
59 ),
60 1 => array(
61 'operator' => 'OR',
62 'modifier' => '',
63 'func' => array(
64 'type' => 'IFNULL',
65 'default' => array(
66 0 => '1',
67 1 => '\''
68 ),
69 'table' => 'pages',
70 'field' => 'fe_group'
71 )
72 ),
73 2 => array(
74 'operator' => 'OR',
75 'modifier' => '',
76 'table' => 'pages',
77 'field' => 'fe_group',
78 'calc' => '',
79 'comparator' => '=',
80 'value' => array(
81 0 => '0',
82 1 => '\''
83 )
84 ),
85 3 => array(
86 'operator' => 'OR',
87 'modifier' => '',
88 'func' => array(
89 'type' => 'FIND_IN_SET',
90 'str' => array(
91 0 => '0',
92 1 => '\''
93 ),
94 'table' => 'pages',
95 'field' => 'fe_group'
96 ),
97 'comparator' => ''
98 ),
99 4 => array(
100 'operator' => 'OR',
101 'modifier' => '',
102 'func' => array(
103 'type' => 'FIND_IN_SET',
104 'str' => array(
105 0 => '-1',
106 1 => '\''
107 ),
108 'table' => 'pages',
109 'field' => 'fe_group'
110 ),
111 'comparator' => ''
112 )
113 );
114 $output = $this->fixture->compileWhereClause($clauses);
115 $parts = explode(' OR ', $output);
116 $this->assertSame(count($clauses), count($parts));
117 $this->assertContains('IFNULL', $output);
118 }
119
120 /**
121 * Data provider for trimSqlReallyTrimsAllWhitespace
122 *
123 * @see trimSqlReallyTrimsAllWhitespace
124 */
125 public function trimSqlReallyTrimsAllWhitespaceDataProvider() {
126 return array(
127 'Nothing to trim' => array('SELECT * FROM test WHERE 1=1;', 'SELECT * FROM test WHERE 1=1 '),
128 'Space after ;' => array('SELECT * FROM test WHERE 1=1; ', 'SELECT * FROM test WHERE 1=1 '),
129 'Space before ;' => array('SELECT * FROM test WHERE 1=1 ;', 'SELECT * FROM test WHERE 1=1 '),
130 'Space before and after ;' => array('SELECT * FROM test WHERE 1=1 ; ', 'SELECT * FROM test WHERE 1=1 '),
131 'Linefeed after ;' => array('SELECT * FROM test WHERE 1=1' . LF . ';', 'SELECT * FROM test WHERE 1=1 '),
132 'Linefeed before ;' => array('SELECT * FROM test WHERE 1=1;' . LF, 'SELECT * FROM test WHERE 1=1 '),
133 'Linefeed before and after ;' => array('SELECT * FROM test WHERE 1=1' . LF . ';' . LF, 'SELECT * FROM test WHERE 1=1 '),
134 'Tab after ;' => array('SELECT * FROM test WHERE 1=1' . TAB . ';', 'SELECT * FROM test WHERE 1=1 '),
135 'Tab before ;' => array('SELECT * FROM test WHERE 1=1;' . TAB, 'SELECT * FROM test WHERE 1=1 '),
136 'Tab before and after ;' => array('SELECT * FROM test WHERE 1=1' . TAB . ';' . TAB, 'SELECT * FROM test WHERE 1=1 '),
137 );
138 }
139
140 /**
141 * @test
142 * @dataProvider trimSqlReallyTrimsAllWhitespaceDataProvider
143 * @param string $sql The SQL to trim
144 * @param string $expected The expected trimmed SQL with single space at the end
145 */
146 public function trimSqlReallyTrimsAllWhitespace($sql, $expected) {
147 $result = $this->fixture->_call('trimSQL', $sql);
148 $this->assertSame($expected, $result);
149 }
150
151 }