[BUGFIX] compileWhereClause causes Extbase errors with DBAL
[Packages/TYPO3.CMS.git] / tests / t3lib / class.t3lib_sqlparserTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2011 Patrick Schriner <patrick.schriner@diemedialen.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for class t3lib_sqlparser.
27 *
28 * @author Patrick Schriner <patrick.schriner@diemedialen.de>
29 *
30 * @package TYPO3
31 * @subpackage t3lib
32 */
33 class t3lib_sqlparserTest extends tx_phpunit_testcase {
34 /**
35 * @var t3lib_sqlparser
36 */
37 private $fixture;
38
39 public function setUp() {
40 $this->fixture = new t3lib_sqlparser();
41 }
42
43 public function tearDown() {
44 unset(
45 $this->fixture
46 );
47 }
48
49 /**
50 * Regression test
51 *
52 * @test
53 */
54 function compileWhereClauseDoesNotDropClauses() {
55 $clauses = array(
56 0 => array(
57 'modifier' => '',
58 'table' => 'pages',
59 'field' => 'fe_group',
60 'calc' => '',
61 'comparator' => '=',
62 'value' => array(
63 0 => '',
64 1 => '\'',
65 ),
66 ),
67 1 => array(
68 'operator' => 'OR',
69 'modifier' => '',
70 'func' => array(
71 'type' => 'IFNULL',
72 'default' => array(
73 0 => '1',
74 1 => '\'',
75 ),
76 'table' => 'pages',
77 'field' => 'fe_group',
78 ),
79 ),
80 2 => array(
81 'operator' => 'OR',
82 'modifier' => '',
83 'table' => 'pages',
84 'field' => 'fe_group',
85 'calc' => '',
86 'comparator' => '=',
87 'value' => array(
88 0 => '0',
89 1 => '\'',
90 ),
91 ),
92 3 => array(
93 'operator' => 'OR',
94 'modifier' => '',
95 'func' => array (
96 'type' => 'FIND_IN_SET',
97 'str' => array(
98 0 => '0',
99 1 => '\'',
100 ),
101 'table' => 'pages',
102 'field' => 'fe_group',
103 ),
104 'comparator' => '',
105 ),
106 4 => array(
107 'operator' => 'OR',
108 'modifier' => '',
109 'func' => array(
110 'type' => 'FIND_IN_SET',
111 'str' => array (
112 0 => '-1',
113 1 => '\'',
114 ),
115 'table' => 'pages',
116 'field' => 'fe_group',
117 ),
118 'comparator' => '',
119 ),
120 );
121 $output = $this->fixture->compileWhereClause($clauses);
122 $parts = explode(' OR ', $output);
123 $this->assertSame(count($clauses), count($parts));
124 $this->assertContains('IFNULL', $output);
125 }
126 }
127
128 ?>