Added general unit test for RFC #12515
[Packages/TYPO3.CMS.git] / typo3 / sysext / dbal / tests / db_general_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Xavier Perseguers <typo3@perseguers.ch>
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 require_once('BaseTestCase.php');
27
28 /**
29 * Testcase for class ux_t3lib_db.
30 *
31 * $Id$
32 *
33 * @author Xavier Perseguers <typo3@perseguers.ch>
34 *
35 * @package TYPO3
36 * @subpackage dbal
37 */
38 class db_general_testcase extends BaseTestCase {
39
40 /**
41 * @var ux_t3lib_db (extended to make protected methods public)
42 */
43 protected $fixture;
44
45 /**
46 * @var array
47 */
48 protected $loadedExtensions;
49
50 /**
51 * Prepares the environment before running a test.
52 */
53 public function setUp() {
54 // Backup list of loaded extensions
55 $this->loadedExtensions = $GLOBALS['TYPO3_LOADED_EXT'];
56
57 $className = self::buildAccessibleProxy('ux_t3lib_db');
58 $this->fixture = new $className;
59 }
60
61 /**
62 * Cleans up the environment after running a test.
63 */
64 public function tearDown() {
65 // Clear DBAL-generated cache files
66 $this->fixture->clearCachedFieldInfo();
67 unset($this->fixture);
68 // Restore list of loaded extensions
69 $GLOBALS['TYPO3_LOADED_EXT'] = $this->loadedExtensions;
70 }
71
72 /**
73 * Cleans a SQL query.
74 *
75 * @param mixed $sql
76 * @return mixed (string or array)
77 */
78 private function cleanSql($sql) {
79 if (!is_string($sql)) {
80 return $sql;
81 }
82
83 $sql = str_replace("\n", ' ', $sql);
84 $sql = preg_replace('/\s+/', ' ', $sql);
85 return $sql;
86 }
87
88 /**
89 * @test
90 * @see http://bugs.typo3.org/view.php?id=12515
91 */
92 public function concatCanBeParsedAfterLikeOperator() {
93 $query = $this->cleanSql($this->fixture->SELECTquery(
94 '*',
95 'sys_refindex, tx_dam_file_tracking',
96 'sys_refindex.tablename = \'tx_dam_file_tracking\''
97 . ' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path, tx_dam_file_tracking.file_name)'
98 ));
99 $expected = 'SELECT * FROM sys_refindex, tx_dam_file_tracking WHERE sys_refindex.tablename = \'tx_dam_file_tracking\'';
100 $expected .= ' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path,tx_dam_file_tracking.file_name)';
101 $this->assertEquals($expected, $query);
102 }
103 }
104 ?>