TYPO3 API  SVNRelease
t3lib_dbTest.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 * Copyright notice
00004 *
00005 * (c) 2010-2011 Ernesto Baschny (ernst@cron-it.de)
00006 * All rights reserved
00007 *
00008 * This script is part of the TYPO3 project. The TYPO3 project is
00009 * free software; you can redistribute it and/or modify
00010 * it under the terms of the GNU General Public License as published by
00011 * the Free Software Foundation; either version 2 of the License, or
00012 * (at your option) any later version.
00013 *
00014 * The GNU General Public License can be found at
00015 * http://www.gnu.org/copyleft/gpl.html.
00016 *
00017 * This script is distributed in the hope that it will be useful,
00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 * GNU General Public License for more details.
00021 *
00022 * This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 /**
00026  * Testcase for the t3lib_db class in the TYPO3 Core.
00027  *
00028  * @package TYPO3
00029  * @subpackage t3lib
00030  *
00031  * @author Ernesto Baschny <ernst@cron-it.de>
00032  */
00033 class t3lib_dbTest extends tx_phpunit_testcase {
00034     /**
00035      * @var t3lib_db
00036      */
00037     private $fixture = NULL;
00038 
00039     private $testTable;
00040 
00041     public function setUp() {
00042         $this->fixture = $GLOBALS['TYPO3_DB'];
00043 
00044         $this->testTable = 'test_t3lib_dbtest';
00045 
00046         $this->fixture->sql_query('CREATE TABLE ' . $this->testTable . ' (
00047             id int(11) unsigned NOT NULL auto_increment,
00048             fieldblob mediumblob,
00049             PRIMARY KEY (id)
00050         ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
00051         ');
00052     }
00053 
00054     public function tearDown() {
00055         $this->fixture->sql_query(
00056             'DROP TABLE ' . $this->testTable . ';'
00057         );
00058 
00059         unset($this->fixture);
00060     }
00061 
00062 
00063     //////////////////////////////////////////////////
00064     // Write/Read tests for charsets and binaries
00065     //////////////////////////////////////////////////
00066 
00067     /**
00068      * @test
00069      */
00070     public function storedFullAsciiRangeReturnsSameData() {
00071         $binaryString = '';
00072         for ($i = 0; $i < 256; $i ++) {
00073             $binaryString .= chr($i);
00074         }
00075         
00076         $this->fixture->exec_INSERTquery(
00077             $this->testTable,
00078             array('fieldblob' => $binaryString)
00079         );
00080 
00081         $id = $this->fixture->sql_insert_id();
00082 
00083         $entry = $this->fixture->exec_SELECTgetRows(
00084             'fieldblob',
00085             $this->testTable,
00086             'id = ' . $id
00087         );
00088 
00089         $this->assertEquals(
00090             $binaryString,
00091             $entry[0]['fieldblob']
00092         );
00093     }
00094 
00095     /**
00096      * @test
00097      */
00098     public function storedGzipCompressedDataReturnsSameData() {
00099         $testStringWithBinary = @gzcompress('sdfkljer4587');
00100 
00101         $this->fixture->exec_INSERTquery(
00102             $this->testTable,
00103             array('fieldblob' => $testStringWithBinary)
00104         );
00105 
00106         $id = $this->fixture->sql_insert_id();
00107 
00108         $entry = $this->fixture->exec_SELECTgetRows(
00109             'fieldblob',
00110             $this->testTable,
00111             'id = ' . $id
00112         );
00113 
00114         $this->assertEquals(
00115             $testStringWithBinary,
00116             $entry[0]['fieldblob']
00117         );
00118     }
00119 
00120 
00121     ////////////////////////////////
00122     // Tests concerning listQuery
00123     ////////////////////////////////
00124 
00125     /**
00126      * @test
00127      *
00128      * @see http://bugs.typo3.org/view.php?id=15211
00129      */
00130     public function listQueryWithIntegerCommaAsValue() {
00131             // Note: 44 = ord(',')
00132         $this->assertEquals(
00133             $this->fixture->listQuery('dummy', 44, 'table'),
00134             $this->fixture->listQuery('dummy', '44', 'table')
00135         );
00136     }
00137 
00138 
00139     /////////////////////////////////////////////////
00140     // Tests concerning escapeStringForLikeComparison
00141     /////////////////////////////////////////////////
00142 
00143     /**
00144      * @test
00145      */
00146     public function escapeStringForLikeComparison() {
00147         $this->assertEquals(
00148             'foo\_bar\%',
00149             $this->fixture->escapeStrForLike('foo_bar%', 'table')
00150         );
00151     }
00152 }
00153 ?>