[TASK] Namespace and move t3lib unit tests - 3 68/14168/2
authorWouter Wolters <typo3@wouterwolters.nl>
Tue, 28 Aug 2012 18:49:19 +0000 (20:49 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 28 Aug 2012 19:21:38 +0000 (21:21 +0200)
This patch moves most unit tests of the tests/Unit/t3lib/*
directory to the core extension, following the new name scheme.

Change-Id: Icff5a0ad820914e225e8c60b323aa68e99461840
Resolves: #40355
Related: #40095
Releases: 6.0

24 files changed:
tests/Unit/t3lib/category/Collection/CategoryCollectionTest.php [deleted file]
tests/Unit/t3lib/category/RegistryTest.php [deleted file]
tests/Unit/t3lib/codec/t3lib_codec_javascriptencoderTest.php [deleted file]
tests/Unit/t3lib/collection/RecordCollectionRepositoryTest.php [deleted file]
tests/Unit/t3lib/db/class.t3lib_db_preparedstatementTest.php [deleted file]
tests/Unit/t3lib/error/class.t3lib_error_debugexceptionhandlerTest.php [deleted file]
tests/Unit/t3lib/error/class.t3lib_error_productionexceptionhandlerTest.php [deleted file]
tests/Unit/t3lib/formprotection/class.t3lib_formprotection_AbstractTest.php [deleted file]
tests/Unit/t3lib/formprotection/class.t3lib_formprotection_BackendFormProtectionTest.php [deleted file]
tests/Unit/t3lib/formprotection/class.t3lib_formprotection_FactoryTest.php [deleted file]
tests/Unit/t3lib/formprotection/class.t3lib_formprotection_InstallToolFormProtectionTest.php [deleted file]
tests/Unit/t3lib/formprotection/fixtures/class.t3lib_formprotection_testing.php [deleted file]
typo3/sysext/core/Tests/Unit/Category/CategoryRegistryTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Category/Collection/CategoryCollectionTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Collection/RecordCollectionRepositoryTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Database/PreparedStatementTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Encoder/JavaScriptEncoderTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Error/DebugExceptionHandlerTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Error/ProductionExceptionHandlerTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/FormProtection/AbstractFormProtectionTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/FormProtection/BackendFormProtectionTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/FormProtection/Fixtures/FormProtectionTesting.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/FormProtection/FormProtectionFactoryTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/FormProtection/InstallToolFormProtectionTest.php [new file with mode: 0644]

diff --git a/tests/Unit/t3lib/category/Collection/CategoryCollectionTest.php b/tests/Unit/t3lib/category/Collection/CategoryCollectionTest.php
deleted file mode 100644 (file)
index ce60097..0000000
+++ /dev/null
@@ -1,301 +0,0 @@
-<?php
-/**
- * Test case for t3lib_category_CategoryCollection
- *
- * @package TYPO3
- * @subpackage t3lib
- * @author Fabine Udriot <fabien.udriot@typo3.org>
- */
-class t3lib_category_CategoryCollectionTest extends Tx_Phpunit_TestCase {
-
-       /**
-        * @var \TYPO3\CMS\Core\Category\Collection\CategoryCollection
-        */
-       private $fixture;
-
-       /**
-        * @var string
-        */
-       private $tableName = 'tx_foo_5001615c50bed';
-
-       /**
-        * @var array
-        */
-       private $tables = array('sys_category', 'sys_category_record_mm');
-
-       /**
-        * @var int
-        */
-       private $categoryUid = 0;
-
-       /**
-        * @var array
-        */
-       private $collectionRecord = array();
-
-       /**
-        * @var Tx_Phpunit_Framework
-        */
-       private $testingFramework;
-
-       /**
-        * @var \TYPO3\CMS\Core\Database\DatabaseConnection
-        */
-       private $database;
-
-       /**
-        * Sets up this test suite.
-        *
-        * @return void
-        */
-       public function setUp() {
-               $this->database = $GLOBALS['TYPO3_DB'];
-               $this->fixture = new \TYPO3\CMS\Core\Category\Collection\CategoryCollection($this->tableName);
-               $this->collectionRecord = array(
-                       'uid' => 0,
-                       'title' => uniqid('title'),
-                       'description' => uniqid('description'),
-                       'table_name' => $this->tableName,
-               );
-               $GLOBALS['TCA'][$this->tableName] = array('ctrl' => array());
-               // prepare environment
-               $this->createDummyTable();
-               $this->testingFramework = new Tx_Phpunit_Framework('sys_category', array('tx_foo'));
-               $this->populateDummyTable();
-               $this->prepareTables();
-               $this->makeRelationBetweenCategoryAndDummyTable();
-       }
-
-       /**
-        * Tears down this test suite.
-        *
-        * @return void
-        */
-       public function tearDown() {
-               $this->testingFramework->cleanUp();
-               // clean up environment
-               $this->dropDummyTable();
-               $this->dropDummyField();
-               unset($this->testingFramework);
-               unset($this->collectionRecord);
-               unset($this->fixture);
-               unset($this->database);
-       }
-
-       /**
-        * @test
-        * @expectedException RuntimeException
-        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::__construct
-        * @return void
-        */
-       public function missingTableNameArgumentForObjectCategoryCollection() {
-               new \TYPO3\CMS\Core\Category\Collection\CategoryCollection();
-       }
-
-       /**
-        * @test
-        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::fromArray
-        * @return void
-        */
-       public function checkIfFromArrayMethodSetCorrectProperties() {
-               $this->fixture->fromArray($this->collectionRecord);
-               $this->assertEquals($this->collectionRecord['uid'], $this->fixture->getIdentifier());
-               $this->assertEquals($this->collectionRecord['uid'], $this->fixture->getUid());
-               $this->assertEquals($this->collectionRecord['title'], $this->fixture->getTitle());
-               $this->assertEquals($this->collectionRecord['description'], $this->fixture->getDescription());
-               $this->assertEquals($this->collectionRecord['table_name'], $this->fixture->getItemTableName());
-       }
-
-       /**
-        * @test
-        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::create
-        * @return void
-        */
-       public function canCreateDummyCollection() {
-               $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::create($this->collectionRecord);
-               $this->assertInstanceOf('\TYPO3\CMS\Core\Category\Collection\CategoryCollection', $collection);
-       }
-
-       /**
-        * @test
-        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::create
-        * @return void
-        */
-       public function canCreateDummyCollectionAndFillItems() {
-               $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::create($this->collectionRecord, TRUE);
-               $this->assertInstanceOf('\TYPO3\CMS\Core\Category\Collection\CategoryCollection', $collection);
-       }
-
-       /**
-        * @test
-        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getCollectedRecords
-        * @return void
-        */
-       public function getCollectedRecordsReturnsEmptyRecordSet() {
-               $method = new ReflectionMethod('TYPO3\\CMS\\Core\\Category\\Collection\\CategoryCollection', 'getCollectedRecords');
-               $method->setAccessible(TRUE);
-               $records = $method->invoke($this->fixture);
-               $this->assertInternalType('array', $records);
-               $this->assertEmpty($records);
-       }
-
-       /**
-        * @test
-        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getStorageTableName
-        * @return void
-        */
-       public function isStorageTableNameEqualsToSysCategory() {
-               $this->assertEquals('sys_category', \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getStorageTableName());
-       }
-
-       /**
-        * @test
-        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getStorageItemsField
-        * @return void
-        */
-       public function isStorageItemsFieldEqualsToItems() {
-               $this->assertEquals('items', \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getStorageItemsField());
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function canLoadADummyCollectionFromDatabase() {
-               /** @var $collection \TYPO3\CMS\Core\Category\Collection\CategoryCollection */
-               $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, TRUE, $this->tableName);
-               // Check the number of record
-               $this->assertEquals($this->numberOfRecords, $collection->count());
-               // Check that the first record is the one expected
-               $record = $this->database->exec_SELECTgetSingleRow('*', $this->tableName, 'uid=1');
-               $collection->rewind();
-               $this->assertEquals($record, $collection->current());
-               // Add a new record
-               $fakeRecord = array(
-                       'uid' => $this->numberOfRecords + 1,
-                       'pid' => 0,
-                       'title' => uniqid('title'),
-                       'categories' => 0
-               );
-               // Check the number of records
-               $collection->add($fakeRecord);
-               $this->assertEquals($this->numberOfRecords + 1, $collection->count());
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function canLoadADummyCollectionFromDatabaseAndAddRecord() {
-               $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, TRUE, $this->tableName);
-               // Add a new record
-               $fakeRecord = array(
-                       'uid' => $this->numberOfRecords + 1,
-                       'pid' => 0,
-                       'title' => uniqid('title'),
-                       'categories' => 0
-               );
-               // Check the number of records
-               $collection->add($fakeRecord);
-               $this->assertEquals($this->numberOfRecords + 1, $collection->count());
-       }
-
-       /**
-        * @test
-        * @return void
-        */
-       public function canLoadADummyCollectionWithoutContentFromDatabase() {
-               /** @var $collection \TYPO3\CMS\Core\Category\Collection\CategoryCollection */
-               $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, FALSE, $this->tableName);
-               // Check the number of record
-               $this->assertEquals(0, $collection->count());
-       }
-
-       /********************/
-       /* INTERNAL METHODS */
-       /********************/
-       /**
-        * Create dummy table for testing purpose
-        *
-        * @return void
-        */
-       private function populateDummyTable() {
-               $this->numberOfRecords = 5;
-               for ($index = 1; $index <= $this->numberOfRecords; $index++) {
-                       $values = array(
-                               'title' => uniqid('title')
-                       );
-                       $this->testingFramework->createRecord($this->tableName, $values);
-               }
-       }
-
-       /**
-        * Make relation between tables
-        *
-        * @return void
-        */
-       private function makeRelationBetweenCategoryAndDummyTable() {
-               for ($index = 1; $index <= $this->numberOfRecords; $index++) {
-                       $values = array(
-                               'uid_local' => $this->categoryUid,
-                               'uid_foreign' => $index,
-                               'tablenames' => $this->tableName
-                       );
-                       $this->testingFramework->createRecord('sys_category_record_mm', $values);
-               }
-       }
-
-       /**
-        * Create dummy table for testing purpose
-        *
-        * @return void
-        */
-       private function createDummyTable() {
-               $sql = "CREATE TABLE {$this->tableName} (\n\tuid int(11) auto_increment,\n\tpid int(11) unsigned DEFAULT '0' NOT NULL,\n    title tinytext,\n\tcategories int(11) unsigned DEFAULT '0' NOT NULL,\n\tsys_category_is_dummy_record int(11) unsigned DEFAULT '0' NOT NULL,\n\n    PRIMARY KEY (uid)\n);";
-               $this->database->sql_query($sql);
-       }
-
-       /**
-        * Drop dummy table
-        *
-        * @return void
-        */
-       private function dropDummyTable() {
-               $sql = ('DROP TABLE ' . $this->tableName) . ';';
-               $this->database->sql_query($sql);
-       }
-
-       /**
-        * Add is_dummy_record record and create dummy record
-        *
-        * @return void
-        */
-       private function prepareTables() {
-               $sql = 'ALTER TABLE %s ADD is_dummy_record tinyint(1) unsigned DEFAULT \'0\' NOT NULL';
-               foreach ($this->tables as $table) {
-                       $_sql = sprintf($sql, $table);
-                       $this->database->sql_query($_sql);
-               }
-               $values = array(
-                       'title' => uniqid('title'),
-                       'is_dummy_record' => 1
-               );
-               $this->categoryUid = $this->testingFramework->createRecord('sys_category', $values);
-       }
-
-       /**
-        * Remove dummy record and drop field
-        *
-        * @return void
-        */
-       private function dropDummyField() {
-               $sql = 'ALTER TABLE %s DROP COLUMN is_dummy_record';
-               foreach ($this->tables as $table) {
-                       $_sql = sprintf($sql, $table);
-                       $this->database->sql_query($_sql);
-               }
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/category/RegistryTest.php b/tests/Unit/t3lib/category/RegistryTest.php
deleted file mode 100644 (file)
index ab53fa9..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-<?php
-/***************************************************************
- * Copyright notice
- *
- * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-/**
- * Testcase for t3lib_category_Registry
- *
- * @package TYPO3
- * @subpackage t3lib
- * @author Oliver Hader <oliver.hader@typo3.org>
- */
-class t3lib_category_RegistryTest extends Tx_Phpunit_TestCase {
-
-       /**
-        * Enable backup of global and system variables
-        *
-        * @var boolean
-        */
-       protected $backupGlobals = TRUE;
-
-       /**
-        * @var \TYPO3\CMS\Core\Category\CategoryRegistry
-        */
-       protected $fixture;
-
-       /**
-        * @var array
-        */
-       protected $tables;
-
-       /**
-        * Sets up this test suite.
-        */
-       protected function setUp() {
-               $this->fixture = new \TYPO3\CMS\Core\Category\CategoryRegistry();
-               $this->tables = array(
-                       'first' => uniqid('first'),
-                       'second' => uniqid('second')
-               );
-               foreach ($this->tables as $tableName) {
-                       $GLOBALS['TCA'][$tableName] = array('ctrl' => array());
-               }
-       }
-
-       /**
-        * Tears down this test suite.
-        */
-       protected function tearDown() {
-               unset($this->tables);
-               unset($this->fixture);
-       }
-
-       /**
-        * @test
-        */
-       public function isRegistryEmptyByDefault() {
-               $this->assertEquals(array(), $this->fixture->get());
-       }
-
-       /**
-        * @test
-        */
-       public function doesAddReturnTrueOnDefinedTable() {
-               $this->assertTrue($this->fixture->add('test_extension_a', $this->tables['first'], 'categories'));
-       }
-
-       /**
-        * @test
-        */
-       public function doesAddReturnFalseOnUndefinedTable() {
-               $this->assertFalse($this->fixture->add('test_extension_a', uniqid('undefined'), 'categories'));
-       }
-
-       /**
-        * @test
-        */
-       public function areMultipleElementsOfSameExtensionRegistered() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
-               $registry = $this->fixture->get();
-               ob_flush();
-               $this->assertEquals('categories', $registry['test_extension_a'][$this->tables['first']]);
-               $this->assertEquals('categories', $registry['test_extension_b'][$this->tables['second']]);
-       }
-
-       /**
-        * @test
-        */
-       public function areElementsOfDifferentExtensionsRegistered() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
-               $registry = $this->fixture->get();
-               $this->assertEquals('categories', $registry['test_extension_a'][$this->tables['first']]);
-               $this->assertEquals('categories', $registry['test_extension_b'][$this->tables['second']]);
-       }
-
-       /**
-        * @test
-        */
-       public function areElementsOnSameTableOverridden() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], $this->tables['first']);
-               $this->fixture->add('test_extension_b', $this->tables['second'], $this->tables['second']);
-               $registry = $this->fixture->get();
-               $this->assertEquals($this->tables['first'], $registry['test_extension_a'][$this->tables['first']]);
-       }
-
-       /**
-        * @test
-        */
-       public function areDatabaseDefinitionsOfAllElementsAvailable() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
-               $this->fixture->add('test_extension_c', $this->tables['first'], 'categories');
-               $definitions = $this->fixture->getDatabaseTableDefinitions();
-               $matches = array();
-               preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
-               $this->assertEquals(2, count($matches[0]));
-               $this->assertEquals($matches[1][0], $this->tables['first']);
-               $this->assertEquals($matches[2][0], 'categories');
-               $this->assertEquals($matches[1][1], $this->tables['second']);
-               $this->assertEquals($matches[2][1], 'categories');
-       }
-
-       /**
-        * @test
-        */
-       public function areDatabaseDefinitionsOfParticularExtensionAvailable() {
-               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
-               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
-               $definitions = $this->fixture->getDatabaseTableDefinition('test_extension_a');
-               $matches = array();
-               preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
-               $this->assertEquals(1, count($matches[0]));
-               $this->assertEquals($matches[1][0], $this->tables['first']);
-               $this->assertEquals($matches[2][0], 'categories');
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/codec/t3lib_codec_javascriptencoderTest.php b/tests/Unit/t3lib/codec/t3lib_codec_javascriptencoderTest.php
deleted file mode 100644 (file)
index 9d6db79..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/***************************************************************
- * Copyright notice
- *
- * (c) 2012 Helmut Hummel <helmut.hummel@typo3.org>
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-/**
- * Test cases for t3lib_codec_JavaScriptEncoder.
- *
- * @package TYPO3
- * @subpackage t3lib
- * @author Helmut Hummel <helmut.hummel@typo3.org>
- */
-class t3lib_codec_JavaScriptEncoderTest extends Tx_Phpunit_TestCase {
-
-       /**
-        * @var \TYPO3\CMS\Core\Encoder\JavaScriptEncoder
-        */
-       protected $fixture = NULL;
-
-       public function setUp() {
-               $this->fixture = new \TYPO3\CMS\Core\Encoder\JavaScriptEncoder();
-       }
-
-       public function tearDown() {
-               unset($this->fixture);
-       }
-
-       /**
-        * Data provider for encodeEncodesCorrectly.
-        *
-        * @return array
-        */
-       public function encodeEncodesCorrectlyDataProvider() {
-               return array(
-                       'Immune characters are returned as is' => array(
-                               '._,',
-                               '._,'
-                       ),
-                       'Alphanumerical characters are returned as is' => array(
-                               'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
-                               'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
-                       ),
-                       'Angel brackets and ampersand are encoded' => array(
-                               '<>&',
-                               '\\x3C\\x3E\\x26'
-                       ),
-                       'Quotes and slashes are encoded' => array(
-                               '"\'\\/',
-                               '\\x22\\x27\\x5C\\x2F'
-                       ),
-                       'Empty string stays empty' => array(
-                               '',
-                               ''
-                       ),
-                       'Exclamation mark and space are properly encoded' => array(
-                               'Hello World!',
-                               'Hello\\x20World\\x21'
-                       ),
-                       'Whitespaces are properly encoded' => array(
-                               ((TAB . LF) . CR) . ' ',
-                               '\\x09\\x0A\\x0D\\x20'
-                       ),
-                       'Null byte is properly encoded' => array(
-                               chr(0),
-                               '\\x00'
-                       ),
-                       'Umlauts are properly encoded' => array(
-                               'ÜüÖöÄä',
-                               '\\xDC\\xFC\\xD6\\xF6\\xC4\\xE4'
-                       )
-               );
-       }
-
-       /**
-        * @test
-        * @param string $input
-        * @param string  $expected
-        * @dataProvider encodeEncodesCorrectlyDataProvider
-        */
-       public function encodeEncodesCorrectly($input, $expected) {
-               $this->assertSame($expected, $this->fixture->encode($input));
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/collection/RecordCollectionRepositoryTest.php b/tests/Unit/t3lib/collection/RecordCollectionRepositoryTest.php
deleted file mode 100644 (file)
index 9445f51..0000000
+++ /dev/null
@@ -1,263 +0,0 @@
-<?php
-/***************************************************************
- * Copyright notice
- *
- * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- * A copy is found in the textfile GPL.txt and important notices to the license
- * from the author is found in LICENSE.txt distributed with these scripts.
- *
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-/**
- * Test case for t3lib_collection_RecordCollectionRepository
- *
- * @author Oliver Hader <oliver.hader@typo3.org>
- * @package TYPO3
- * @subpackage t3lib
- */
-class t3lib_collection_RecordCollectionRepositoryTest extends Tx_Phpunit_TestCase {
-
-       /**
-        * @var PHPUnit_Framework_MockObject_MockObject|t3lib_collection_RecordCollectionRepository
-        */
-       protected $fixture;
-
-       /**
-        * @var PHPUnit_Framework_MockObject_MockObject|t3lib_DB
-        */
-       protected $databaseMock;
-
-       /**
-        * @var NULL|array
-        */
-       protected $getSingleRowCallbackReturnValue;
-
-       /**
-        * @var NULL|array
-        */
-       protected $getRowsCallbackReturnValue;
-
-       /**
-        * @var string
-        */
-       protected $testTableName;
-
-       /**
-        * Sets up this test case.
-        */
-       protected function setUp() {
-               $this->databaseMock = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_UPDATEquery', 'exec_SELECTgetSingleRow', 'exec_SELECTgetRows'));
-               $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Collection\\RecordCollectionRepository', array('getDatabase'));
-               $this->fixture->expects($this->any())->method('getDatabase')->will($this->returnValue($this->databaseMock));
-               $this->testTableName = uniqid('tx_testtable');
-       }
-
-       /**
-        * Cleans up this test case.
-        */
-       protected function tearDown() {
-               unset($this->databaseMock);
-               unset($this->fixture);
-               unset($this->getSingleRowCallbackReturnValue);
-               unset($this->getRowsCallbackReturnValue);
-               unset($this->testTableName);
-       }
-
-       /**
-        * @test
-        */
-       public function doesFindByUidReturnNull() {
-               $testUid = rand(1, 1000);
-               $this->databaseMock->expects($this->once())->method('exec_SELECTgetSingleRow')->will($this->returnCallback(array($this, 'getSingleRowCallback')));
-               $this->getSingleRowCallbackReturnValue = NULL;
-               $object = $this->fixture->findByUid($testUid);
-               $this->assertNull($object);
-       }
-
-       /**
-        * @test
-        */
-       public function doesFindByUidReturnObject() {
-               $testUid = rand(1, 1000);
-               $this->databaseMock->expects($this->once())->method('exec_SELECTgetSingleRow')->will($this->returnCallback(array($this, 'getSingleRowCallback')));
-               $this->getSingleRowCallbackReturnValue = array(
-                       'uid' => $testUid,
-                       'type' => \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static,
-                       'table_name' => $this->testTableName
-               );
-               $object = $this->fixture->findByUid($testUid);
-               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $object);
-       }
-
-       /**
-        * @test
-        * @expectedException RuntimeException
-        */
-       public function doesFindByUidThrowException() {
-               $testUid = rand(1, 1000);
-               $this->databaseMock->expects($this->once())->method('exec_SELECTgetSingleRow')->will($this->returnCallback(array($this, 'getSingleRowCallback')));
-               $this->getSingleRowCallbackReturnValue = array(
-                       'uid' => $testUid,
-                       'type' => uniqid('unknown')
-               );
-               $object = $this->fixture->findByUid($testUid);
-       }
-
-       /**
-        * @test
-        */
-       public function doesFindByTypeReturnNull() {
-               $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static;
-               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
-               $this->getRowsCallbackReturnValue = NULL;
-               $objects = $this->fixture->findByType($type);
-               $this->assertNull($objects);
-       }
-
-       /**
-        * @test
-        */
-       public function doesFindByTypeReturnObjects() {
-               $testUid = rand(1, 1000);
-               $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static;
-               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
-               $this->getRowsCallbackReturnValue = array(
-                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName),
-                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName)
-               );
-               $objects = $this->fixture->findByType($type);
-               $this->assertEquals(2, count($objects));
-               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[0]);
-               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[1]);
-       }
-
-       /**
-        * @test
-        */
-       public function doesFindByTableNameReturnNull() {
-               $testTable = uniqid('sys_collection_');
-               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
-               $this->getRowsCallbackReturnValue = NULL;
-               $objects = $this->fixture->findByTableName($testTable);
-               $this->assertNull($objects);
-       }
-
-       /**
-        * @test
-        */
-       public function doesFindByTableNameReturnObjects() {
-               $testUid = rand(1, 1000);
-               $testTable = uniqid('sys_collection_');
-               $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static;
-               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
-               $this->getRowsCallbackReturnValue = array(
-                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName),
-                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName)
-               );
-               $objects = $this->fixture->findByTableName($testTable);
-               $this->assertEquals(2, count($objects));
-               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[0]);
-               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[1]);
-       }
-
-       /**
-        * @test
-        */
-       public function doesFindByTypeAndTableNameReturnNull() {
-               $testTable = uniqid('sys_collection_');
-               $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static;
-               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
-               $this->getRowsCallbackReturnValue = NULL;
-               $objects = $this->fixture->findByTypeAndTableName($type, $testTable);
-               $this->assertNull($objects);
-       }
-
-       /**
-        * @test
-        */
-       public function doesFindByTypeAndTableNameReturnObjects() {
-               $testUid = rand(1, 1000);
-               $testTable = uniqid('sys_collection_');
-               $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static;
-               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
-               $this->getRowsCallbackReturnValue = array(
-                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName),
-                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName)
-               );
-               $objects = $this->fixture->findByTypeAndTableName($type, $testTable);
-               $this->assertEquals(2, count($objects));
-               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[0]);
-               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[1]);
-       }
-
-       /**
-        * Callback for exec_SELECTgetSingleRow
-        *
-        * @param string $fields
-        * @param string $table
-        * @return NULL|array
-        */
-       public function getSingleRowCallback($fields, $table) {
-               if (!is_array($this->getSingleRowCallbackReturnValue) || $fields === '*') {
-                       $returnValue = $this->getSingleRowCallbackReturnValue;
-               } else {
-                       $returnValue = $this->limitRecordFields($fields, $this->getSingleRowCallbackReturnValue);
-               }
-               return $returnValue;
-       }
-
-       /**
-        * Callback for exec_SELECTgetRows
-        *
-        * @param string $fields
-        * @param string $table
-        * @return NULL|array
-        */
-       public function getRowsCallback($fields, $table) {
-               if (!is_array($this->getRowsCallbackReturnValue) || $fields === '*') {
-                       $returnValue = $this->getRowsCallbackReturnValue;
-               } else {
-                       $returnValue = array();
-                       foreach ($this->getRowsCallbackReturnValue as $record) {
-                               $returnValue[] = $this->limitRecordFields($fields, $record);
-                       }
-               }
-               return $returnValue;
-       }
-
-       /**
-        * Limits record fields to a given field list.
-        *
-        * @param string $fields List of fields
-        * @param array $record The database record (or the simulated one)
-        * @return array
-        */
-       protected function limitRecordFields($fields, array $record) {
-               $result = array();
-               foreach ($record as $field => $value) {
-                       if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($fields, $field)) {
-                               $result[$field] = $value;
-                       }
-               }
-               return $result;
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/db/class.t3lib_db_preparedstatementTest.php b/tests/Unit/t3lib/db/class.t3lib_db_preparedstatementTest.php
deleted file mode 100644 (file)
index df57e57..0000000
+++ /dev/null
@@ -1,266 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2010-2011 Helmut Hummel <helmut@typo3.org>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-/**
- * Testcase for the prepared statement database class
- *
- * @author     Helmut Hummel <helmut@typo3.org>
- * @package TYPO3
- * @subpackage tests
- */
-class t3lib_db_PreparedStatementTest extends tx_phpunit_testcase {
-
-       /**
-        * Backup and restore of the $GLOBALS array.
-        *
-        * @var boolean
-        */
-       protected $backupGlobalsArray = array();
-
-       /**
-        * Mock object of t3lib_db
-        *
-        * @var PHPUnit_Framework_MockObject_MockObject
-        */
-       private $databaseStub;
-
-       /**
-        * Create a new database mock object for every test
-        * and backup the original global database object.
-        *
-        * @return void
-        */
-       protected function setUp() {
-               $this->backupGlobalsArray['TYPO3_DB'] = $GLOBALS['TYPO3_DB'];
-               $this->databaseStub = $this->setUpAndReturnDatabaseStub();
-       }
-
-       /**
-        * Restore global database object.
-        *
-        * @return void
-        */
-       protected function tearDown() {
-               $GLOBALS['TYPO3_DB'] = $this->backupGlobalsArray['TYPO3_DB'];
-       }
-
-       //////////////////////
-       // Utility functions
-       //////////////////////
-       /**
-        * Set up the stub to be able to get the result of the prepared statement.
-        *
-        * @return PHPUnit_Framework_MockObject_MockObject
-        */
-       private function setUpAndReturnDatabaseStub() {
-               $databaseLink = $GLOBALS['TYPO3_DB']->link;
-               $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_PREPAREDquery'), array(), '', FALSE, FALSE);
-               $GLOBALS['TYPO3_DB']->link = $databaseLink;
-               return $GLOBALS['TYPO3_DB'];
-       }
-
-       /**
-        * Create a object fo the subject to be tested.
-        *
-        * @param string $query
-        * @return \TYPO3\CMS\Core\Database\PreparedStatement
-        */
-       private function createPreparedStatement($query) {
-               return new \TYPO3\CMS\Core\Database\PreparedStatement($query, 'pages');
-       }
-
-       ////////////////////////////////////
-       // Tests for the utility functions
-       ////////////////////////////////////
-       /**
-        * Checks if setUpAndReturnDatabaseStub() really returns
-        * a mock of t3lib_DB.
-        *
-        * @test
-        * @return void
-        */
-       public function setUpAndReturnDatabaseStubReturnsMockObjectOf_t3lib_DB() {
-               $this->assertTrue($this->setUpAndReturnDatabaseStub() instanceof \TYPO3\CMS\Core\Database\DatabaseConnection);
-       }
-
-       /**
-        * Checks if createPreparedStatement() really returns an instance of t3lib_db_PreparedStatement.
-        *
-        * @test
-        * @return void
-        */
-       public function createPreparedStatementReturnsInstanceOfPreparedStatementClass() {
-               $this->assertTrue($this->createPreparedStatement('dummy') instanceof \TYPO3\CMS\Core\Database\PreparedStatement);
-       }
-
-       ///////////////////////////////////////
-       // Tests for t3lib_db_PreparedStatement
-       ///////////////////////////////////////
-       /**
-        * Data Provider for two tests, providing sample queries, parameters and expected result queries.
-        *
-        * @see parametersAreReplacedInQueryByCallingExecute
-        * @see parametersAreReplacedInQueryWhenBoundWithBindValues
-        * @return array
-        */
-       public function parametersAndQueriesDataProvider() {
-               return array(
-                       'one named integer parameter' => array('SELECT * FROM pages WHERE pid=:pid', array(':pid' => 1), 'SELECT * FROM pages WHERE pid=1'),
-                       'one unnamed integer parameter' => array('SELECT * FROM pages WHERE pid=?', array(1), 'SELECT * FROM pages WHERE pid=1'),
-                       'one named integer parameter is replaced multiple times' => array('SELECT * FROM pages WHERE pid=:pid OR uid=:pid', array(':pid' => 1), 'SELECT * FROM pages WHERE pid=1 OR uid=1'),
-                       'two named integer parameters are replaced' => array('SELECT * FROM pages WHERE pid=:pid OR uid=:uid', array(':pid' => 1, ':uid' => 10), 'SELECT * FROM pages WHERE pid=1 OR uid=10'),
-                       'two unnamed integer parameters are replaced' => array('SELECT * FROM pages WHERE pid=? OR uid=?', array(1, 1), 'SELECT * FROM pages WHERE pid=1 OR uid=1'),
-                       'php bool TRUE parameter is replaced with 1' => array('SELECT * FROM pages WHERE deleted=?', array(TRUE), 'SELECT * FROM pages WHERE deleted=1'),
-                       'php bool FALSE parameter is replaced with 0' => array('SELECT * FROM pages WHERE deleted=?', array(FALSE), 'SELECT * FROM pages WHERE deleted=0'),
-                       'php null parameter is replaced with NULL' => array('SELECT * FROM pages WHERE deleted=?', array(NULL), 'SELECT * FROM pages WHERE deleted=NULL'),
-                       'string parameter is wrapped in quotes' => array('SELECT * FROM pages WHERE title=?', array('Foo bar'), 'SELECT * FROM pages WHERE title=\'Foo bar\''),
-                       'number as string parameter is wrapped in quotes' => array('SELECT * FROM pages WHERE title=?', array('12'), 'SELECT * FROM pages WHERE title=\'12\''),
-                       'string single quotes in parameter are properly escaped' => array('SELECT * FROM pages WHERE title=?', array('\'Foo\''), 'SELECT * FROM pages WHERE title=\'\\\'Foo\\\'\''),
-                       'question mark as values with unnamed parameters are properly escaped' => array('SELECT * FROM foo WHERE title=? AND name=?', array('?', 'fancy title'), 'SELECT * FROM foo WHERE title=\'?\' AND name=\'fancy title\''),
-                       'parameter name as value is properly escaped' => array('SELECT * FROM foo WHERE title=:name AND name=:title', array(':name' => ':title', ':title' => 'fancy title'), 'SELECT * FROM foo WHERE title=\':title\' AND name=\'fancy title\''),
-                       'question mark as value of a parameter with a name is properly escaped' => array('SELECT * FROM foo WHERE title=:name AND name=?', array(':name' => '?', 'cool name'), 'SELECT * FROM foo WHERE title=\'?\' AND name=\'cool name\''),
-                       'regular expression back references as values are left untouched' => array('SELECT * FROM foo WHERE title=:name AND name=?', array(':name' => '\\1', '${1}'), 'SELECT * FROM foo WHERE title=\'\\\\1\' AND name=\'${1}\''),
-                       'unsubstituted question marks do not contain the token wrap' => array('SELECT * FROM foo WHERE title=:name AND question LIKE "%what?" AND name=:title', array(':name' => 'Title', ':title' => 'Name'), 'SELECT * FROM foo WHERE title=\'Title\' AND question LIKE "%what?" AND name=\'Name\'')
-               );
-       }
-
-       /**
-        * Checking if calling execute() with parameters, they are
-        * properly relpaced in the query.
-        *
-        * @test
-        * @dataProvider parametersAndQueriesDataProvider
-        * @param string $query                         Query with unreplaced markers
-        * @param array  $parameters            Array of parameters to be replaced in the query
-        * @param string $expectedResult        Query with all markers replaced
-        * @return void
-        */
-       public function parametersAreReplacedInQueryByCallingExecute($query, $parameters, $expectedResult) {
-               $statement = $this->createPreparedStatement($query);
-               $this->databaseStub->expects($this->any())->method('exec_PREPAREDquery')->with($this->equalTo($expectedResult));
-               $statement->execute($parameters);
-       }
-
-       /**
-        * Checking if parameters bound to the statement by bindValues()
-        * are properly replaced in the query.
-        *
-        * @test
-        * @dataProvider parametersAndQueriesDataProvider
-        * @param string $query                         Query with unreplaced markers
-        * @param array  $parameters            Array of parameters to be replaced in the query
-        * @param string $expectedResult        Query with all markers replaced
-        * @return void
-        */
-       public function parametersAreReplacedInQueryWhenBoundWithBindValues($query, $parameters, $expectedResult) {
-               $statement = $this->createPreparedStatement($query);
-               $this->databaseStub->expects($this->any())->method('exec_PREPAREDquery')->with($this->equalTo($expectedResult));
-               $statement->bindValues($parameters);
-               $statement->execute();
-       }
-
-       /**
-        * Data Provider with invalid parameters.
-        *
-        * @see invalidParameterTypesPassedToBindValueThrowsException
-        * @return array
-        */
-       public function invalidParameterTypesPassedToBindValueThrowsExceptionDataProvider() {
-               return array(
-                       'integer passed with param type NULL' => array(1, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_NULL),
-                       'string passed with param type NULL' => array('1', \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_NULL),
-                       'bool passed with param type NULL' => array(TRUE, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_NULL),
-                       'NULL passed with param type INT' => array(NULL, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_INT),
-                       'string passed with param type INT' => array('1', \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_INT),
-                       'bool passed with param type INT' => array(TRUE, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_INT),
-                       'NULL passed with param type BOOL' => array(NULL, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_BOOL),
-                       'string passed with param type BOOL' => array('1', \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_BOOL),
-                       'integer passed with param type BOOL' => array(1, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_BOOL)
-               );
-       }
-
-       /**
-        * Checking if an exception is thrown if invalid parameters are
-        * provided vor bindValue().
-        *
-        * @test
-        * @expectedException InvalidArgumentException
-        * @dataProvider invalidParameterTypesPassedToBindValueThrowsExceptionDataProvider
-        * @param mixed   $parameter    Parameter to be replaced in the query
-        * @param integer $type                 Type of the parameter value
-        * @return void
-        */
-       public function invalidParameterTypesPassedToBindValueThrowsException($parameter, $type) {
-               $statement = $this->createPreparedStatement('');
-               $statement->bindValue(1, $parameter, $type);
-       }
-
-       /**
-        * Checking if formerly bound values are replaced by the values passed to execute().
-        *
-        * @test
-        * @return void
-        */
-       public function parametersPassedToExecuteOverrulesFormerlyBoundValues() {
-               $query = 'SELECT * FROM pages WHERE pid=? OR uid=?';
-               $expectedResult = 'SELECT * FROM pages WHERE pid=30 OR uid=40';
-               $this->databaseStub->expects($this->any())->method('exec_PREPAREDquery')->with($this->equalTo($expectedResult));
-               $statement = $this->createPreparedStatement($query);
-               $statement->bindValues(array(10, 20));
-               $statement->execute(array(30, 40));
-       }
-
-       /**
-        * Data Provieder for invalid marker names.
-        *
-        * @see passingInvalidMarkersThrowsExeption
-        * @return array
-        */
-       public function passingInvalidMarkersThrowsExeptionDataProvider() {
-               return array(
-                       'using other prefix than colon' => array('SELECT * FROM pages WHERE pid=#pid', array('#pid' => 1)),
-                       'using non alphanumerical character' => array('SELECT * FROM pages WHERE title=:stra≠e', array(':stra≠e' => 1)),
-                       'no colon used' => array('SELECT * FROM pages WHERE pid=pid', array('pid' => 1)),
-                       'colon at the end' => array('SELECT * FROM pages WHERE pid=pid:', array('pid:' => 1)),
-                       'colon without alphanumerical character' => array('SELECT * FROM pages WHERE pid=:', array(':' => 1))
-               );
-       }
-
-       /**
-        * Checks if an exception is thrown, if parameter have invalid marker named.
-        *
-        * @test
-        * @expectedException InvalidArgumentException
-        * @dataProvider passingInvalidMarkersThrowsExeptionDataProvider
-        * @param string $query                         Query with unreplaced markers
-        * @param array  $parameters            Array of parameters to be replaced in the query
-        * @return void
-        */
-       public function passingInvalidMarkersThrowsExeption($query, $parameters) {
-               $statement = $this->createPreparedStatement($query);
-               $statement->execute($parameters);
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/error/class.t3lib_error_debugexceptionhandlerTest.php b/tests/Unit/t3lib/error/class.t3lib_error_debugexceptionhandlerTest.php
deleted file mode 100644 (file)
index 756d3b9..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012 Oliver Klee <typo3-coding@oliverklee.de>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-/**
- * testcase for the t3lib_error_DebugExceptionHandler class.
- *
- * @author Oliver Klee <typo3-coding@oliverklee.de>
- * @package TYPO3
- * @subpackage t3lib_error
- */
-class t3lib_error_DebugExceptionHandlerTest extends Tx_Phpunit_TestCase {
-
-       /**
-        * @var t3lib_error_DebugExceptionHandler|PHPUnit_Framework_MockObject_MockObject
-        */
-       private $fixture = NULL;
-
-       /**
-        * Sets up this test case.
-        */
-       protected function setUp() {
-               $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Error\\DebugExceptionHandler', array('sendStatusHeaders', 'writeLogEntries'), array(), '', FALSE);
-               $this->fixture->expects($this->any())->method('discloseExceptionInformation')->will($this->returnValue(TRUE));
-       }
-
-       /**
-        * Tears down this test case.
-        */
-       protected function tearDown() {
-               unset($this->fixture);
-       }
-
-       /**
-        * @test
-        */
-       public function echoExceptionWebEscapesExceptionMessage() {
-               $message = '<b>b</b><script>alert(1);</script>';
-               $exception = new Exception($message);
-               ob_start();
-               $this->fixture->echoExceptionWeb($exception);
-               $output = ob_get_contents();
-               ob_end_clean();
-               $this->assertContains(htmlspecialchars($message), $output);
-               $this->assertNotContains($message, $output);
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/error/class.t3lib_error_productionexceptionhandlerTest.php b/tests/Unit/t3lib/error/class.t3lib_error_productionexceptionhandlerTest.php
deleted file mode 100644 (file)
index 7f05845..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-<?php
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012 Oliver Klee <typo3-coding@oliverklee.de>
- *  All rights reserved
- *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-/**
- * testcase for the t3lib_error_ProductionExceptionHandler class.
- *
- * @author Oliver Klee <typo3-coding@oliverklee.de>
- * @package TYPO3
- * @subpackage t3lib_error
- */
-class t3lib_error_ProductionExceptionHandlerTest extends Tx_Phpunit_TestCase {
-
-       /**
-        * @var t3lib_error_ProductionExceptionHandler|PHPUnit_Framework_MockObject_MockObject
-        */
-       private $fixture = NULL;
-
-       /**
-        * Sets up this test case.
-        */
-       protected function setUp() {
-               $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Error\\ProductionExceptionHandler', array('discloseExceptionInformation', 'sendStatusHeaders', 'writeLogEntries'), array(), '', FALSE);
-               $this->fixture->expects($this->any())->method('discloseExceptionInformation')->will($this->returnValue(TRUE));
-       }
-
-       /**
-        * Tears down this test case.
-        */
-       protected function tearDown() {
-               unset($this->fixture);
-       }
-
-       /**
-        * @test
-        */
-       public function echoExceptionWebEscapesExceptionMessage() {
-               $message = '<b>b</b><script>alert(1);</script>';
-               $exception = new Exception($message);
-               ob_start();
-               $this->fixture->echoExceptionWeb($exception);
-               $output = ob_get_contents();
-               ob_end_clean();
-               $this->assertContains(htmlspecialchars($message), $output);
-               $this->assertNotContains($message, $output);
-       }
-
-       /**
-        * @test
-        */
-       public function echoExceptionWebEscapesExceptionTitle() {
-               $title = '<b>b</b><script>alert(1);</script>';
-               /** @var $exception Exception|PHPUnit_Framework_MockObject_MockObject */
-               $exception = $this->getMock('Exception', array('getTitle'), array('some message'));
-               $exception->expects($this->any())->method('getTitle')->will($this->returnValue($title));
-               ob_start();
-               $this->fixture->echoExceptionWeb($exception);
-               $output = ob_get_contents();
-               ob_end_clean();
-               $this->assertContains(htmlspecialchars($title), $output);
-               $this->assertNotContains($title, $output);
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/formprotection/class.t3lib_formprotection_AbstractTest.php b/tests/Unit/t3lib/formprotection/class.t3lib_formprotection_AbstractTest.php
deleted file mode 100644 (file)
index 8a94853..0000000
+++ /dev/null
@@ -1,261 +0,0 @@
-<?php
-/***************************************************************
- * Copyright notice
- *
- * (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-require_once 'fixtures/class.t3lib_formprotection_testing.php';
-/**
- * Testcase for the t3lib_formprotection_Abstract class.
- *
- * @package TYPO3
- * @subpackage t3lib
- * @author Oliver Klee <typo3-coding@oliverklee.de>
- */
-class t3lib_formprotection_AbstractTest extends tx_phpunit_testcase {
-
-       /**
-        * @var t3lib_formProtection_Testing
-        */
-       private $fixture;
-
-       public function setUp() {
-               $this->fixture = new t3lib_formProtection_Testing();
-       }
-
-       public function tearDown() {
-               $this->fixture->__destruct();
-               unset($this->fixture);
-       }
-
-       /////////////////////////////////////////
-       // Tests concerning the basic functions
-       /////////////////////////////////////////
-       /**
-        * @test
-        */
-       public function constructionRetrievesToken() {
-               $className = uniqid('t3lib_formProtection');
-               eval((((((('class ' . $className) . ' extends t3lib_formProtection_Testing {') . 'public $tokenHasBeenRetrieved = FALSE; ') . 'protected function retrieveSessionToken() {') . '$this->tokenHasBeenRetrieved = TRUE;') . '}') . '}');
-               $fixture = new $className();
-               $this->assertTrue($fixture->tokenHasBeenRetrieved);
-       }
-
-       /**
-        * @test
-        */
-       public function cleanMakesTokenInvalid() {
-               $formName = 'foo';
-               $tokenId = $this->fixture->generateToken($formName);
-               $this->fixture->clean();
-               $this->assertFalse($this->fixture->validateToken($tokenId, $formName));
-       }
-
-       /**
-        * @test
-        */
-       public function cleanPersistsToken() {
-               $fixture = $this->getMock('t3lib_formProtection_Testing', array('persistSessionToken'));
-               $fixture->expects($this->once())->method('persistSessionToken');
-               $fixture->clean();
-       }
-
-       ///////////////////////////////////
-       // Tests concerning generateToken
-       ///////////////////////////////////
-       /**
-        * @test
-        */
-       public function generateTokenFormForEmptyFormNameThrowsException() {
-               $this->setExpectedException('InvalidArgumentException', '$formName must not be empty.');
-               $this->fixture->generateToken('', 'edit', 'bar');
-       }
-
-       /**
-        * @test
-        */
-       public function generateTokenFormForEmptyActionNotThrowsException() {
-               $this->fixture->generateToken('foo', '', '42');
-       }
-
-       /**
-        * @test
-        */
-       public function generateTokenFormForEmptyFormInstanceNameNotThrowsException() {
-               $this->fixture->generateToken('foo', 'edit', '');
-       }
-
-       /**
-        * @test
-        */
-       public function generateTokenFormForOmittedActionAndFormInstanceNameNotThrowsException() {
-               $this->fixture->generateToken('foo');
-       }
-
-       /**
-        * @test
-        */
-       public function generateTokenReturns32CharacterHexToken() {
-               $this->assertRegexp('/^[0-9a-f]{40}$/', $this->fixture->generateToken('foo'));
-       }
-
-       /**
-        * @test
-        */
-       public function generateTokenCalledTwoTimesWithSameParametersReturnsSameTokens() {
-               $this->assertEquals($this->fixture->generateToken('foo', 'edit', 'bar'), $this->fixture->generateToken('foo', 'edit', 'bar'));
-       }
-
-       ///////////////////////////////////
-       // Tests concerning validateToken
-       ///////////////////////////////////
-       /**
-        * @test
-        */
-       public function validateTokenWithFourEmptyParametersNotThrowsException() {
-               $this->fixture->validateToken('', '', '', '');
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenWithTwoEmptyAndTwoMissingParametersNotThrowsException() {
-               $this->fixture->validateToken('', '');
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenWithDataFromGenerateTokenWithFormInstanceNameReturnsTrue() {
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = 'bar';
-               $this->assertTrue($this->fixture->validateToken($this->fixture->generateToken($formName, $action, $formInstanceName), $formName, $action, $formInstanceName));
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenWithDataFromGenerateTokenWithMissingActionAndFormInstanceNameReturnsTrue() {
-               $formName = 'foo';
-               $this->assertTrue($this->fixture->validateToken($this->fixture->generateToken($formName), $formName));
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenWithValidDataCalledTwoTimesReturnsTrueOnSecondCall() {
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = 'bar';
-               $tokenId = $this->fixture->generateToken($formName, $action, $formInstanceName);
-               $this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName);
-               $this->assertTrue($this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName));
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenWithMismatchingTokenIdReturnsFalse() {
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = 'bar';
-               $this->fixture->generateToken($formName, $action, $formInstanceName);
-               $this->assertFalse($this->fixture->validateToken('Hello world!', $formName, $action, $formInstanceName));
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenWithMismatchingFormNameReturnsFalse() {
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = 'bar';
-               $tokenId = $this->fixture->generateToken($formName, $action, $formInstanceName);
-               $this->assertFalse($this->fixture->validateToken($tokenId, 'espresso', $action, $formInstanceName));
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenWithMismatchingActionReturnsFalse() {
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = 'bar';
-               $tokenId = $this->fixture->generateToken($formName, $action, $formInstanceName);
-               $this->assertFalse($this->fixture->validateToken($tokenId, $formName, 'delete', $formInstanceName));
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenWithMismatchingFormInstanceNameReturnsFalse() {
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = 'bar';
-               $tokenId = $this->fixture->generateToken($formName, $action, $formInstanceName);
-               $this->assertFalse($this->fixture->validateToken($tokenId, $formName, $action, 'beer'));
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenForValidTokenNotCallsCreateValidationErrorMessage() {
-               $fixture = $this->getMock('t3lib_formProtection_Testing', array('createValidationErrorMessage'));
-               $fixture->expects($this->never())->method('createValidationErrorMessage');
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = 'bar';
-               $token = $fixture->generateToken($formName, $action, $formInstanceName);
-               $fixture->validateToken($token, $formName, $action, $formInstanceName);
-               $fixture->__destruct();
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenForInvalidTokenCallsCreateValidationErrorMessage() {
-               $fixture = $this->getMock('t3lib_formProtection_Testing', array('createValidationErrorMessage'));
-               $fixture->expects($this->once())->method('createValidationErrorMessage');
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = 'bar';
-               $fixture->generateToken($formName, $action, $formInstanceName);
-               $fixture->validateToken('an invalid token ...', $formName, $action, $formInstanceName);
-               $fixture->__destruct();
-       }
-
-       /**
-        * @test
-        */
-       public function validateTokenForInvalidFormNameCallsCreateValidationErrorMessage() {
-               $fixture = $this->getMock('t3lib_formProtection_Testing', array('createValidationErrorMessage'));
-               $fixture->expects($this->once())->method('createValidationErrorMessage');
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = 'bar';
-               $token = $fixture->generateToken($formName, $action, $formInstanceName);
-               $fixture->validateToken($token, 'another form name', $action, $formInstanceName);
-               $fixture->__destruct();
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/formprotection/class.t3lib_formprotection_BackendFormProtectionTest.php b/tests/Unit/t3lib/formprotection/class.t3lib_formprotection_BackendFormProtectionTest.php
deleted file mode 100644 (file)
index c3ec350..0000000
+++ /dev/null
@@ -1,269 +0,0 @@
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
-* All rights reserved
-*
-* This script is part of the TYPO3 project. The TYPO3 project is
-* free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* The GNU General Public License can be found at
-* http://www.gnu.org/copyleft/gpl.html.
-*
-* This script is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
-
-/**
- * Testcase for the \TYPO3\CMS\Core\FormProtection\BackendFormProtection class.
- *
- * @package TYPO3
- * @subpackage t3lib
- *
- * @author Oliver Klee <typo3-coding@oliverklee.de>
- */
-class t3lib_formprotection_BackendFormProtectionTest extends tx_phpunit_testcase {
-       /**
-        * Enable backup of global and system variables
-        *
-        * @var boolean
-        */
-       protected $backupGlobals = TRUE;
-
-       /**
-        * Exclude TYPO3_DB from backup/ restore of $GLOBALS
-        * because resource types cannot be handled during serializing
-        *
-        * @var array
-        */
-       protected $backupGlobalsBlacklist = array('TYPO3_DB');
-
-
-       /**
-        * @var \TYPO3\CMS\Core\FormProtection\BackendFormProtection
-        */
-       private $fixture;
-
-       public function setUp() {
-               $GLOBALS['BE_USER'] = $this->getMock(
-                       't3lib_beUserAuth',
-                       array('getSessionData', 'setAndSaveSessionData')
-               );
-               $GLOBALS['BE_USER']->user['uid'] = 1;
-
-               $className = $this->createAccessibleProxyClass();
-               $this->fixture = $this->getMock($className, array('acquireLock', 'releaseLock'));
-       }
-
-       public function tearDown() {
-               $this->fixture->__destruct();
-               unset($this->fixture);
-               \TYPO3\CMS\Core\Messaging\FlashMessageQueue::getAllMessagesAndFlush();
-       }
-
-
-       //////////////////////
-       // Utility functions
-       //////////////////////
-
-       /**
-        * Creates a subclass \TYPO3\CMS\Core\FormProtection\BackendFormProtection with retrieveTokens made
-        * public.
-        *
-        * @return string the name of the created class, will not be empty
-        */
-       private function createAccessibleProxyClass() {
-               $namespace = 'TYPO3\\CMS\\Core\\FormProtection';
-               $className = 'BackendFormProtectionAccessibleProxy';
-               if (!class_exists($namespace . '\\' .$className)) {
-                       eval(
-                               'namespace ' . $namespace . ';' .
-                               'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection {' .
-                               '  public function createValidationErrorMessage() {' .
-                               '    parent::createValidationErrorMessage();' .
-                               '  }' .
-                               '  public function retrieveSessionToken() {' .
-                               '    return parent::retrieveSessionToken();' .
-                               '  }' .
-                               '  public function setSessionToken($sessionToken) {' .
-                               '    $this->sessionToken = $sessionToken;' .
-                               '  }' .
-                               '}'
-                       );
-               }
-               $className = $namespace . '\\' . $className;
-               return $className;
-       }
-
-       /**
-        * Mock session methods in t3lib_beUserAuth
-        *
-        * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication Instance of BE_USER object with mocked session storage methods
-        */
-       private function createBackendUserSessionStorageStub() {
-               $namespace = 'TYPO3\\CMS\\Core\\Authentication';
-               $className = 'BackendUserAuthenticationMocked';
-               if (!class_exists($namespace . '\\' .$className)) {
-                       eval(
-                               'namespace ' . $namespace . ';' .
-                               'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication {' .
-                               '  protected $session=array();' .
-                               '  public function getSessionData($key) {' .
-                               '    return $this->session[$key];' .
-                               '  }' .
-                               '  public function setAndSaveSessionData($key, $data) {' .
-                               '    $this->session[$key] = $data;' .
-                               '  }' .
-                               '}'
-                       );
-               }
-               $className = $namespace . '\\' . $className;
-               return $this->getMock($className, array('foo'));// $className;
-       }
-
-       ////////////////////////////////////
-       // Tests for the utility functions
-       ////////////////////////////////////
-
-       /**
-        * @test
-        */
-       public function createAccessibleProxyCreatesBackendFormProtectionSubclass() {
-               $className = $this->createAccessibleProxyClass();
-
-               $this->assertTrue(
-                       (new $className()) instanceof \TYPO3\CMS\Core\FormProtection\BackendFormProtection
-               );
-       }
-
-       /**
-        * @test
-        */
-       public function createBackendUserSessionStorageStubWorkProperly() {
-               $GLOBALS['BE_USER'] = $this->createBackendUserSessionStorageStub();
-
-               $allTokens = array(
-                       '12345678' => array(
-                                       'formName' => 'foo',
-                                       'action' => 'edit',
-                                       'formInstanceName' => '42'
-                               ),
-               );
-
-               $GLOBALS['BE_USER']->setAndSaveSessionData('tokens', $allTokens);
-
-               $this->assertEquals($GLOBALS['BE_USER']->getSessionData('tokens'), $allTokens);
-       }
-
-
-       //////////////////////////////////////////////////////////
-       // Tests concerning the reading and saving of the tokens
-       //////////////////////////////////////////////////////////
-
-       /**
-        * @test
-        */
-       public function retrieveTokenReadsTokenFromSessionData() {
-               $GLOBALS['BE_USER']->expects($this->once())->method('getSessionData')
-                       ->with('formSessionToken')->will($this->returnValue(array()));
-
-               $this->fixture->retrieveSessionToken();
-       }
-
-       /**
-        * @test
-        */
-       public function tokenFromSessionDataIsAvailableForValidateToken() {
-               $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = '42';
-
-               $tokenId = \t3lib_div::hmac($formName . $action . $formInstanceName . $sessionToken);
-
-               $GLOBALS['BE_USER']->expects($this->atLeastOnce())->method('getSessionData')
-                       ->with('formSessionToken')
-                       ->will($this->returnValue($sessionToken));
-
-               $this->fixture->retrieveSessionToken();
-
-               $this->assertTrue(
-                       $this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName)
-               );
-       }
-
-       /**
-        * @expectedException UnexpectedValueException
-        * @test
-        */
-       public function restoreSessionTokenFromRegistryThrowsExceptionIfSessionTokenIsEmpty() {
-               $this->fixture->injectRegistry(
-                       $this->getMock('t3lib_Registry')
-               );
-               $this->fixture->setSessionTokenFromRegistry();
-       }
-
-       /**
-        * @test
-        */
-       public function persistSessionTokenWritesTokenToSession() {
-               $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
-               $this->fixture->setSessionToken($sessionToken);
-
-               $GLOBALS['BE_USER']->expects($this->once())
-                       ->method('setAndSaveSessionData')->with('formSessionToken', $sessionToken);
-
-               $this->fixture->persistSessionToken();
-       }
-
-
-       //////////////////////////////////////////////////
-       // Tests concerning createValidationErrorMessage
-       //////////////////////////////////////////////////
-
-       /**
-        * @test
-        */
-       public function createValidationErrorMessageAddsErrorFlashMessage() {
-               $GLOBALS['BE_USER'] = $this->createBackendUserSessionStorageStub();
-               $this->fixture->createValidationErrorMessage();
-
-               $messages = \TYPO3\CMS\Core\Messaging\FlashMessageQueue::getAllMessagesAndFlush();
-
-               $this->assertNotEmpty($messages);
-               $this->assertContains(
-                       $GLOBALS['LANG']->sL(
-                               'LLL:EXT:lang/locallang_core.xml:error.formProtection.tokenInvalid'
-                       ),
-                       $messages[0]->render()
-               );
-       }
-
-       /**
-        * @test
-        */
-       public function createValidationErrorMessageAddsErrorFlashMessageButNotInSessionInAjaxRequest() {
-               $GLOBALS['BE_USER'] = $this->createBackendUserSessionStorageStub();
-               $GLOBALS['TYPO3_AJAX'] = TRUE;
-               $this->fixture->createValidationErrorMessage();
-
-               $messages = \TYPO3\CMS\Core\Messaging\FlashMessageQueue::$messages;
-
-               $this->assertNotEmpty($messages);
-               $this->assertContains(
-                       $GLOBALS['LANG']->sL(
-                               'LLL:EXT:lang/locallang_core.xml:error.formProtection.tokenInvalid'
-                       ),
-                       $messages[0]->render()
-               );
-       }
-}
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/formprotection/class.t3lib_formprotection_FactoryTest.php b/tests/Unit/t3lib/formprotection/class.t3lib_formprotection_FactoryTest.php
deleted file mode 100644 (file)
index ab8ba9b..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-<?php
-/***************************************************************
- * Copyright notice
- *
- * (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-require_once 'fixtures/class.t3lib_formprotection_testing.php';
-/**
- * Testcase for the t3lib_formprotection_Factory class.
- *
- * @package TYPO3
- * @subpackage t3lib
- * @author Oliver Klee <typo3-coding@oliverklee.de>
- * @author Ernesto Baschny <ernst@cron-it.de>
- */
-class t3lib_formprotection_FactoryTest extends tx_phpunit_testcase {
-
-       public function setUp() {
-
-       }
-
-       public function tearDown() {
-               \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::purgeInstances();
-       }
-
-       /////////////////////////
-       // Tests concerning get
-       /////////////////////////
-       /**
-        * @test
-        * @expectedException InvalidArgumentException
-        */
-       public function getForInexistentClassThrowsException() {
-               \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('noSuchClass');
-       }
-
-       /**
-        * @test
-        * @expectedException InvalidArgumentException
-        */
-       public function getForClassThatIsNoFormProtectionSubclassThrowsException() {
-               \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\FormProtectionFactoryTest');
-       }
-
-       /**
-        * @test
-        */
-       public function getForTypeBackEndWithExistingBackEndReturnsBackEndFormProtection() {
-               $this->assertTrue(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection') instanceof \TYPO3\CMS\Core\FormProtection\BackendFormProtection);
-       }
-
-       /**
-        * @test
-        */
-       public function getForTypeBackEndCalledTwoTimesReturnsTheSameInstance() {
-               $this->assertSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
-       }
-
-       /**
-        * @test
-        */
-       public function getForTypeInstallToolReturnsInstallToolFormProtection() {
-               $this->assertTrue(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection') instanceof \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection);
-       }
-
-       /**
-        * @test
-        */
-       public function getForTypeInstallToolCalledTwoTimesReturnsTheSameInstance() {
-               $this->assertSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'));
-       }
-
-       /**
-        * @test
-        */
-       public function getForTypesInstallToolAndBackEndReturnsDifferentInstances() {
-               $this->assertNotSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
-       }
-
-       /////////////////////////
-       // Tests concerning set
-       /////////////////////////
-       /**
-        * @test
-        */
-       public function setSetsInstanceForType() {
-               $instance = new t3lib_formProtection_Testing();
-               \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::set('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection', $instance);
-               $this->assertSame($instance, \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
-       }
-
-       /**
-        * @test
-        */
-       public function setNotSetsInstanceForOtherType() {
-               $instance = new t3lib_formProtection_Testing();
-               \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::set('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection', $instance);
-               $this->assertNotSame($instance, \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'));
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/formprotection/class.t3lib_formprotection_InstallToolFormProtectionTest.php b/tests/Unit/t3lib/formprotection/class.t3lib_formprotection_InstallToolFormProtectionTest.php
deleted file mode 100644 (file)
index e5eaadc..0000000
+++ /dev/null
@@ -1,173 +0,0 @@
-<?php
-/***************************************************************
-* Copyright notice
-*
-* (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
-* All rights reserved
-*
-* This script is part of the TYPO3 project. The TYPO3 project is
-* free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* The GNU General Public License can be found at
-* http://www.gnu.org/copyleft/gpl.html.
-*
-* This script is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
-
-require_once(t3lib_extMgm::extPath('install') . 'mod/class.tx_install.php');
-
-/**
- * Testcase for the t3lib_formprotection_InstallToolFormProtection class.
- *
- * @package TYPO3
- * @subpackage t3lib
- *
- * @author Oliver Klee <typo3-coding@oliverklee.de>
- */
-class t3lib_formprotection_InstallToolFormProtectionTest extends tx_phpunit_testcase {
-       /**
-        * @var \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
-        */
-       private $fixture;
-
-       /**
-        * backup of $_SESSION
-        *
-        * @var array
-        */
-       private $sessionBackup;
-
-       public function setUp() {
-               $this->sessionBackup = $_SESSION;
-
-               $className = $this->createAccessibleProxyClass();
-               $this->fixture = new $className();
-       }
-
-       public function tearDown() {
-               $this->fixture->__destruct();
-               unset($this->fixture);
-
-               \TYPO3\CMS\Core\Messaging\FlashMessageQueue::getAllMessagesAndFlush();
-
-               $_SESSION = $this->sessionBackup;
-       }
-
-
-       //////////////////////
-       // Utility functions
-       //////////////////////
-
-       /**
-        * Creates a subclass \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection with retrieveTokens made
-        * public.
-        *
-        * @return string the name of the created class, will not be empty
-        */
-       private function createAccessibleProxyClass() {
-               $className = 't3lib_formprotection_InstallToolFormProtectionAccessibleProxy';
-               if (!class_exists($className)) {
-                       eval(
-                               'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection {' .
-                               '  public $sessionToken;' .
-                               '  public function createValidationErrorMessage() {' .
-                               '    parent::createValidationErrorMessage();' .
-                               '  }' .
-                               '  public function retrieveSessionToken() {' .
-                               '    parent::retrieveSessionToken();' .
-                               '  }' .
-                               '}'
-                       );
-               }
-
-               return $className;
-       }
-
-
-       ////////////////////////////////////
-       // Tests for the utility functions
-       ////////////////////////////////////
-
-       /**
-        * @test
-        */
-       public function createAccessibleProxyCreatesInstallToolFormProtectionSubclass() {
-               $className = $this->createAccessibleProxyClass();
-
-               $this->assertTrue(
-                       (new $className()) instanceof \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
-               );
-       }
-
-
-       //////////////////////////////////////////////////////////
-       // Tests concerning the reading and saving of the tokens
-       //////////////////////////////////////////////////////////
-
-       /**
-        * @test
-        */
-       public function tokenFromSessionDataIsAvailableForValidateToken() {
-               $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
-               $formName = 'foo';
-               $action = 'edit';
-               $formInstanceName = '42';
-
-               $tokenId = \t3lib_div::hmac($formName . $action . $formInstanceName . $sessionToken);
-
-               $_SESSION['installToolFormToken'] = $sessionToken;
-
-               $this->fixture->retrieveSessionToken();
-
-               $this->assertTrue(
-                       $this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName)
-               );
-       }
-
-       /**
-        * @test
-        */
-       public function persistSessionTokenWritesTokensToSession() {
-               $_SESSION['installToolFormToken'] = 'foo';
-
-               $this->fixture->sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
-
-               $this->fixture->persistSessionToken();
-
-               $this->assertEquals(
-                       '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd',
-                       $_SESSION['installToolFormToken']
-               );
-       }
-
-
-       //////////////////////////////////////////////////
-       // Tests concerning createValidationErrorMessage
-       //////////////////////////////////////////////////
-
-       /**
-        * @test
-        */
-       public function createValidationErrorMessageAddsErrorMessage() {
-               $installTool = $this->getMock(
-                       'TYPO3\\CMS\\Install\\Installer', array('addErrorMessage'), array(), '', FALSE
-               );
-               $installTool->expects($this->once())->method('addErrorMessage')
-                       ->with(
-                               'Validating the security token of this form has failed. ' .
-                                       'Please reload the form and submit it again.'
-                       );
-               $this->fixture->injectInstallTool($installTool);
-
-               $this->fixture->createValidationErrorMessage();
-       }
-}
-?>
\ No newline at end of file
diff --git a/tests/Unit/t3lib/formprotection/fixtures/class.t3lib_formprotection_testing.php b/tests/Unit/t3lib/formprotection/fixtures/class.t3lib_formprotection_testing.php
deleted file mode 100644 (file)
index b3ee8d9..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-/***************************************************************
- * Copyright notice
- *
- * (c) 2010-2011 Oliver Klee <typo3-coding@oliverklee.de>
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
-/**
- * Class t3lib_formProtection_Testing.
- *
- * This is a testing subclass of the abstract t3lib_formprotection_Abstract
- * class.
- *
- * @package TYPO3
- * @subpackage t3lib
- * @author Oliver Klee <typo3-coding@oliverklee.de>
- */
-class t3lib_formProtection_Testing extends \TYPO3\CMS\Core\FormProtection\AbstractFormProtection {
-
-       /**
-        * Creates or displayes an error message telling the user that the submitted
-        * form token is invalid.
-        *
-        * @return void
-        */
-       protected function createValidationErrorMessage() {
-
-       }
-
-       /**
-        * Retrieves all saved tokens.
-        *
-        * @return array the saved tokens as a two-dimensional array, will be empty
-        */
-       protected function retrieveSessionToken() {
-               $this->sessionToken = $this->generateSessionToken();
-       }
-
-       /**
-        * Saves the tokens so that they can be used by a later incarnation of this
-        * class.
-        *
-        * @return void
-        */
-       public function persistSessionToken() {
-
-       }
-
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Category/CategoryRegistryTest.php b/typo3/sysext/core/Tests/Unit/Category/CategoryRegistryTest.php
new file mode 100644 (file)
index 0000000..815dcb2
--- /dev/null
@@ -0,0 +1,162 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Category;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Testcase for CategoryRegistry
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ * @author Oliver Hader <oliver.hader@typo3.org>
+ */
+class CategoryRegistryTest extends \tx_phpunit_testcase {
+
+       /**
+        * Enable backup of global and system variables
+        *
+        * @var boolean
+        */
+       protected $backupGlobals = TRUE;
+
+       /**
+        * @var \TYPO3\CMS\Core\Category\CategoryRegistry
+        */
+       protected $fixture;
+
+       /**
+        * @var array
+        */
+       protected $tables;
+
+       /**
+        * Sets up this test suite.
+        */
+       protected function setUp() {
+               $this->fixture = new \TYPO3\CMS\Core\Category\CategoryRegistry();
+               $this->tables = array(
+                       'first' => uniqid('first'),
+                       'second' => uniqid('second')
+               );
+               foreach ($this->tables as $tableName) {
+                       $GLOBALS['TCA'][$tableName] = array('ctrl' => array());
+               }
+       }
+
+       /**
+        * Tears down this test suite.
+        */
+       protected function tearDown() {
+               unset($this->tables);
+               unset($this->fixture);
+       }
+
+       /**
+        * @test
+        */
+       public function isRegistryEmptyByDefault() {
+               $this->assertEquals(array(), $this->fixture->get());
+       }
+
+       /**
+        * @test
+        */
+       public function doesAddReturnTrueOnDefinedTable() {
+               $this->assertTrue($this->fixture->add('test_extension_a', $this->tables['first'], 'categories'));
+       }
+
+       /**
+        * @test
+        */
+       public function doesAddReturnFalseOnUndefinedTable() {
+               $this->assertFalse($this->fixture->add('test_extension_a', uniqid('undefined'), 'categories'));
+       }
+
+       /**
+        * @test
+        */
+       public function areMultipleElementsOfSameExtensionRegistered() {
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
+               $registry = $this->fixture->get();
+               ob_flush();
+               $this->assertEquals('categories', $registry['test_extension_a'][$this->tables['first']]);
+               $this->assertEquals('categories', $registry['test_extension_b'][$this->tables['second']]);
+       }
+
+       /**
+        * @test
+        */
+       public function areElementsOfDifferentExtensionsRegistered() {
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
+               $registry = $this->fixture->get();
+               $this->assertEquals('categories', $registry['test_extension_a'][$this->tables['first']]);
+               $this->assertEquals('categories', $registry['test_extension_b'][$this->tables['second']]);
+       }
+
+       /**
+        * @test
+        */
+       public function areElementsOnSameTableOverridden() {
+               $this->fixture->add('test_extension_a', $this->tables['first'], $this->tables['first']);
+               $this->fixture->add('test_extension_b', $this->tables['second'], $this->tables['second']);
+               $registry = $this->fixture->get();
+               $this->assertEquals($this->tables['first'], $registry['test_extension_a'][$this->tables['first']]);
+       }
+
+       /**
+        * @test
+        */
+       public function areDatabaseDefinitionsOfAllElementsAvailable() {
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
+               $this->fixture->add('test_extension_c', $this->tables['first'], 'categories');
+               $definitions = $this->fixture->getDatabaseTableDefinitions();
+               $matches = array();
+               preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
+               $this->assertEquals(2, count($matches[0]));
+               $this->assertEquals($matches[1][0], $this->tables['first']);
+               $this->assertEquals($matches[2][0], 'categories');
+               $this->assertEquals($matches[1][1], $this->tables['second']);
+               $this->assertEquals($matches[2][1], 'categories');
+       }
+
+       /**
+        * @test
+        */
+       public function areDatabaseDefinitionsOfParticularExtensionAvailable() {
+               $this->fixture->add('test_extension_a', $this->tables['first'], 'categories');
+               $this->fixture->add('test_extension_b', $this->tables['second'], 'categories');
+               $definitions = $this->fixture->getDatabaseTableDefinition('test_extension_a');
+               $matches = array();
+               preg_match_all('#CREATE TABLE\\s*([^ (]+)\\s*\\(\\s*([^ )]+)\\s+int\\(11\\)[^)]+\\);#mis', $definitions, $matches);
+               $this->assertEquals(1, count($matches[0]));
+               $this->assertEquals($matches[1][0], $this->tables['first']);
+               $this->assertEquals($matches[2][0], 'categories');
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Category/Collection/CategoryCollectionTest.php b/typo3/sysext/core/Tests/Unit/Category/Collection/CategoryCollectionTest.php
new file mode 100644 (file)
index 0000000..8836356
--- /dev/null
@@ -0,0 +1,326 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Category\Collection;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2012 Fabien Udriot <fabien.udriot@typo3.org>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Test case for t3lib_category_CategoryCollection
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ * @author Fabien Udriot <fabien.udriot@typo3.org>
+ */
+class CategoryCollectionTest extends \tx_phpunit_testcase {
+
+       /**
+        * @var \TYPO3\CMS\Core\Category\Collection\CategoryCollection
+        */
+       private $fixture;
+
+       /**
+        * @var string
+        */
+       private $tableName = 'tx_foo_5001615c50bed';
+
+       /**
+        * @var array
+        */
+       private $tables = array('sys_category', 'sys_category_record_mm');
+
+       /**
+        * @var int
+        */
+       private $categoryUid = 0;
+
+       /**
+        * @var array
+        */
+       private $collectionRecord = array();
+
+       /**
+        * @var Tx_Phpunit_Framework
+        */
+       private $testingFramework;
+
+       /**
+        * @var \TYPO3\CMS\Core\Database\DatabaseConnection
+        */
+       private $database;
+
+       /**
+        * Sets up this test suite.
+        *
+        * @return void
+        */
+       public function setUp() {
+               $this->database = $GLOBALS['TYPO3_DB'];
+               $this->fixture = new \TYPO3\CMS\Core\Category\Collection\CategoryCollection($this->tableName);
+               $this->collectionRecord = array(
+                       'uid' => 0,
+                       'title' => uniqid('title'),
+                       'description' => uniqid('description'),
+                       'table_name' => $this->tableName,
+               );
+               $GLOBALS['TCA'][$this->tableName] = array('ctrl' => array());
+               // prepare environment
+               $this->createDummyTable();
+               $this->testingFramework = new \Tx_Phpunit_Framework('sys_category', array('tx_foo'));
+               $this->populateDummyTable();
+               $this->prepareTables();
+               $this->makeRelationBetweenCategoryAndDummyTable();
+       }
+
+       /**
+        * Tears down this test suite.
+        *
+        * @return void
+        */
+       public function tearDown() {
+               $this->testingFramework->cleanUp();
+               // clean up environment
+               $this->dropDummyTable();
+               $this->dropDummyField();
+               unset($this->testingFramework);
+               unset($this->collectionRecord);
+               unset($this->fixture);
+               unset($this->database);
+       }
+
+       /**
+        * @test
+        * @expectedException RuntimeException
+        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::__construct
+        * @return void
+        */
+       public function missingTableNameArgumentForObjectCategoryCollection() {
+               new \TYPO3\CMS\Core\Category\Collection\CategoryCollection();
+       }
+
+       /**
+        * @test
+        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::fromArray
+        * @return void
+        */
+       public function checkIfFromArrayMethodSetCorrectProperties() {
+               $this->fixture->fromArray($this->collectionRecord);
+               $this->assertEquals($this->collectionRecord['uid'], $this->fixture->getIdentifier());
+               $this->assertEquals($this->collectionRecord['uid'], $this->fixture->getUid());
+               $this->assertEquals($this->collectionRecord['title'], $this->fixture->getTitle());
+               $this->assertEquals($this->collectionRecord['description'], $this->fixture->getDescription());
+               $this->assertEquals($this->collectionRecord['table_name'], $this->fixture->getItemTableName());
+       }
+
+       /**
+        * @test
+        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::create
+        * @return void
+        */
+       public function canCreateDummyCollection() {
+               $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::create($this->collectionRecord);
+               $this->assertInstanceOf('\TYPO3\CMS\Core\Category\Collection\CategoryCollection', $collection);
+       }
+
+       /**
+        * @test
+        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::create
+        * @return void
+        */
+       public function canCreateDummyCollectionAndFillItems() {
+               $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::create($this->collectionRecord, TRUE);
+               $this->assertInstanceOf('\TYPO3\CMS\Core\Category\Collection\CategoryCollection', $collection);
+       }
+
+       /**
+        * @test
+        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getCollectedRecords
+        * @return void
+        */
+       public function getCollectedRecordsReturnsEmptyRecordSet() {
+               $method = new \ReflectionMethod('TYPO3\\CMS\\Core\\Category\\Collection\\CategoryCollection', 'getCollectedRecords');
+               $method->setAccessible(TRUE);
+               $records = $method->invoke($this->fixture);
+               $this->assertInternalType('array', $records);
+               $this->assertEmpty($records);
+       }
+
+       /**
+        * @test
+        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getStorageTableName
+        * @return void
+        */
+       public function isStorageTableNameEqualsToSysCategory() {
+               $this->assertEquals('sys_category', \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getStorageTableName());
+       }
+
+       /**
+        * @test
+        * @covers \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getStorageItemsField
+        * @return void
+        */
+       public function isStorageItemsFieldEqualsToItems() {
+               $this->assertEquals('items', \TYPO3\CMS\Core\Category\Collection\CategoryCollection::getStorageItemsField());
+       }
+
+       /**
+        * @test
+        * @return void
+        */
+       public function canLoadADummyCollectionFromDatabase() {
+               /** @var $collection \TYPO3\CMS\Core\Category\Collection\CategoryCollection */
+               $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, TRUE, $this->tableName);
+               // Check the number of record
+               $this->assertEquals($this->numberOfRecords, $collection->count());
+               // Check that the first record is the one expected
+               $record = $this->database->exec_SELECTgetSingleRow('*', $this->tableName, 'uid=1');
+               $collection->rewind();
+               $this->assertEquals($record, $collection->current());
+               // Add a new record
+               $fakeRecord = array(
+                       'uid' => $this->numberOfRecords + 1,
+                       'pid' => 0,
+                       'title' => uniqid('title'),
+                       'categories' => 0
+               );
+               // Check the number of records
+               $collection->add($fakeRecord);
+               $this->assertEquals($this->numberOfRecords + 1, $collection->count());
+       }
+
+       /**
+        * @test
+        * @return void
+        */
+       public function canLoadADummyCollectionFromDatabaseAndAddRecord() {
+               $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, TRUE, $this->tableName);
+               // Add a new record
+               $fakeRecord = array(
+                       'uid' => $this->numberOfRecords + 1,
+                       'pid' => 0,
+                       'title' => uniqid('title'),
+                       'categories' => 0
+               );
+               // Check the number of records
+               $collection->add($fakeRecord);
+               $this->assertEquals($this->numberOfRecords + 1, $collection->count());
+       }
+
+       /**
+        * @test
+        * @return void
+        */
+       public function canLoadADummyCollectionWithoutContentFromDatabase() {
+               /** @var $collection \TYPO3\CMS\Core\Category\Collection\CategoryCollection */
+               $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, FALSE, $this->tableName);
+               // Check the number of record
+               $this->assertEquals(0, $collection->count());
+       }
+
+       /********************/
+       /* INTERNAL METHODS */
+       /********************/
+       /**
+        * Create dummy table for testing purpose
+        *
+        * @return void
+        */
+       private function populateDummyTable() {
+               $this->numberOfRecords = 5;
+               for ($index = 1; $index <= $this->numberOfRecords; $index++) {
+                       $values = array(
+                               'title' => uniqid('title')
+                       );
+                       $this->testingFramework->createRecord($this->tableName, $values);
+               }
+       }
+
+       /**
+        * Make relation between tables
+        *
+        * @return void
+        */
+       private function makeRelationBetweenCategoryAndDummyTable() {
+               for ($index = 1; $index <= $this->numberOfRecords; $index++) {
+                       $values = array(
+                               'uid_local' => $this->categoryUid,
+                               'uid_foreign' => $index,
+                               'tablenames' => $this->tableName
+                       );
+                       $this->testingFramework->createRecord('sys_category_record_mm', $values);
+               }
+       }
+
+       /**
+        * Create dummy table for testing purpose
+        *
+        * @return void
+        */
+       private function createDummyTable() {
+               $sql = "CREATE TABLE {$this->tableName} (\n\tuid int(11) auto_increment,\n\tpid int(11) unsigned DEFAULT '0' NOT NULL,\n    title tinytext,\n\tcategories int(11) unsigned DEFAULT '0' NOT NULL,\n\tsys_category_is_dummy_record int(11) unsigned DEFAULT '0' NOT NULL,\n\n    PRIMARY KEY (uid)\n);";
+               $this->database->sql_query($sql);
+       }
+
+       /**
+        * Drop dummy table
+        *
+        * @return void
+        */
+       private function dropDummyTable() {
+               $sql = ('DROP TABLE ' . $this->tableName) . ';';
+               $this->database->sql_query($sql);
+       }
+
+       /**
+        * Add is_dummy_record record and create dummy record
+        *
+        * @return void
+        */
+       private function prepareTables() {
+               $sql = 'ALTER TABLE %s ADD is_dummy_record tinyint(1) unsigned DEFAULT \'0\' NOT NULL';
+               foreach ($this->tables as $table) {
+                       $_sql = sprintf($sql, $table);
+                       $this->database->sql_query($_sql);
+               }
+               $values = array(
+                       'title' => uniqid('title'),
+                       'is_dummy_record' => 1
+               );
+               $this->categoryUid = $this->testingFramework->createRecord('sys_category', $values);
+       }
+
+       /**
+        * Remove dummy record and drop field
+        *
+        * @return void
+        */
+       private function dropDummyField() {
+               $sql = 'ALTER TABLE %s DROP COLUMN is_dummy_record';
+               foreach ($this->tables as $table) {
+                       $_sql = sprintf($sql, $table);
+                       $this->database->sql_query($_sql);
+               }
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Collection/RecordCollectionRepositoryTest.php b/typo3/sysext/core/Tests/Unit/Collection/RecordCollectionRepositoryTest.php
new file mode 100644 (file)
index 0000000..59c4c9a
--- /dev/null
@@ -0,0 +1,266 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Collection;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ * A copy is found in the textfile GPL.txt and important notices to the license
+ * from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Test case for \TYPO3\CMS\Core\Collection\RecordCollectionRepository
+ *
+ * @author Oliver Hader <oliver.hader@typo3.org>
+ * @package TYPO3
+ * @subpackage t3lib
+ */
+class RecordCollectionRepositoryTest extends \Tx_Phpunit_TestCase {
+
+       /**
+        * @var PHPUnit_Framework_MockObject_MockObject|t3lib_collection_RecordCollectionRepository
+        */
+       protected $fixture;
+
+       /**
+        * @var PHPUnit_Framework_MockObject_MockObject|t3lib_DB
+        */
+       protected $databaseMock;
+
+       /**
+        * @var NULL|array
+        */
+       protected $getSingleRowCallbackReturnValue;
+
+       /**
+        * @var NULL|array
+        */
+       protected $getRowsCallbackReturnValue;
+
+       /**
+        * @var string
+        */
+       protected $testTableName;
+
+       /**
+        * Sets up this test case.
+        */
+       protected function setUp() {
+               $this->databaseMock = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_UPDATEquery', 'exec_SELECTgetSingleRow', 'exec_SELECTgetRows'));
+               $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Collection\\RecordCollectionRepository', array('getDatabase'));
+               $this->fixture->expects($this->any())->method('getDatabase')->will($this->returnValue($this->databaseMock));
+               $this->testTableName = uniqid('tx_testtable');
+       }
+
+       /**
+        * Cleans up this test case.
+        */
+       protected function tearDown() {
+               unset($this->databaseMock);
+               unset($this->fixture);
+               unset($this->getSingleRowCallbackReturnValue);
+               unset($this->getRowsCallbackReturnValue);
+               unset($this->testTableName);
+       }
+
+       /**
+        * @test
+        */
+       public function doesFindByUidReturnNull() {
+               $testUid = rand(1, 1000);
+               $this->databaseMock->expects($this->once())->method('exec_SELECTgetSingleRow')->will($this->returnCallback(array($this, 'getSingleRowCallback')));
+               $this->getSingleRowCallbackReturnValue = NULL;
+               $object = $this->fixture->findByUid($testUid);
+               $this->assertNull($object);
+       }
+
+       /**
+        * @test
+        */
+       public function doesFindByUidReturnObject() {
+               $testUid = rand(1, 1000);
+               $this->databaseMock->expects($this->once())->method('exec_SELECTgetSingleRow')->will($this->returnCallback(array($this, 'getSingleRowCallback')));
+               $this->getSingleRowCallbackReturnValue = array(
+                       'uid' => $testUid,
+                       'type' => \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static,
+                       'table_name' => $this->testTableName
+               );
+               $object = $this->fixture->findByUid($testUid);
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $object);
+       }
+
+       /**
+        * @test
+        * @expectedException RuntimeException
+        */
+       public function doesFindByUidThrowException() {
+               $testUid = rand(1, 1000);
+               $this->databaseMock->expects($this->once())->method('exec_SELECTgetSingleRow')->will($this->returnCallback(array($this, 'getSingleRowCallback')));
+               $this->getSingleRowCallbackReturnValue = array(
+                       'uid' => $testUid,
+                       'type' => uniqid('unknown')
+               );
+               $object = $this->fixture->findByUid($testUid);
+       }
+
+       /**
+        * @test
+        */
+       public function doesFindByTypeReturnNull() {
+               $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static;
+               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
+               $this->getRowsCallbackReturnValue = NULL;
+               $objects = $this->fixture->findByType($type);
+               $this->assertNull($objects);
+       }
+
+       /**
+        * @test
+        */
+       public function doesFindByTypeReturnObjects() {
+               $testUid = rand(1, 1000);
+               $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static;
+               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
+               $this->getRowsCallbackReturnValue = array(
+                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName),
+                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName)
+               );
+               $objects = $this->fixture->findByType($type);
+               $this->assertEquals(2, count($objects));
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[0]);
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[1]);
+       }
+
+       /**
+        * @test
+        */
+       public function doesFindByTableNameReturnNull() {
+               $testTable = uniqid('sys_collection_');
+               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
+               $this->getRowsCallbackReturnValue = NULL;
+               $objects = $this->fixture->findByTableName($testTable);
+               $this->assertNull($objects);
+       }
+
+       /**
+        * @test
+        */
+       public function doesFindByTableNameReturnObjects() {
+               $testUid = rand(1, 1000);
+               $testTable = uniqid('sys_collection_');
+               $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static;
+               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
+               $this->getRowsCallbackReturnValue = array(
+                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName),
+                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName)
+               );
+               $objects = $this->fixture->findByTableName($testTable);
+               $this->assertEquals(2, count($objects));
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[0]);
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[1]);
+       }
+
+       /**
+        * @test
+        */
+       public function doesFindByTypeAndTableNameReturnNull() {
+               $testTable = uniqid('sys_collection_');
+               $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static;
+               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
+               $this->getRowsCallbackReturnValue = NULL;
+               $objects = $this->fixture->findByTypeAndTableName($type, $testTable);
+               $this->assertNull($objects);
+       }
+
+       /**
+        * @test
+        */
+       public function doesFindByTypeAndTableNameReturnObjects() {
+               $testUid = rand(1, 1000);
+               $testTable = uniqid('sys_collection_');
+               $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static;
+               $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback')));
+               $this->getRowsCallbackReturnValue = array(
+                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName),
+                       array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName)
+               );
+               $objects = $this->fixture->findByTypeAndTableName($type, $testTable);
+               $this->assertEquals(2, count($objects));
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[0]);
+               $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[1]);
+       }
+
+       /**
+        * Callback for exec_SELECTgetSingleRow
+        *
+        * @param string $fields
+        * @param string $table
+        * @return NULL|array
+        */
+       public function getSingleRowCallback($fields, $table) {
+               if (!is_array($this->getSingleRowCallbackReturnValue) || $fields === '*') {
+                       $returnValue = $this->getSingleRowCallbackReturnValue;
+               } else {
+                       $returnValue = $this->limitRecordFields($fields, $this->getSingleRowCallbackReturnValue);
+               }
+               return $returnValue;
+       }
+
+       /**
+        * Callback for exec_SELECTgetRows
+        *
+        * @param string $fields
+        * @param string $table
+        * @return NULL|array
+        */
+       public function getRowsCallback($fields, $table) {
+               if (!is_array($this->getRowsCallbackReturnValue) || $fields === '*') {
+                       $returnValue = $this->getRowsCallbackReturnValue;
+               } else {
+                       $returnValue = array();
+                       foreach ($this->getRowsCallbackReturnValue as $record) {
+                               $returnValue[] = $this->limitRecordFields($fields, $record);
+                       }
+               }
+               return $returnValue;
+       }
+
+       /**
+        * Limits record fields to a given field list.
+        *
+        * @param string $fields List of fields
+        * @param array $record The database record (or the simulated one)
+        * @return array
+        */
+       protected function limitRecordFields($fields, array $record) {
+               $result = array();
+               foreach ($record as $field => $value) {
+                       if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($fields, $field)) {
+                               $result[$field] = $value;
+                       }
+               }
+               return $result;
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Database/PreparedStatementTest.php b/typo3/sysext/core/Tests/Unit/Database/PreparedStatementTest.php
new file mode 100644 (file)
index 0000000..43fa8a2
--- /dev/null
@@ -0,0 +1,269 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Database;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010-2011 Helmut Hummel <helmut@typo3.org>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Testcase for the prepared statement database class
+ *
+ * @author     Helmut Hummel <helmut@typo3.org>
+ * @package TYPO3
+ * @subpackage tests
+ */
+class PreparedStatementTest extends \tx_phpunit_testcase {
+
+       /**
+        * Backup and restore of the $GLOBALS array.
+        *
+        * @var boolean
+        */
+       protected $backupGlobalsArray = array();
+
+       /**
+        * Mock object of t3lib_db
+        *
+        * @var PHPUnit_Framework_MockObject_MockObject
+        */
+       private $databaseStub;
+
+       /**
+        * Create a new database mock object for every test
+        * and backup the original global database object.
+        *
+        * @return void
+        */
+       protected function setUp() {
+               $this->backupGlobalsArray['TYPO3_DB'] = $GLOBALS['TYPO3_DB'];
+               $this->databaseStub = $this->setUpAndReturnDatabaseStub();
+       }
+
+       /**
+        * Restore global database object.
+        *
+        * @return void
+        */
+       protected function tearDown() {
+               $GLOBALS['TYPO3_DB'] = $this->backupGlobalsArray['TYPO3_DB'];
+       }
+
+       //////////////////////
+       // Utility functions
+       //////////////////////
+       /**
+        * Set up the stub to be able to get the result of the prepared statement.
+        *
+        * @return PHPUnit_Framework_MockObject_MockObject
+        */
+       private function setUpAndReturnDatabaseStub() {
+               $databaseLink = $GLOBALS['TYPO3_DB']->link;
+               $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array('exec_PREPAREDquery'), array(), '', FALSE, FALSE);
+               $GLOBALS['TYPO3_DB']->link = $databaseLink;
+               return $GLOBALS['TYPO3_DB'];
+       }
+
+       /**
+        * Create a object fo the subject to be tested.
+        *
+        * @param string $query
+        * @return \TYPO3\CMS\Core\Database\PreparedStatement
+        */
+       private function createPreparedStatement($query) {
+               return new \TYPO3\CMS\Core\Database\PreparedStatement($query, 'pages');
+       }
+
+       ////////////////////////////////////
+       // Tests for the utility functions
+       ////////////////////////////////////
+       /**
+        * Checks if setUpAndReturnDatabaseStub() really returns
+        * a mock of t3lib_DB.
+        *
+        * @test
+        * @return void
+        */
+       public function setUpAndReturnDatabaseStubReturnsMockObjectOf_t3lib_DB() {
+               $this->assertTrue($this->setUpAndReturnDatabaseStub() instanceof \TYPO3\CMS\Core\Database\DatabaseConnection);
+       }
+
+       /**
+        * Checks if createPreparedStatement() really returns an instance of t3lib_db_PreparedStatement.
+        *
+        * @test
+        * @return void
+        */
+       public function createPreparedStatementReturnsInstanceOfPreparedStatementClass() {
+               $this->assertTrue($this->createPreparedStatement('dummy') instanceof \TYPO3\CMS\Core\Database\PreparedStatement);
+       }
+
+       ///////////////////////////////////////
+       // Tests for t3lib_db_PreparedStatement
+       ///////////////////////////////////////
+       /**
+        * Data Provider for two tests, providing sample queries, parameters and expected result queries.
+        *
+        * @see parametersAreReplacedInQueryByCallingExecute
+        * @see parametersAreReplacedInQueryWhenBoundWithBindValues
+        * @return array
+        */
+       public function parametersAndQueriesDataProvider() {
+               return array(
+                       'one named integer parameter' => array('SELECT * FROM pages WHERE pid=:pid', array(':pid' => 1), 'SELECT * FROM pages WHERE pid=1'),
+                       'one unnamed integer parameter' => array('SELECT * FROM pages WHERE pid=?', array(1), 'SELECT * FROM pages WHERE pid=1'),
+                       'one named integer parameter is replaced multiple times' => array('SELECT * FROM pages WHERE pid=:pid OR uid=:pid', array(':pid' => 1), 'SELECT * FROM pages WHERE pid=1 OR uid=1'),
+                       'two named integer parameters are replaced' => array('SELECT * FROM pages WHERE pid=:pid OR uid=:uid', array(':pid' => 1, ':uid' => 10), 'SELECT * FROM pages WHERE pid=1 OR uid=10'),
+                       'two unnamed integer parameters are replaced' => array('SELECT * FROM pages WHERE pid=? OR uid=?', array(1, 1), 'SELECT * FROM pages WHERE pid=1 OR uid=1'),
+                       'php bool TRUE parameter is replaced with 1' => array('SELECT * FROM pages WHERE deleted=?', array(TRUE), 'SELECT * FROM pages WHERE deleted=1'),
+                       'php bool FALSE parameter is replaced with 0' => array('SELECT * FROM pages WHERE deleted=?', array(FALSE), 'SELECT * FROM pages WHERE deleted=0'),
+                       'php null parameter is replaced with NULL' => array('SELECT * FROM pages WHERE deleted=?', array(NULL), 'SELECT * FROM pages WHERE deleted=NULL'),
+                       'string parameter is wrapped in quotes' => array('SELECT * FROM pages WHERE title=?', array('Foo bar'), 'SELECT * FROM pages WHERE title=\'Foo bar\''),
+                       'number as string parameter is wrapped in quotes' => array('SELECT * FROM pages WHERE title=?', array('12'), 'SELECT * FROM pages WHERE title=\'12\''),
+                       'string single quotes in parameter are properly escaped' => array('SELECT * FROM pages WHERE title=?', array('\'Foo\''), 'SELECT * FROM pages WHERE title=\'\\\'Foo\\\'\''),
+                       'question mark as values with unnamed parameters are properly escaped' => array('SELECT * FROM foo WHERE title=? AND name=?', array('?', 'fancy title'), 'SELECT * FROM foo WHERE title=\'?\' AND name=\'fancy title\''),
+                       'parameter name as value is properly escaped' => array('SELECT * FROM foo WHERE title=:name AND name=:title', array(':name' => ':title', ':title' => 'fancy title'), 'SELECT * FROM foo WHERE title=\':title\' AND name=\'fancy title\''),
+                       'question mark as value of a parameter with a name is properly escaped' => array('SELECT * FROM foo WHERE title=:name AND name=?', array(':name' => '?', 'cool name'), 'SELECT * FROM foo WHERE title=\'?\' AND name=\'cool name\''),
+                       'regular expression back references as values are left untouched' => array('SELECT * FROM foo WHERE title=:name AND name=?', array(':name' => '\\1', '${1}'), 'SELECT * FROM foo WHERE title=\'\\\\1\' AND name=\'${1}\''),
+                       'unsubstituted question marks do not contain the token wrap' => array('SELECT * FROM foo WHERE title=:name AND question LIKE "%what?" AND name=:title', array(':name' => 'Title', ':title' => 'Name'), 'SELECT * FROM foo WHERE title=\'Title\' AND question LIKE "%what?" AND name=\'Name\'')
+               );
+       }
+
+       /**
+        * Checking if calling execute() with parameters, they are
+        * properly relpaced in the query.
+        *
+        * @test
+        * @dataProvider parametersAndQueriesDataProvider
+        * @param string $query                         Query with unreplaced markers
+        * @param array  $parameters            Array of parameters to be replaced in the query
+        * @param string $expectedResult        Query with all markers replaced
+        * @return void
+        */
+       public function parametersAreReplacedInQueryByCallingExecute($query, $parameters, $expectedResult) {
+               $statement = $this->createPreparedStatement($query);
+               $this->databaseStub->expects($this->any())->method('exec_PREPAREDquery')->with($this->equalTo($expectedResult));
+               $statement->execute($parameters);
+       }
+
+       /**
+        * Checking if parameters bound to the statement by bindValues()
+        * are properly replaced in the query.
+        *
+        * @test
+        * @dataProvider parametersAndQueriesDataProvider
+        * @param string $query                         Query with unreplaced markers
+        * @param array  $parameters            Array of parameters to be replaced in the query
+        * @param string $expectedResult        Query with all markers replaced
+        * @return void
+        */
+       public function parametersAreReplacedInQueryWhenBoundWithBindValues($query, $parameters, $expectedResult) {
+               $statement = $this->createPreparedStatement($query);
+               $this->databaseStub->expects($this->any())->method('exec_PREPAREDquery')->with($this->equalTo($expectedResult));
+               $statement->bindValues($parameters);
+               $statement->execute();
+       }
+
+       /**
+        * Data Provider with invalid parameters.
+        *
+        * @see invalidParameterTypesPassedToBindValueThrowsException
+        * @return array
+        */
+       public function invalidParameterTypesPassedToBindValueThrowsExceptionDataProvider() {
+               return array(
+                       'integer passed with param type NULL' => array(1, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_NULL),
+                       'string passed with param type NULL' => array('1', \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_NULL),
+                       'bool passed with param type NULL' => array(TRUE, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_NULL),
+                       'NULL passed with param type INT' => array(NULL, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_INT),
+                       'string passed with param type INT' => array('1', \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_INT),
+                       'bool passed with param type INT' => array(TRUE, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_INT),
+                       'NULL passed with param type BOOL' => array(NULL, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_BOOL),
+                       'string passed with param type BOOL' => array('1', \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_BOOL),
+                       'integer passed with param type BOOL' => array(1, \TYPO3\CMS\Core\Database\PreparedStatement::PARAM_BOOL)
+               );
+       }
+
+       /**
+        * Checking if an exception is thrown if invalid parameters are
+        * provided vor bindValue().
+        *
+        * @test
+        * @expectedException InvalidArgumentException
+        * @dataProvider invalidParameterTypesPassedToBindValueThrowsExceptionDataProvider
+        * @param mixed   $parameter    Parameter to be replaced in the query
+        * @param integer $type                 Type of the parameter value
+        * @return void
+        */
+       public function invalidParameterTypesPassedToBindValueThrowsException($parameter, $type) {
+               $statement = $this->createPreparedStatement('');
+               $statement->bindValue(1, $parameter, $type);
+       }
+
+       /**
+        * Checking if formerly bound values are replaced by the values passed to execute().
+        *
+        * @test
+        * @return void
+        */
+       public function parametersPassedToExecuteOverrulesFormerlyBoundValues() {
+               $query = 'SELECT * FROM pages WHERE pid=? OR uid=?';
+               $expectedResult = 'SELECT * FROM pages WHERE pid=30 OR uid=40';
+               $this->databaseStub->expects($this->any())->method('exec_PREPAREDquery')->with($this->equalTo($expectedResult));
+               $statement = $this->createPreparedStatement($query);
+               $statement->bindValues(array(10, 20));
+               $statement->execute(array(30, 40));
+       }
+
+       /**
+        * Data Provieder for invalid marker names.
+        *
+        * @see passingInvalidMarkersThrowsExeption
+        * @return array
+        */
+       public function passingInvalidMarkersThrowsExeptionDataProvider() {
+               return array(
+                       'using other prefix than colon' => array('SELECT * FROM pages WHERE pid=#pid', array('#pid' => 1)),
+                       'using non alphanumerical character' => array('SELECT * FROM pages WHERE title=:stra≠e', array(':stra≠e' => 1)),
+                       'no colon used' => array('SELECT * FROM pages WHERE pid=pid', array('pid' => 1)),
+                       'colon at the end' => array('SELECT * FROM pages WHERE pid=pid:', array('pid:' => 1)),
+                       'colon without alphanumerical character' => array('SELECT * FROM pages WHERE pid=:', array(':' => 1))
+               );
+       }
+
+       /**
+        * Checks if an exception is thrown, if parameter have invalid marker named.
+        *
+        * @test
+        * @expectedException InvalidArgumentException
+        * @dataProvider passingInvalidMarkersThrowsExeptionDataProvider
+        * @param string $query                         Query with unreplaced markers
+        * @param array  $parameters            Array of parameters to be replaced in the query
+        * @return void
+        */
+       public function passingInvalidMarkersThrowsExeption($query, $parameters) {
+               $statement = $this->createPreparedStatement($query);
+               $statement->execute($parameters);
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Encoder/JavaScriptEncoderTest.php b/typo3/sysext/core/Tests/Unit/Encoder/JavaScriptEncoderTest.php
new file mode 100644 (file)
index 0000000..a8c04ec
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Encoder;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2012 Helmut Hummel <helmut.hummel@typo3.org>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Test cases for TYPO3\CMS\Core\Encoder\JavaScriptEncoder.
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ * @author Helmut Hummel <helmut.hummel@typo3.org>
+ */
+class JavaScriptEncoderTest extends \Tx_Phpunit_TestCase {
+
+       /**
+        * @var \TYPO3\CMS\Core\Encoder\JavaScriptEncoder
+        */
+       protected $fixture = NULL;
+
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Core\Encoder\JavaScriptEncoder();
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+       }
+
+       /**
+        * Data provider for encodeEncodesCorrectly.
+        *
+        * @return array
+        */
+       public function encodeEncodesCorrectlyDataProvider() {
+               return array(
+                       'Immune characters are returned as is' => array(
+                               '._,',
+                               '._,'
+                       ),
+                       'Alphanumerical characters are returned as is' => array(
+                               'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
+                               'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
+                       ),
+                       'Angel brackets and ampersand are encoded' => array(
+                               '<>&',
+                               '\\x3C\\x3E\\x26'
+                       ),
+                       'Quotes and slashes are encoded' => array(
+                               '"\'\\/',
+                               '\\x22\\x27\\x5C\\x2F'
+                       ),
+                       'Empty string stays empty' => array(
+                               '',
+                               ''
+                       ),
+                       'Exclamation mark and space are properly encoded' => array(
+                               'Hello World!',
+                               'Hello\\x20World\\x21'
+                       ),
+                       'Whitespaces are properly encoded' => array(
+                               ((TAB . LF) . CR) . ' ',
+                               '\\x09\\x0A\\x0D\\x20'
+                       ),
+                       'Null byte is properly encoded' => array(
+                               chr(0),
+                               '\\x00'
+                       ),
+                       'Umlauts are properly encoded' => array(
+                               'ÜüÖöÄä',
+                               '\\xDC\\xFC\\xD6\\xF6\\xC4\\xE4'
+                       )
+               );
+       }
+
+       /**
+        * @test
+        * @param string $input
+        * @param string  $expected
+        * @dataProvider encodeEncodesCorrectlyDataProvider
+        */
+       public function encodeEncodesCorrectly($input, $expected) {
+               $this->assertSame($expected, $this->fixture->encode($input));
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Error/DebugExceptionHandlerTest.php b/typo3/sysext/core/Tests/Unit/Error/DebugExceptionHandlerTest.php
new file mode 100644 (file)
index 0000000..ae5e880
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Error;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Oliver Klee <typo3-coding@oliverklee.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * testcase for the DebugExceptionHandler class.
+ *
+ * @author Oliver Klee <typo3-coding@oliverklee.de>
+ * @package TYPO3
+ * @subpackage t3lib_error
+ */
+class DebugExceptionHandlerTest extends \Tx_Phpunit_TestCase {
+
+       /**
+        * @var \TYPO3\CMS\Core\Error\DebugExceptionHandler|PHPUnit_Framework_MockObject_MockObject
+        */
+       private $fixture = NULL;
+
+       /**
+        * Sets up this test case.
+        */
+       protected function setUp() {
+               $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Error\\DebugExceptionHandler', array('sendStatusHeaders', 'writeLogEntries'), array(), '', FALSE);
+               $this->fixture->expects($this->any())->method('discloseExceptionInformation')->will($this->returnValue(TRUE));
+       }
+
+       /**
+        * Tears down this test case.
+        */
+       protected function tearDown() {
+               unset($this->fixture);
+       }
+
+       /**
+        * @test
+        */
+       public function echoExceptionWebEscapesExceptionMessage() {
+               $message = '<b>b</b><script>alert(1);</script>';
+               $exception = new \Exception($message);
+               ob_start();
+               $this->fixture->echoExceptionWeb($exception);
+               $output = ob_get_contents();
+               ob_end_clean();
+               $this->assertContains(htmlspecialchars($message), $output);
+               $this->assertNotContains($message, $output);
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/Error/ProductionExceptionHandlerTest.php b/typo3/sysext/core/Tests/Unit/Error/ProductionExceptionHandlerTest.php
new file mode 100644 (file)
index 0000000..18cf753
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Error;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Oliver Klee <typo3-coding@oliverklee.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * testcase for the \TYPO3\CMS\Core\Error\ProductionExceptionHandler class.
+ *
+ * @author Oliver Klee <typo3-coding@oliverklee.de>
+ * @package TYPO3
+ * @subpackage t3lib_error
+ */
+class ProductionExceptionHandlerTest extends \Tx_Phpunit_TestCase {
+
+       /**
+        * @var \TYPO3\CMS\Core\Error\ProductionExceptionHandler|PHPUnit_Framework_MockObject_MockObject
+        */
+       private $fixture = NULL;
+
+       /**
+        * Sets up this test case.
+        */
+       protected function setUp() {
+               $this->fixture = $this->getMock('TYPO3\\CMS\\Core\\Error\\ProductionExceptionHandler', array('discloseExceptionInformation', 'sendStatusHeaders', 'writeLogEntries'), array(), '', FALSE);
+               $this->fixture->expects($this->any())->method('discloseExceptionInformation')->will($this->returnValue(TRUE));
+       }
+
+       /**
+        * Tears down this test case.
+        */
+       protected function tearDown() {
+               unset($this->fixture);
+       }
+
+       /**
+        * @test
+        */
+       public function echoExceptionWebEscapesExceptionMessage() {
+               $message = '<b>b</b><script>alert(1);</script>';
+               $exception = new \Exception($message);
+               ob_start();
+               $this->fixture->echoExceptionWeb($exception);
+               $output = ob_get_contents();
+               ob_end_clean();
+               $this->assertContains(htmlspecialchars($message), $output);
+               $this->assertNotContains($message, $output);
+       }
+
+       /**
+        * @test
+        */
+       public function echoExceptionWebEscapesExceptionTitle() {
+               $title = '<b>b</b><script>alert(1);</script>';
+               /** @var $exception Exception|PHPUnit_Framework_MockObject_MockObject */
+               $exception = $this->getMock('Exception', array('getTitle'), array('some message'));
+               $exception->expects($this->any())->method('getTitle')->will($this->returnValue($title));
+               ob_start();
+               $this->fixture->echoExceptionWeb($exception);
+               $output = ob_get_contents();
+               ob_end_clean();
+               $this->assertContains(htmlspecialchars($title), $output);
+               $this->assertNotContains($title, $output);
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/FormProtection/AbstractFormProtectionTest.php b/typo3/sysext/core/Tests/Unit/FormProtection/AbstractFormProtectionTest.php
new file mode 100644 (file)
index 0000000..390fcdb
--- /dev/null
@@ -0,0 +1,265 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\FormProtection;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+require_once 'Fixtures/FormProtectionTesting.php';
+
+/**
+ * Testcase for the t3lib_formprotection_Abstract class.
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ * @author Oliver Klee <typo3-coding@oliverklee.de>
+ */
+class AbstractFormProtectionTest extends \tx_phpunit_testcase {
+
+       /**
+        * @var t3lib_formProtection_Testing
+        */
+       private $fixture;
+
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting();
+       }
+
+       public function tearDown() {
+               $this->fixture->__destruct();
+               unset($this->fixture);
+       }
+
+       /////////////////////////////////////////
+       // Tests concerning the basic functions
+       /////////////////////////////////////////
+       /**
+        * @test
+        */
+       public function constructionRetrievesToken() {
+               $className = uniqid('t3lib_formProtection');
+               eval((((((('class ' . $className) . ' extends \TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting {') . 'public $tokenHasBeenRetrieved = FALSE; ') . 'protected function retrieveSessionToken() {') . '$this->tokenHasBeenRetrieved = TRUE;') . '}') . '}');
+               $fixture = new $className();
+               $this->assertTrue($fixture->tokenHasBeenRetrieved);
+       }
+
+       /**
+        * @test
+        */
+       public function cleanMakesTokenInvalid() {
+               $formName = 'foo';
+               $tokenId = $this->fixture->generateToken($formName);
+               $this->fixture->clean();
+               $this->assertFalse($this->fixture->validateToken($tokenId, $formName));
+       }
+
+       /**
+        * @test
+        */
+       public function cleanPersistsToken() {
+               $fixture = $this->getMock('TYPO3\\CMS\\Core\\Tests\\Unit\\FormProtection\\Fixtures\\FormProtectionTesting', array('persistSessionToken'));
+               $fixture->expects($this->once())->method('persistSessionToken');
+               $fixture->clean();
+       }
+
+       ///////////////////////////////////
+       // Tests concerning generateToken
+       ///////////////////////////////////
+       /**
+        * @test
+        */
+       public function generateTokenFormForEmptyFormNameThrowsException() {
+               $this->setExpectedException('InvalidArgumentException', '$formName must not be empty.');
+               $this->fixture->generateToken('', 'edit', 'bar');
+       }
+
+       /**
+        * @test
+        */
+       public function generateTokenFormForEmptyActionNotThrowsException() {
+               $this->fixture->generateToken('foo', '', '42');
+       }
+
+       /**
+        * @test
+        */
+       public function generateTokenFormForEmptyFormInstanceNameNotThrowsException() {
+               $this->fixture->generateToken('foo', 'edit', '');
+       }
+
+       /**
+        * @test
+        */
+       public function generateTokenFormForOmittedActionAndFormInstanceNameNotThrowsException() {
+               $this->fixture->generateToken('foo');
+       }
+
+       /**
+        * @test
+        */
+       public function generateTokenReturns32CharacterHexToken() {
+               $this->assertRegexp('/^[0-9a-f]{40}$/', $this->fixture->generateToken('foo'));
+       }
+
+       /**
+        * @test
+        */
+       public function generateTokenCalledTwoTimesWithSameParametersReturnsSameTokens() {
+               $this->assertEquals($this->fixture->generateToken('foo', 'edit', 'bar'), $this->fixture->generateToken('foo', 'edit', 'bar'));
+       }
+
+       ///////////////////////////////////
+       // Tests concerning validateToken
+       ///////////////////////////////////
+       /**
+        * @test
+        */
+       public function validateTokenWithFourEmptyParametersNotThrowsException() {
+               $this->fixture->validateToken('', '', '', '');
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenWithTwoEmptyAndTwoMissingParametersNotThrowsException() {
+               $this->fixture->validateToken('', '');
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenWithDataFromGenerateTokenWithFormInstanceNameReturnsTrue() {
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = 'bar';
+               $this->assertTrue($this->fixture->validateToken($this->fixture->generateToken($formName, $action, $formInstanceName), $formName, $action, $formInstanceName));
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenWithDataFromGenerateTokenWithMissingActionAndFormInstanceNameReturnsTrue() {
+               $formName = 'foo';
+               $this->assertTrue($this->fixture->validateToken($this->fixture->generateToken($formName), $formName));
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenWithValidDataCalledTwoTimesReturnsTrueOnSecondCall() {
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = 'bar';
+               $tokenId = $this->fixture->generateToken($formName, $action, $formInstanceName);
+               $this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName);
+               $this->assertTrue($this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName));
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenWithMismatchingTokenIdReturnsFalse() {
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = 'bar';
+               $this->fixture->generateToken($formName, $action, $formInstanceName);
+               $this->assertFalse($this->fixture->validateToken('Hello world!', $formName, $action, $formInstanceName));
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenWithMismatchingFormNameReturnsFalse() {
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = 'bar';
+               $tokenId = $this->fixture->generateToken($formName, $action, $formInstanceName);
+               $this->assertFalse($this->fixture->validateToken($tokenId, 'espresso', $action, $formInstanceName));
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenWithMismatchingActionReturnsFalse() {
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = 'bar';
+               $tokenId = $this->fixture->generateToken($formName, $action, $formInstanceName);
+               $this->assertFalse($this->fixture->validateToken($tokenId, $formName, 'delete', $formInstanceName));
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenWithMismatchingFormInstanceNameReturnsFalse() {
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = 'bar';
+               $tokenId = $this->fixture->generateToken($formName, $action, $formInstanceName);
+               $this->assertFalse($this->fixture->validateToken($tokenId, $formName, $action, 'beer'));
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenForValidTokenNotCallsCreateValidationErrorMessage() {
+               $fixture = $this->getMock('TYPO3\\CMS\\Core\\Tests\\Unit\\FormProtection\\Fixtures\\FormProtectionTesting', array('createValidationErrorMessage'));
+               $fixture->expects($this->never())->method('createValidationErrorMessage');
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = 'bar';
+               $token = $fixture->generateToken($formName, $action, $formInstanceName);
+               $fixture->validateToken($token, $formName, $action, $formInstanceName);
+               $fixture->__destruct();
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenForInvalidTokenCallsCreateValidationErrorMessage() {
+               $fixture = $this->getMock('TYPO3\\CMS\\Core\\Tests\\Unit\\FormProtection\\Fixtures\\FormProtectionTesting', array('createValidationErrorMessage'));
+               $fixture->expects($this->once())->method('createValidationErrorMessage');
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = 'bar';
+               $fixture->generateToken($formName, $action, $formInstanceName);
+               $fixture->validateToken('an invalid token ...', $formName, $action, $formInstanceName);
+               $fixture->__destruct();
+       }
+
+       /**
+        * @test
+        */
+       public function validateTokenForInvalidFormNameCallsCreateValidationErrorMessage() {
+               $fixture = $this->getMock('TYPO3\\CMS\\Core\\Tests\\Unit\\FormProtection\\Fixtures\\FormProtectionTesting', array('createValidationErrorMessage'));
+               $fixture->expects($this->once())->method('createValidationErrorMessage');
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = 'bar';
+               $token = $fixture->generateToken($formName, $action, $formInstanceName);
+               $fixture->validateToken($token, 'another form name', $action, $formInstanceName);
+               $fixture->__destruct();
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/FormProtection/BackendFormProtectionTest.php b/typo3/sysext/core/Tests/Unit/FormProtection/BackendFormProtectionTest.php
new file mode 100644 (file)
index 0000000..a8fbebf
--- /dev/null
@@ -0,0 +1,271 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\FormProtection;
+
+/***************************************************************
+* Copyright notice
+*
+* (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
+* All rights reserved
+*
+* This script is part of the TYPO3 project. The TYPO3 project is
+* free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* The GNU General Public License can be found at
+* http://www.gnu.org/copyleft/gpl.html.
+*
+* This script is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Testcase for the \TYPO3\CMS\Core\FormProtection\BackendFormProtection class.
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ *
+ * @author Oliver Klee <typo3-coding@oliverklee.de>
+ */
+class BackendFormProtectionTest extends \tx_phpunit_testcase {
+       /**
+        * Enable backup of global and system variables
+        *
+        * @var boolean
+        */
+       protected $backupGlobals = TRUE;
+
+       /**
+        * Exclude TYPO3_DB from backup/ restore of $GLOBALS
+        * because resource types cannot be handled during serializing
+        *
+        * @var array
+        */
+       protected $backupGlobalsBlacklist = array('TYPO3_DB');
+
+
+       /**
+        * @var \TYPO3\CMS\Core\FormProtection\BackendFormProtection
+        */
+       private $fixture;
+
+       public function setUp() {
+               $GLOBALS['BE_USER'] = $this->getMock(
+                       't3lib_beUserAuth',
+                       array('getSessionData', 'setAndSaveSessionData')
+               );
+               $GLOBALS['BE_USER']->user['uid'] = 1;
+
+               $className = $this->createAccessibleProxyClass();
+               $this->fixture = $this->getMock($className, array('acquireLock', 'releaseLock'));
+       }
+
+       public function tearDown() {
+               $this->fixture->__destruct();
+               unset($this->fixture);
+               \TYPO3\CMS\Core\Messaging\FlashMessageQueue::getAllMessagesAndFlush();
+       }
+
+
+       //////////////////////
+       // Utility functions
+       //////////////////////
+
+       /**
+        * Creates a subclass \TYPO3\CMS\Core\FormProtection\BackendFormProtection with retrieveTokens made
+        * public.
+        *
+        * @return string the name of the created class, will not be empty
+        */
+       private function createAccessibleProxyClass() {
+               $namespace = 'TYPO3\\CMS\\Core\\FormProtection';
+               $className = 'BackendFormProtectionAccessibleProxy';
+               if (!class_exists($namespace . '\\' .$className)) {
+                       eval(
+                               'namespace ' . $namespace . ';' .
+                               'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection {' .
+                               '  public function createValidationErrorMessage() {' .
+                               '    parent::createValidationErrorMessage();' .
+                               '  }' .
+                               '  public function retrieveSessionToken() {' .
+                               '    return parent::retrieveSessionToken();' .
+                               '  }' .
+                               '  public function setSessionToken($sessionToken) {' .
+                               '    $this->sessionToken = $sessionToken;' .
+                               '  }' .
+                               '}'
+                       );
+               }
+               $className = $namespace . '\\' . $className;
+               return $className;
+       }
+
+       /**
+        * Mock session methods in t3lib_beUserAuth
+        *
+        * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication Instance of BE_USER object with mocked session storage methods
+        */
+       private function createBackendUserSessionStorageStub() {
+               $namespace = 'TYPO3\\CMS\\Core\\Authentication';
+               $className = 'BackendUserAuthenticationMocked';
+               if (!class_exists($namespace . '\\' .$className)) {
+                       eval(
+                               'namespace ' . $namespace . ';' .
+                               'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication {' .
+                               '  protected $session=array();' .
+                               '  public function getSessionData($key) {' .
+                               '    return $this->session[$key];' .
+                               '  }' .
+                               '  public function setAndSaveSessionData($key, $data) {' .
+                               '    $this->session[$key] = $data;' .
+                               '  }' .
+                               '}'
+                       );
+               }
+               $className = $namespace . '\\' . $className;
+               return $this->getMock($className, array('foo'));// $className;
+       }
+
+       ////////////////////////////////////
+       // Tests for the utility functions
+       ////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function createAccessibleProxyCreatesBackendFormProtectionSubclass() {
+               $className = $this->createAccessibleProxyClass();
+
+               $this->assertTrue(
+                       (new $className()) instanceof \TYPO3\CMS\Core\FormProtection\BackendFormProtection
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function createBackendUserSessionStorageStubWorkProperly() {
+               $GLOBALS['BE_USER'] = $this->createBackendUserSessionStorageStub();
+
+               $allTokens = array(
+                       '12345678' => array(
+                                       'formName' => 'foo',
+                                       'action' => 'edit',
+                                       'formInstanceName' => '42'
+                               ),
+               );
+
+               $GLOBALS['BE_USER']->setAndSaveSessionData('tokens', $allTokens);
+
+               $this->assertEquals($GLOBALS['BE_USER']->getSessionData('tokens'), $allTokens);
+       }
+
+
+       //////////////////////////////////////////////////////////
+       // Tests concerning the reading and saving of the tokens
+       //////////////////////////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function retrieveTokenReadsTokenFromSessionData() {
+               $GLOBALS['BE_USER']->expects($this->once())->method('getSessionData')
+                       ->with('formSessionToken')->will($this->returnValue(array()));
+
+               $this->fixture->retrieveSessionToken();
+       }
+
+       /**
+        * @test
+        */
+       public function tokenFromSessionDataIsAvailableForValidateToken() {
+               $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = '42';
+
+               $tokenId = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac($formName . $action . $formInstanceName . $sessionToken);
+
+               $GLOBALS['BE_USER']->expects($this->atLeastOnce())->method('getSessionData')
+                       ->with('formSessionToken')
+                       ->will($this->returnValue($sessionToken));
+
+               $this->fixture->retrieveSessionToken();
+
+               $this->assertTrue(
+                       $this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName)
+               );
+       }
+
+       /**
+        * @expectedException UnexpectedValueException
+        * @test
+        */
+       public function restoreSessionTokenFromRegistryThrowsExceptionIfSessionTokenIsEmpty() {
+               $this->fixture->injectRegistry(
+                       $this->getMock('t3lib_Registry')
+               );
+               $this->fixture->setSessionTokenFromRegistry();
+       }
+
+       /**
+        * @test
+        */
+       public function persistSessionTokenWritesTokenToSession() {
+               $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
+               $this->fixture->setSessionToken($sessionToken);
+
+               $GLOBALS['BE_USER']->expects($this->once())
+                       ->method('setAndSaveSessionData')->with('formSessionToken', $sessionToken);
+
+               $this->fixture->persistSessionToken();
+       }
+
+
+       //////////////////////////////////////////////////
+       // Tests concerning createValidationErrorMessage
+       //////////////////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function createValidationErrorMessageAddsErrorFlashMessage() {
+               $GLOBALS['BE_USER'] = $this->createBackendUserSessionStorageStub();
+               $this->fixture->createValidationErrorMessage();
+
+               $messages = \TYPO3\CMS\Core\Messaging\FlashMessageQueue::getAllMessagesAndFlush();
+
+               $this->assertNotEmpty($messages);
+               $this->assertContains(
+                       $GLOBALS['LANG']->sL(
+                               'LLL:EXT:lang/locallang_core.xml:error.formProtection.tokenInvalid'
+                       ),
+                       $messages[0]->render()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function createValidationErrorMessageAddsErrorFlashMessageButNotInSessionInAjaxRequest() {
+               $GLOBALS['BE_USER'] = $this->createBackendUserSessionStorageStub();
+               $GLOBALS['TYPO3_AJAX'] = TRUE;
+               $this->fixture->createValidationErrorMessage();
+
+               $messages = \TYPO3\CMS\Core\Messaging\FlashMessageQueue::$messages;
+
+               $this->assertNotEmpty($messages);
+               $this->assertContains(
+                       $GLOBALS['LANG']->sL(
+                               'LLL:EXT:lang/locallang_core.xml:error.formProtection.tokenInvalid'
+                       ),
+                       $messages[0]->render()
+               );
+       }
+}
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/FormProtection/Fixtures/FormProtectionTesting.php b/typo3/sysext/core/Tests/Unit/FormProtection/Fixtures/FormProtectionTesting.php
new file mode 100644 (file)
index 0000000..265bcc1
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2010-2011 Oliver Klee <typo3-coding@oliverklee.de>
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Class \TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting.
+ *
+ * This is a testing subclass of the abstract \TYPO3\CMS\Core\FormProtection\AbstractFormProtection
+ * class.
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ * @author Oliver Klee <typo3-coding@oliverklee.de>
+ */
+class FormProtectionTesting extends \TYPO3\CMS\Core\FormProtection\AbstractFormProtection {
+
+       /**
+        * Creates or displayes an error message telling the user that the submitted
+        * form token is invalid.
+        *
+        * @return void
+        */
+       protected function createValidationErrorMessage() {
+
+       }
+
+       /**
+        * Retrieves all saved tokens.
+        *
+        * @return array the saved tokens as a two-dimensional array, will be empty
+        */
+       protected function retrieveSessionToken() {
+               $this->sessionToken = $this->generateSessionToken();
+       }
+
+       /**
+        * Saves the tokens so that they can be used by a later incarnation of this
+        * class.
+        *
+        * @return void
+        */
+       public function persistSessionToken() {
+
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/FormProtection/FormProtectionFactoryTest.php b/typo3/sysext/core/Tests/Unit/FormProtection/FormProtectionFactoryTest.php
new file mode 100644 (file)
index 0000000..d247e00
--- /dev/null
@@ -0,0 +1,124 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\FormProtection;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+require_once 'Fixtures/FormProtectionTesting.php';
+
+/**
+ * Testcase for the t3lib_formprotection_Factory class.
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ * @author Oliver Klee <typo3-coding@oliverklee.de>
+ * @author Ernesto Baschny <ernst@cron-it.de>
+ */
+class FormprotectionFactoryTest extends \tx_phpunit_testcase {
+
+       public function setUp() {
+
+       }
+
+       public function tearDown() {
+               \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::purgeInstances();
+       }
+
+       /////////////////////////
+       // Tests concerning get
+       /////////////////////////
+       /**
+        * @test
+        * @expectedException InvalidArgumentException
+        */
+       public function getForInexistentClassThrowsException() {
+               \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('noSuchClass');
+       }
+
+       /**
+        * @test
+        * @expectedException InvalidArgumentException
+        */
+       public function getForClassThatIsNoFormProtectionSubclassThrowsException() {
+               \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\FormProtectionFactoryTest');
+       }
+
+       /**
+        * @test
+        */
+       public function getForTypeBackEndWithExistingBackEndReturnsBackEndFormProtection() {
+               $this->assertTrue(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection') instanceof \TYPO3\CMS\Core\FormProtection\BackendFormProtection);
+       }
+
+       /**
+        * @test
+        */
+       public function getForTypeBackEndCalledTwoTimesReturnsTheSameInstance() {
+               $this->assertSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
+       }
+
+       /**
+        * @test
+        */
+       public function getForTypeInstallToolReturnsInstallToolFormProtection() {
+               $this->assertTrue(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection') instanceof \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection);
+       }
+
+       /**
+        * @test
+        */
+       public function getForTypeInstallToolCalledTwoTimesReturnsTheSameInstance() {
+               $this->assertSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'));
+       }
+
+       /**
+        * @test
+        */
+       public function getForTypesInstallToolAndBackEndReturnsDifferentInstances() {
+               $this->assertNotSame(\TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'), \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
+       }
+
+       /////////////////////////
+       // Tests concerning set
+       /////////////////////////
+       /**
+        * @test
+        */
+       public function setSetsInstanceForType() {
+               $instance = new \TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting();
+               \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::set('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection', $instance);
+               $this->assertSame($instance, \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection'));
+       }
+
+       /**
+        * @test
+        */
+       public function setNotSetsInstanceForOtherType() {
+               $instance = new \TYPO3\CMS\Core\Tests\Unit\FormProtection\Fixtures\FormProtectionTesting();
+               \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::set('TYPO3\\CMS\\Core\\FormProtection\\BackendFormProtection', $instance);
+               $this->assertNotSame($instance, \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::get('TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection'));
+       }
+
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/core/Tests/Unit/FormProtection/InstallToolFormProtectionTest.php b/typo3/sysext/core/Tests/Unit/FormProtection/InstallToolFormProtectionTest.php
new file mode 100644 (file)
index 0000000..6761710
--- /dev/null
@@ -0,0 +1,175 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\FormProtection;
+
+/***************************************************************
+* Copyright notice
+*
+* (c) 2010-2011 Oliver Klee (typo3-coding@oliverklee.de)
+* All rights reserved
+*
+* This script is part of the TYPO3 project. The TYPO3 project is
+* free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* The GNU General Public License can be found at
+* http://www.gnu.org/copyleft/gpl.html.
+*
+* This script is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+require_once(\TYPO3\CMS\Core\Extension\ExtensionManager::extPath('install') . 'mod/class.tx_install.php');
+
+/**
+ * Testcase for the \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection class.
+ *
+ * @package TYPO3
+ * @subpackage t3lib
+ *
+ * @author Oliver Klee <typo3-coding@oliverklee.de>
+ */
+class InstallToolFormProtectionTest extends \tx_phpunit_testcase {
+       /**
+        * @var \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
+        */
+       private $fixture;
+
+       /**
+        * backup of $_SESSION
+        *
+        * @var array
+        */
+       private $sessionBackup;
+
+       public function setUp() {
+               $this->sessionBackup = $_SESSION;
+
+               $className = $this->createAccessibleProxyClass();
+               $this->fixture = new $className();
+       }
+
+       public function tearDown() {
+               $this->fixture->__destruct();
+               unset($this->fixture);
+
+               \TYPO3\CMS\Core\Messaging\FlashMessageQueue::getAllMessagesAndFlush();
+
+               $_SESSION = $this->sessionBackup;
+       }
+
+
+       //////////////////////
+       // Utility functions
+       //////////////////////
+
+       /**
+        * Creates a subclass \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection with retrieveTokens made
+        * public.
+        *
+        * @return string the name of the created class, will not be empty
+        */
+       private function createAccessibleProxyClass() {
+               $className = 't3lib_formprotection_InstallToolFormProtectionAccessibleProxy';
+               if (!class_exists($className)) {
+                       eval(
+                               'class ' . $className . ' extends \\TYPO3\\CMS\\Core\\FormProtection\\InstallToolFormProtection {' .
+                               '  public $sessionToken;' .
+                               '  public function createValidationErrorMessage() {' .
+                               '    parent::createValidationErrorMessage();' .
+                               '  }' .
+                               '  public function retrieveSessionToken() {' .
+                               '    parent::retrieveSessionToken();' .
+                               '  }' .
+                               '}'
+                       );
+               }
+
+               return $className;
+       }
+
+
+       ////////////////////////////////////
+       // Tests for the utility functions
+       ////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function createAccessibleProxyCreatesInstallToolFormProtectionSubclass() {
+               $className = $this->createAccessibleProxyClass();
+
+               $this->assertTrue(
+                       (new $className()) instanceof \TYPO3\CMS\Core\FormProtection\InstallToolFormProtection
+               );
+       }
+
+
+       //////////////////////////////////////////////////////////
+       // Tests concerning the reading and saving of the tokens
+       //////////////////////////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function tokenFromSessionDataIsAvailableForValidateToken() {
+               $sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
+               $formName = 'foo';
+               $action = 'edit';
+               $formInstanceName = '42';
+
+               $tokenId = \t3lib_div::hmac($formName . $action . $formInstanceName . $sessionToken);
+
+               $_SESSION['installToolFormToken'] = $sessionToken;
+
+               $this->fixture->retrieveSessionToken();
+
+               $this->assertTrue(
+                       $this->fixture->validateToken($tokenId, $formName, $action, $formInstanceName)
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function persistSessionTokenWritesTokensToSession() {
+               $_SESSION['installToolFormToken'] = 'foo';
+
+               $this->fixture->sessionToken = '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd';
+
+               $this->fixture->persistSessionToken();
+
+               $this->assertEquals(
+                       '881ffea2159ac72182557b79dc0c723f5a8d20136f9fab56cdd4f8b3a1dbcfcd',
+                       $_SESSION['installToolFormToken']
+               );
+       }
+
+
+       //////////////////////////////////////////////////
+       // Tests concerning createValidationErrorMessage
+       //////////////////////////////////////////////////
+
+       /**
+        * @test
+        */
+       public function createValidationErrorMessageAddsErrorMessage() {
+               $installTool = $this->getMock(
+                       'TYPO3\\CMS\\Install\\Installer', array('addErrorMessage'), array(), '', FALSE
+               );
+               $installTool->expects($this->once())->method('addErrorMessage')
+                       ->with(
+                               'Validating the security token of this form has failed. ' .
+                                       'Please reload the form and submit it again.'
+                       );
+               $this->fixture->injectInstallTool($installTool);
+
+               $this->fixture->createValidationErrorMessage();
+       }
+}
+?>
\ No newline at end of file