[TASK] Namespace and move t3lib unit tests - 1
[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 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 * @package TYPO3
31 * @subpackage t3lib
32 */
33 class SqlParserTest extends \tx_phpunit_testcase {
34
35 /**
36 * @var \TYPO3\CMS\Core\Database\SqlParser
37 */
38 private $fixture;
39
40 public function setUp() {
41 $this->fixture = new \TYPO3\CMS\Core\Database\SqlParser();
42 }
43
44 public function tearDown() {
45 unset($this->fixture);
46 }
47
48 /**
49 * Regression test
50 *
51 * @test
52 * @todo Define visibility
53 */
54 public 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
129 ?>