Added unit test for bug #11093: bigint (int8) values get converted to int4 by int...
[Packages/TYPO3.CMS.git] / typo3 / sysext / dbal / tests / db_general_testcase.php
index 8dcde8c..c5fbe66 100644 (file)
@@ -38,24 +38,33 @@ require_once('BaseTestCase.php');
 class db_general_testcase extends BaseTestCase {
 
        /**
-        * @var ux_t3lib_db (extended to make protected methods public)
+        * @var t3lib_db
         */
-       protected $fixture;
+       protected $db;
 
        /**
         * @var array
         */
        protected $loadedExtensions;
 
+       /** 
+        * @var array
+        */
+       protected $temporaryFiles;
+
        /**
         * Prepares the environment before running a test.
         */
        public function setUp() {
                        // Backup list of loaded extensions
                $this->loadedExtensions = $GLOBALS['TYPO3_LOADED_EXT'];
+                       // Backup database connection
+               $this->db = $GLOBALS['TYPO3_DB'];
+               $this->temporaryFiles = array();
 
                $className =  self::buildAccessibleProxy('ux_t3lib_db');
-               $this->fixture = new $className;
+               $GLOBALS['TYPO3_DB'] = new $className;
+               $GLOBALS['TYPO3_DB']->lastHandlerKey = '_DEFAULT';
        }
 
        /**
@@ -63,8 +72,11 @@ class db_general_testcase extends BaseTestCase {
         */
        public function tearDown() {
                        // Clear DBAL-generated cache files
-               $this->fixture->clearCachedFieldInfo();
-               unset($this->fixture);
+               $GLOBALS['TYPO3_DB']->clearCachedFieldInfo();
+                       // Delete temporary files
+               foreach ($this->temporaryFiles as $filename) unlink($filename);
+                       // Restore DB connection
+               $GLOBALS['TYPO3_DB'] = $this->db;
                        // Restore list of loaded extensions
                $GLOBALS['TYPO3_LOADED_EXT'] = $this->loadedExtensions;
        }
@@ -85,54 +97,101 @@ class db_general_testcase extends BaseTestCase {
                return $sql;
        }
 
+       /**
+        * Creates a fake extension with a given table definition.
+        * 
+        * @param string $tableDefinition SQL script to create the extension's tables
+        * @return void
+        */
+       protected function createFakeExtension($tableDefinition) {
+                       // Prepare a fake extension configuration
+               $ext_tables = t3lib_div::tempnam('ext_tables');
+               t3lib_div::writeFile($ext_tables, $tableDefinition);
+               $this->temporaryFiles[] = $ext_tables;
+
+               $GLOBALS['TYPO3_LOADED_EXT']['test_dbal'] = array(
+                       'ext_tables.sql' => $ext_tables
+               );
+
+                       // Append our test table to the list of existing tables
+               $GLOBALS['TYPO3_DB']->clearCachedFieldInfo();
+               $GLOBALS['TYPO3_DB']->_call('initInternalVariables');
+       }
+
        /**
         * @test
         * @see http://bugs.typo3.org/view.php?id=12515
         */
        public function concatCanBeParsedAfterLikeOperator() {
-               $query = $this->cleanSql($this->fixture->SELECTquery(
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->SELECTquery(
                        '*',
                        'sys_refindex, tx_dam_file_tracking',
                        'sys_refindex.tablename = \'tx_dam_file_tracking\''
                        . ' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path, tx_dam_file_tracking.file_name)'
                ));
                $expected = 'SELECT * FROM sys_refindex, tx_dam_file_tracking WHERE sys_refindex.tablename = \'tx_dam_file_tracking\'';
-               $expected .= ' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path,tx_dam_file_tracking.file_name)';
+               $expected .= ' AND sys_refindex.ref_string LIKE CONCAT(tx_dam_file_tracking.file_path, tx_dam_file_tracking.file_name)';
                $this->assertEquals($expected, $query);
        }
 
-       /** 
+       /**
         * @test
         * @see http://bugs.typo3.org/view.php?id=10965
         */
        public function floatNumberCanBeStoredInDatabase() {
-                       // Prepare a fake extension configuration
-               $ext_tables = t3lib_div::tempnam('ext_tables');
-               t3lib_div::writeFile($ext_tables, '
+               $this->createFakeExtension('
                        CREATE TABLE tx_test_dbal (
                                foo double default \'0\',
                                foobar integer default \'0\'
                        );
                ');
-
-               $GLOBALS['TYPO3_LOADED_EXT']['test_dbal'] = array(
-                       'ext_tables.sql' => $ext_tables
-               );
-
-                       // Append our test table to the list of existing tables
-               $this->fixture->clearCachedFieldInfo();
-               $this->fixture->_call('initInternalVariables');
-
                $data = array(
                        'foo'    => 99.12,
                        'foobar' => -120,
                );
-               $query = $this->cleanSql($this->fixture->INSERTquery('tx_test_dbal', $data));
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->INSERTquery('tx_test_dbal', $data));
                $expected = 'INSERT INTO tx_test_dbal ( foo, foobar ) VALUES ( \'99.12\', \'-120\' )';
                $this->assertEquals($expected, $query);
+       }
+
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=11093
+        */
+       public function positive64BitIntegerIsSupported() {
+               $this->createFakeExtension('
+                       CREATE TABLE tx_test_dbal (
+                               foo int default \'0\',
+                               foobar bigint default \'0\'
+                       );
+               ');
+               $data = array(
+                       'foo'    => 9223372036854775807,
+                       'foobar' => 9223372036854775807,
+               );
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->INSERTquery('tx_test_dbal', $data));
+               $expected = 'INSERT INTO tx_test_dbal ( foo, foobar ) VALUES ( \'9223372036854775807\', \'9223372036854775807\' )';
+               $this->assertEquals($expected, $query);
+       }
 
-                       // Remove temporary file
-               unlink($ext_tables);
+       /**
+        * @test
+        * @see http://bugs.typo3.org/view.php?id=11093
+        */
+       public function negative64BitIntegerIsSupported() {
+               $this->createFakeExtension('
+                       CREATE TABLE tx_test_dbal (
+                               foo int default \'0\',
+                               foobar bigint default \'0\'
+                       );
+               ');
+               $data = array(
+                       'foo'    => -9223372036854775808,
+                       'foobar' => -9223372036854775808,
+               );
+               $query = $this->cleanSql($GLOBALS['TYPO3_DB']->INSERTquery('tx_test_dbal', $data));
+               $expected = 'INSERT INTO tx_test_dbal ( foo, foobar ) VALUES ( \'-9223372036854775808\', \'-9223372036854775808\' )';
+               $this->assertEquals($expected, $query);
        }
 }
 ?>
\ No newline at end of file