Fixed bug #14997: Performance: t3lib_db->escapeStrForLike() is using preg_replace...
[Packages/TYPO3.CMS.git] / tests / t3lib / t3lib_dbTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010 Ernesto Baschny (ernst@cron-it.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 the t3lib_db class in the TYPO3 Core.
27 *
28 * @package TYPO3
29 * @subpackage t3lib
30 *
31 * @author Ernesto Baschny <ernst@cron-it.de>
32 */
33 class t3lib_dbTest extends tx_phpunit_testcase {
34 /**
35 * @var t3lib_db
36 */
37 private $fixture = NULL;
38
39 private $testTable;
40
41 public function setUp() {
42 $this->fixture = $GLOBALS['TYPO3_DB'];
43
44 $this->testTable = 'test_t3lib_dbtest';
45
46 $this->fixture->sql_query('CREATE TABLE ' . $this->testTable . ' (
47 id int(11) unsigned NOT NULL auto_increment,
48 fieldblob mediumblob,
49 PRIMARY KEY (id)
50 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
51 ');
52 }
53
54 public function tearDown() {
55 $this->fixture->sql_query(
56 'DROP TABLE ' . $this->testTable . ';'
57 );
58
59 unset($this->fixture);
60 }
61
62
63 //////////////////////////////////////////////////
64 // Write/Read tests for charsets and binaries
65 //////////////////////////////////////////////////
66
67 /**
68 * @test
69 */
70 public function storedFullAsciiRangeReturnsSameData() {
71 $binaryString = '';
72 for ($i = 0; $i < 256; $i ++) {
73 $binaryString .= chr($i);
74 }
75
76 $this->fixture->exec_INSERTquery(
77 $this->testTable,
78 array('fieldblob' => $binaryString)
79 );
80
81 $id = $this->fixture->sql_insert_id();
82
83 $entry = $this->fixture->exec_SELECTgetRows(
84 'fieldblob',
85 $this->testTable,
86 'id = ' . $id
87 );
88
89 $this->assertEquals(
90 $binaryString,
91 $entry[0]['fieldblob']
92 );
93 }
94
95 /**
96 * @test
97 */
98 public function storedGzipCompressedDataReturnsSameData() {
99 $testStringWithBinary = @gzcompress('sdfkljer4587');
100
101 $this->fixture->exec_INSERTquery(
102 $this->testTable,
103 array('fieldblob' => $testStringWithBinary)
104 );
105
106 $id = $this->fixture->sql_insert_id();
107
108 $entry = $this->fixture->exec_SELECTgetRows(
109 'fieldblob',
110 $this->testTable,
111 'id = ' . $id
112 );
113
114 $this->assertEquals(
115 $testStringWithBinary,
116 $entry[0]['fieldblob']
117 );
118 }
119
120
121 ////////////////////////////////
122 // Tests concerning listQuery
123 ////////////////////////////////
124
125 /**
126 * @test
127 *
128 * @see http://bugs.typo3.org/view.php?id=15211
129 */
130 public function listQueryWithIntegerCommaAsValue() {
131 // Note: 44 = ord(',')
132 $this->assertEquals(
133 $this->fixture->listQuery('dummy', 44, 'table'),
134 $this->fixture->listQuery('dummy', '44', 'table')
135 );
136 }
137
138
139 /////////////////////////////////////////////////
140 // Tests concerning escapeStringForLikeComparison
141 /////////////////////////////////////////////////
142
143 /**
144 * @test
145 */
146 public function escapeStringForLikeComparison() {
147 $this->assertEquals(
148 'foo\_bar\%',
149 $this->fixture->escapeStrForLike('foo_bar%', 'table')
150 );
151 }
152 }
153 ?>