From 0b20c47a5e4af17e238ee0d97731464f016353c1 Mon Sep 17 00:00:00 2001
From: Christian Kuhn <lolli@schwarzbu.ch>
Date: Tue, 10 Aug 2010 11:44:06 +0000
Subject: [PATCH] Follow-up to feature #15141: Add tests to t3lib_db to test
 storing of binary data (Thanks to Steffen Kamper)

git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@8552 709f56b5-9817-0410-a4d7-c38de5d9e867
---
 ChangeLog                    |  1 +
 tests/t3lib/t3lib_dbTest.php | 79 ++++++++++++++++++++++++++++++++++--
 2 files changed, 77 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a49931ceb1b2..e3156571f912 100755
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2010-08-10  Christian Kuhn  <lolli@schwarzbu.ch>
 
+	* Follow-up to feature #15141: Add tests to t3lib_db to test storing of binary data (Thanks to Steffen Kamper)
 	* Added feature #15141: [Caching framework] Add compress data options to DbBackend
 	* Fixed bug #15383: [Unit tests] Add tests for t3lib_div::validEmail
 	* Fixed bug #15382: [Unit tests] Streamline and refactor t3lib_divTest
diff --git a/tests/t3lib/t3lib_dbTest.php b/tests/t3lib/t3lib_dbTest.php
index c49b718665fa..78ba48c7ab9f 100644
--- a/tests/t3lib/t3lib_dbTest.php
+++ b/tests/t3lib/t3lib_dbTest.php
@@ -23,7 +23,7 @@
 ***************************************************************/
 
 /**
- * Testcase for the t3lib_cs class in the TYPO3 Core.
+ * Testcase for the t3lib_db class in the TYPO3 Core.
  *
  * @package TYPO3
  * @subpackage t3lib
@@ -34,17 +34,90 @@ class t3lib_dbTest extends tx_phpunit_testcase {
 	/**
 	 * @var t3lib_db
 	 */
-	private $fixture = null;
+	private $fixture = NULL;
+
+	private $testTable;
 
 	public function setUp() {
-		$this->fixture = new t3lib_db();
+		$this->fixture = $GLOBALS['TYPO3_DB'];
+
+		$this->testTable = 'test_t3lib_dbtest';
+
+		$this->fixture->sql_query('CREATE TABLE ' . $this->testTable . ' (
+			id int(11) unsigned NOT NULL auto_increment,
+			fieldblob mediumblob,
+			PRIMARY KEY (id)
+		) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+		');
 	}
 
 	public function tearDown() {
+		$this->fixture->sql_query(
+			'DROP TABLE ' . $this->testTable . ';'
+		);
+
 		unset($this->fixture);
 	}
 
 
+	//////////////////////////////////////////////////
+	// Write/Read tests for charsets and binaries
+	//////////////////////////////////////////////////
+
+	/**
+	 * @test
+	 */
+	public function storedFullAsciiRangeReturnsSameData() {
+		$binaryString = '';
+		for ($i = 0; $i < 256; $i ++) {
+			$binaryString .= chr($i);
+		}
+		
+		$this->fixture->exec_INSERTquery(
+			$this->testTable,
+			array('fieldblob' => $binaryString)
+		);
+
+		$id = $this->fixture->sql_insert_id();
+
+		$entry = $this->fixture->exec_SELECTgetRows(
+			'fieldblob',
+			$this->testTable,
+			'id = ' . $id
+		);
+
+		$this->assertEquals(
+			$binaryString,
+			$entry[0]['fieldblob']
+		);
+	}
+
+	/**
+	 * @test
+	 */
+	public function storedGzipCompressedDataReturnsSameData() {
+		$testStringWithBinary = @gzcompress('sdfkljer4587');
+
+		$this->fixture->exec_INSERTquery(
+			$this->testTable,
+			array('fieldblob' => $testStringWithBinary)
+		);
+
+		$id = $this->fixture->sql_insert_id();
+
+		$entry = $this->fixture->exec_SELECTgetRows(
+			'fieldblob',
+			$this->testTable,
+			'id = ' . $id
+		);
+
+		$this->assertEquals(
+			$testStringWithBinary,
+			$entry[0]['fieldblob']
+		);
+	}
+
+
 	////////////////////////////////
 	// Tests concerning listQuery
 	////////////////////////////////
-- 
GitLab