[TASK] Move persistence unit tests
authorAlexander Schnitzler <alex.schnitzler@typovision.de>
Wed, 21 Nov 2012 18:30:59 +0000 (19:30 +0100)
committerAlexander Schnitzler <typo3@alexanderschnitzler.de>
Wed, 21 Nov 2012 18:34:10 +0000 (19:34 +0100)
From Persistence to Persistence\Generic

Releases: 6.0
Fixes: #43204

Change-Id: I5eb269217e8369b0f05dc52b2595fed3f1a41442
Reviewed-on: http://review.typo3.org/16675
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
20 files changed:
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapFactoryTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapperTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/ObjectStorageTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/PersistenceManagerTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryFactoryTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryResultTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/RepositoryTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/SessionTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php [new file with mode: 0644]
typo3/sysext/extbase/Tests/Unit/Persistence/Mapper/DataMapFactoryTest.php [deleted file]
typo3/sysext/extbase/Tests/Unit/Persistence/Mapper/DataMapperTest.php [deleted file]
typo3/sysext/extbase/Tests/Unit/Persistence/ObjectStorageTest.php [deleted file]
typo3/sysext/extbase/Tests/Unit/Persistence/PersistenceManagerTest.php [deleted file]
typo3/sysext/extbase/Tests/Unit/Persistence/QueryFactoryTest.php [deleted file]
typo3/sysext/extbase/Tests/Unit/Persistence/QueryResultTest.php [deleted file]
typo3/sysext/extbase/Tests/Unit/Persistence/QueryTest.php [deleted file]
typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php [deleted file]
typo3/sysext/extbase/Tests/Unit/Persistence/SessionTest.php [deleted file]
typo3/sysext/extbase/Tests/Unit/Persistence/Storage/Typo3DbBackendTest.php [deleted file]

diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapFactoryTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapFactoryTest.php
new file mode 100644 (file)
index 0000000..7aa21b7
--- /dev/null
@@ -0,0 +1,455 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Mapper;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  This class is a backport of the corresponding class of TYPO3 Flow.
+ *  All credits go to the TYPO3 Flow team.
+ *  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!
+ ***************************************************************/
+class DataMapFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @return array
+        */
+       public function oneToOneRelation() {
+               return array(
+                       array('Tx_Myext_Domain_Model_Foo'),
+                       array('TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider oneToOneRelation
+        */
+       public function setRelationsDetectsOneToOneRelation($className) {
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $columnConfiguration = array(
+                       'type' => 'select',
+                       'foreign_table' => 'tx_myextension_bar',
+                       'foreign_field' => 'parentid'
+               );
+               $propertyMetaData = array(
+                       'type' => $className,
+                       'elementType' => NULL
+               );
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->once())->method('setOneToOneRelation');
+               $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
+               $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
+               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
+       }
+
+       /**
+        * @test
+        */
+       public function setRelationsDetectsOneToOneRelationWithIntermediateTable() {
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $columnConfiguration = array(
+                       'type' => 'select',
+                       'foreign_table' => 'tx_myextension_bar',
+                       'MM' => 'tx_myextension_mm'
+               );
+               $propertyMetaData = array(
+                       'type' => 'Tx_Myext_Domain_Model_Foo',
+                       'elementType' => NULL
+               );
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
+               $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
+               $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
+               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
+       }
+
+       /**
+        * @test
+        */
+       public function setRelationsDetectsOneToManyRelation() {
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $columnConfiguration = array(
+                       'type' => 'select',
+                       'foreign_table' => 'tx_myextension_bar',
+                       'foreign_field' => 'parentid',
+                       'foreign_table_field' => 'parenttable'
+               );
+               $propertyMetaData = array(
+                       'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
+                       'elementType' => 'Tx_Myext_Domain_Model_Foo'
+               );
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
+               $mockDataMapFactory->expects($this->once())->method('setOneToManyRelation');
+               $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
+               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
+       }
+
+       /**
+        * @test
+        */
+       public function setRelationsDetectsManyToManyRelationOfTypeSelect() {
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $columnConfiguration = array(
+                       'type' => 'select',
+                       'foreign_table' => 'tx_myextension_bar',
+                       'MM' => 'tx_myextension_mm'
+               );
+               $propertyMetaData = array(
+                       'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
+                       'elementType' => 'Tx_Myext_Domain_Model_Foo'
+               );
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
+               $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
+               $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
+               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
+       }
+
+       /**
+        * @test
+        */
+       public function setRelationsDetectsManyToManyRelationOfTypeInlineWithIntermediateTable() {
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $columnConfiguration = array(
+                       'type' => 'inline',
+                       'foreign_table' => 'tx_myextension_righttable',
+                       'MM' => 'tx_myextension_mm'
+               );
+               $propertyMetaData = array(
+                       'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
+                       'elementType' => 'Tx_Myext_Domain_Model_Foo'
+               );
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
+               $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
+               $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
+               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
+       }
+
+       /**
+        * @test
+        */
+       public function setRelationsDetectsManyToManyRelationOfTypeInlineWithForeignSelector() {
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $columnConfiguration = array(
+                       'type' => 'inline',
+                       'foreign_table' => 'tx_myextension_mm',
+                       'foreign_field' => 'uid_local',
+                       'foreign_selector' => 'uid_foreign'
+               );
+               $propertyMetaData = array(
+                       'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
+                       'elementType' => 'Tx_Myext_Domain_Model_Foo'
+               );
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
+               $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
+               $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
+               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
+       }
+
+       /**
+        * @test
+        */
+       public function columnMapIsInitializedWithManyToManyRelationOfTypeSelect() {
+               $leftColumnsDefinition = array(
+                       'rights' => array(
+                               'type' => 'select',
+                               'foreign_table' => 'tx_myextension_righttable',
+                               'foreign_table_where' => 'WHERE 1=1',
+                               'MM' => 'tx_myextension_mm',
+                               'MM_table_where' => 'WHERE 2=2'
+                       )
+               );
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
+               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
+               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
+               $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with($this->equalTo('WHERE 1=1'));
+               $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
+               $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
+               $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
+               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
+               $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'), array(), '', FALSE);
+               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
+       }
+
+       /**
+        * @test
+        */
+       public function columnMapIsInitializedWithOppositeManyToManyRelationOfTypeSelect() {
+               $rightColumnsDefinition = array(
+                       'lefts' => array(
+                               'type' => 'select',
+                               'foreign_table' => 'tx_myextension_lefttable',
+                               'MM' => 'tx_myextension_mm',
+                               'MM_opposite_field' => 'rights'
+                       )
+               );
+               $leftColumnsDefinition['rights']['MM_opposite_field'] = 'opposite_field';
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
+               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
+               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_lefttable'));
+               $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with(NULL);
+               $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting_foreign'));
+               $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_foreign'));
+               $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
+               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
+               $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'), array(), '', FALSE);
+               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $rightColumnsDefinition['lefts']);
+       }
+
+       /**
+        * @test
+        */
+       public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndIntermediateTable() {
+               $leftColumnsDefinition = array(
+                       'rights' => array(
+                               'type' => 'inline',
+                               'foreign_table' => 'tx_myextension_righttable',
+                               'MM' => 'tx_myextension_mm',
+                               'foreign_sortby' => 'sorting'
+                       )
+               );
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
+               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
+               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
+               $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement');
+               $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
+               $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
+               $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
+               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
+               $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getColumnsDefinition'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->never())->method('getColumnsDefinition');
+               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
+       }
+
+       /**
+        * @test
+        */
+       public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndForeignSelector() {
+               $leftColumnsDefinition = array(
+                       'rights' => array(
+                               'type' => 'inline',
+                               'foreign_table' => 'tx_myextension_mm',
+                               'foreign_field' => 'uid_local',
+                               'foreign_selector' => 'uid_foreign',
+                               'foreign_sortby' => 'sorting'
+                       )
+               );
+               $relationTableColumnsDefiniton = array(
+                       'uid_local' => array(
+                               'config' => array('foreign_table' => 'tx_myextension_localtable')
+                       ),
+                       'uid_foreign' => array(
+                               'config' => array('foreign_table' => 'tx_myextension_righttable')
+                       )
+               );
+               $rightColumnsDefinition = array(
+                       'lefts' => array(
+                               'type' => 'inline',
+                               'foreign_table' => 'tx_myextension_mm',
+                               'foreign_field' => 'uid_foreign',
+                               'foreign_selector' => 'uid_local',
+                               'foreign_sortby' => 'sorting_foreign'
+                       )
+               );
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
+               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
+               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
+               $mockColumnMap->expects($this->never())->method('setChildTableWhereStatement');
+               $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
+               $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
+               $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
+               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
+               $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getColumnsDefinition'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefiniton));
+               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
+       }
+
+       /**
+        * @test
+        */
+       public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndForeignSelectorWithForeignTableField() {
+               $leftColumnsDefinition = array(
+                       'rights' => array(
+                               'type' => 'inline',
+                               'foreign_table' => 'tx_myextension_mm',
+                               'foreign_field' => 'uid_local',
+                               'foreign_selector' => 'uid_foreign',
+                               'foreign_table_field' => 'tx_myextension_localtable',
+                               'foreign_sortby' => 'sorting'
+                       )
+               );
+               $relationTableColumnsDefinition = array(
+                       'uid_local' => array(
+                               'config' => array('foreign_table' => 'tx_myextension_localtable')
+                       ),
+                       'uid_foreign' => array(
+                               'config' => array('foreign_table' => 'tx_myextension_righttable')
+                       )
+               );
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
+               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
+               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
+               $mockColumnMap->expects($this->never())->method('setChildTableWhereStatement');
+               $mockColumnMap->expects($this->once())->method('setChildSortbyFieldName')->with($this->equalTo('sorting'));
+               $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
+               $mockColumnMap->expects($this->once())->method('setParentTableFieldName')->with($this->equalTo('tx_myextension_localtable'));
+               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
+               $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
+
+               $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory'), array('getColumnsDefinition'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefinition));
+               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
+       }
+
+       /**
+        * @test
+        */
+       public function columnMapIsInitializedWithManyToManyRelationWithoutPidColumn() {
+               $leftColumnsDefinition = array(
+                       'rights' => array(
+                               'type' => 'select',
+                               'foreign_table' => 'tx_myextension_righttable',
+                               'foreign_table_where' => 'WHERE 1=1',
+                               'MM' => 'tx_myextension_mm'
+                       )
+               );
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
+               $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
+               $mockColumnMap->expects($this->never())->method('setrelationTablePageIdColumnName');
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(NULL));
+               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
+       }
+
+       /**
+        * @test
+        */
+       public function columnMapIsInitializedWithManyToManyRelationWithPidColumn() {
+               $leftColumnsDefinition = array(
+                       'rights' => array(
+                               'type' => 'select',
+                               'foreign_table' => 'tx_myextension_righttable',
+                               'foreign_table_where' => 'WHERE 1=1',
+                               'MM' => 'tx_myextension_mm'
+                       )
+               );
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
+               $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
+               $mockColumnMap->expects($this->once())->method('setrelationTablePageIdColumnName')->with($this->equalTo('pid'));
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
+               $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(array('ctrl' => array('foo' => 'bar'))));
+               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidClassException
+        */
+       public function buildDataMapThrowsExceptionIfClassNameIsNotKnown() {
+               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
+               $cacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', array('get'), array(), '', FALSE);
+               $cacheMock->expects($this->any())->method('get')->will($this->returnValue(FALSE));
+               $mockDataMapFactory->_set('dataMapCache', $cacheMock);
+               $mockDataMapFactory->buildDataMap('UnknownObject');
+       }
+
+       /**
+        * @test
+        */
+       public function buildDataMapFetchesSubclassesRecursively() {
+               $configuration = array(
+                       'persistence' => array(
+                               'classes' => array(
+                                       'TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser' => array(
+                                               'subclasses' => array(
+                                                       'Tx_SampleExt_Domain_Model_LevelOne1' => 'Tx_SampleExt_Domain_Model_LevelOne1',
+                                                       'Tx_SampleExt_Domain_Model_LevelOne2' => 'Tx_SampleExt_Domain_Model_LevelOne2'
+                                               )
+                                       ),
+                                       'Tx_SampleExt_Domain_Model_LevelOne1' => array(
+                                               'subclasses' => array(
+                                                       'Tx_SampleExt_Domain_Model_LevelTwo1' => 'Tx_SampleExt_Domain_Model_LevelTwo1',
+                                                       'Tx_SampleExt_Domain_Model_LevelTwo2' => 'Tx_SampleExt_Domain_Model_LevelTwo2'
+                                               )
+                                       ),
+                                       'Tx_SampleExt_Domain_Model_LevelOne2' => array(
+                                               'subclasses' => array()
+                                       )
+                               )
+                       )
+               );
+               $expectedSubclasses = array(
+                       'Tx_SampleExt_Domain_Model_LevelOne1',
+                       'Tx_SampleExt_Domain_Model_LevelTwo1',
+                       'Tx_SampleExt_Domain_Model_LevelTwo2',
+                       'Tx_SampleExt_Domain_Model_LevelOne2'
+               );
+               /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject */
+               $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
+               $configurationManager->expects($this->once())->method('getConfiguration')->with('Framework')->will($this->returnValue($configuration));
+               $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('test'));
+               $dataMapFactory->injectReflectionService(new \TYPO3\CMS\Extbase\Reflection\ReflectionService());
+               $dataMapFactory->injectObjectManager(new \TYPO3\CMS\Extbase\Object\ObjectManager());
+               $dataMapFactory->injectConfigurationManager($configurationManager);
+               $cacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', array(), array(), '', FALSE);
+               $cacheMock->expects($this->any())->method('get')->will($this->returnValue(FALSE));
+               $dataMapFactory->_set('dataMapCache', $cacheMock);
+               $dataMap = $dataMapFactory->buildDataMap('TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser');
+               $this->assertSame($dataMap->getSubclasses(), $expectedSubclasses);
+       }
+
+       /**
+        * @return array
+        */
+       public function classNameTableNameMappings() {
+               return array(
+                       'Core classes' => array('TYPO3\\CMS\\Belog\\Domain\\Model\\LogEntry', 'tx_belog_domain_model_logentry'),
+                       'Extension classes' => array('ExtbaseTeam\\BlogExample\\Domain\\Model\\Blog', 'tx_blogexample_domain_model_blog'),
+                       'Extension classes without namespace' => array('Tx_News_Domain_Model_News', 'tx_news_domain_model_news'),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider classNameTableNameMappings
+        */
+       public function resolveTableNameReturnsExpectedTablenames($className, $expected) {
+               $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'));
+               $this->assertSame($expected, $dataMapFactory->_call('resolveTableName', $className));
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapperTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapperTest.php
new file mode 100644 (file)
index 0000000..c068eee
--- /dev/null
@@ -0,0 +1,141 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Mapper;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Tymoteusz Motylewski <t.motylewski@gmail.com>
+ *  All rights reserved
+ *
+ *  Part of This class is a backport of the corresponding class of TYPO3 Flow.
+ *  Credits go to the v5 team.
+ *
+ *  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 \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
+ */
+class DataMapperTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function mapMapsArrayToObjectByCallingmapToObject() {
+               $rows = array(array('uid' => '1234'));
+               $object = new \stdClass();
+               $dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('mapSingleRow', 'getTargetType'));
+               $dataMapper->expects($this->any())->method('getTargetType')->will($this->returnArgument(1));
+               $dataMapFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory');
+               $dataMapper->injectDataMapFactory($dataMapFactory);
+               $dataMapper->expects($this->once())->method('mapSingleRow')->with($rows[0])->will($this->returnValue($object));
+               $dataMapper->map(get_class($object), $rows);
+       }
+
+       /**
+        * @test
+        */
+       public function mapSingleRowReturnsObjectFromIdentityMapIfAvailable() {
+               $row = array('uid' => '1234');
+               $object = new \stdClass();
+               $identityMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\IdentityMap');
+               $identityMap->expects($this->once())->method('hasIdentifier')->with('1234')->will($this->returnValue(TRUE));
+               $identityMap->expects($this->once())->method('getObjectByIdentifier')->with('1234')->will($this->returnValue($object));
+               $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('dummy'));
+               $dataMapper->injectIdentityMap($identityMap);
+               $dataMapper->_call('mapSingleRow', get_class($object), $row);
+       }
+
+       /**
+        * @test
+        */
+       public function thawPropertiesSetsPropertyValues() {
+               $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
+               eval('class ' . $className . ' extends TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity { public $firstProperty; public $secondProperty; public $thirdProperty; public $fourthProperty; }');
+               $object = new $className();
+               $row = array(
+                       'uid' => '1234',
+                       'firstProperty' => 'firstValue',
+                       'secondProperty' => 1234,
+                       'thirdProperty' => 1.234,
+                       'fourthProperty' => FALSE
+               );
+               $columnMaps = array(
+                       'uid' => new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('uid', 'uid'),
+                       'pid' => new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('pid', 'pid'),
+                       'firstProperty' => new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('firstProperty', 'firstProperty'),
+                       'secondProperty' => new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('secondProperty', 'secondProperty'),
+                       'thirdProperty' => new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('thirdProperty', 'thirdProperty')
+               );
+               $dataMap = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('dummy'), array($className, $className));
+               $dataMap->_set('columnMaps', $columnMaps);
+               $dataMaps = array(
+                       $className => $dataMap
+               );
+               $classSchema = new \TYPO3\CMS\Extbase\Reflection\ClassSchema($className);
+               $classSchema->injectTypeHandlingService(new \TYPO3\CMS\Extbase\Service\TypeHandlingService());
+               $classSchema->addProperty('pid', 'integer');
+               $classSchema->addProperty('uid', 'integer');
+               $classSchema->addProperty('firstProperty', 'string');
+               $classSchema->addProperty('secondProperty', 'integer');
+               $classSchema->addProperty('thirdProperty', 'float');
+               $classSchema->addProperty('fourthProperty', 'boolean');
+               $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array('getClassSchema'));
+               $mockReflectionService->expects($this->any())->method('getClassSchema')->will($this->returnValue($classSchema));
+               $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('dummy'));
+               $dataMapper->_set('dataMaps', $dataMaps);
+               $dataMapper->injectReflectionService($mockReflectionService);
+               $dataMapper->_call('thawProperties', $object, $row);
+               $this->assertAttributeEquals('firstValue', 'firstProperty', $object);
+               $this->assertAttributeEquals(1234, 'secondProperty', $object);
+               $this->assertAttributeEquals(1.234, 'thirdProperty', $object);
+               $this->assertAttributeEquals(FALSE, 'fourthProperty', $object);
+       }
+
+       /**
+        * Test if fetchRelatedEager method returns NULL when $fieldValue = '' and relation type == RELATION_HAS_ONE
+        *
+        * @test
+        */
+       public function fetchRelatedEagerReturnsNullForEmptyRelationHasOne() {
+               $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('columnName', 'propertyName');
+               $columnMap->setTypeOfRelation(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_ONE);
+               $dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getColumnMap'), array(), '', FALSE);
+               $dataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($columnMap));
+               $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap'));
+               $dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($dataMap));
+               $result = $dataMapper->_call('fetchRelatedEager', $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity'), 'SomeName', '');
+               $this->assertEquals(NULL, $result);
+       }
+
+       /**
+        * Test if fetchRelatedEager method returns empty array when $fieldValue = '' and relation type != RELATION_HAS_ONE
+        *
+        * @test
+        */
+       public function fetchRelatedEagerReturnsEmptyArrayForEmptyRelationNotHasOne() {
+               $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('columnName', 'propertyName');
+               $columnMap->setTypeOfRelation(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_BELONGS_TO_MANY);
+               $dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getColumnMap'), array(), '', FALSE);
+               $dataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($columnMap));
+               $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap'));
+               $dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($dataMap));
+               $result = $dataMapper->_call('fetchRelatedEager', $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity'), 'SomeName', '');
+               $this->assertEquals(array(), $result);
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/ObjectStorageTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/ObjectStorageTest.php
new file mode 100644 (file)
index 0000000..8b2d25f
--- /dev/null
@@ -0,0 +1,197 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  This class is a backport of the corresponding class of TYPO3 Flow.
+ *  All credits go to the TYPO3 Flow team.
+ *  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!
+ ***************************************************************/
+class ObjectStorageTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function anObjectCanBeAttached() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $objectStorage->attach($object1);
+               $objectStorage->attach($object2, 'foo');
+               $this->assertEquals($objectStorage[$object1], NULL);
+               $this->assertEquals($objectStorage[$object2], 'foo');
+       }
+
+       /**
+        * @test
+        */
+       public function anObjectCanBeDetached() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $objectStorage->attach($object1);
+               $objectStorage->attach($object2, 'foo');
+               $this->assertEquals(count($objectStorage), 2);
+               $objectStorage->detach($object1);
+               $this->assertEquals(count($objectStorage), 1);
+               $objectStorage->detach($object2);
+               $this->assertEquals(count($objectStorage), 0);
+       }
+
+       /**
+        * @test
+        */
+       public function offsetSetAssociatesDataToAnObjectInTheStorage() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $objectStorage->offsetSet($object1, 'foo');
+               $this->assertEquals(count($objectStorage), 1);
+               $objectStorage[$object2] = 'bar';
+               $this->assertEquals(count($objectStorage), 2);
+       }
+
+       /**
+        * @test
+        */
+       public function offsetUnsetRemovesAnObjectFromTheStorage() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $objectStorage->attach($object1);
+               $objectStorage->attach($object2, 'foo');
+               $this->assertEquals(count($objectStorage), 2);
+               $objectStorage->offsetUnset($object2);
+               $this->assertEquals(count($objectStorage), 1);
+               $objectStorage->offsetUnset($object1);
+               $this->assertEquals(count($objectStorage), 0);
+       }
+
+       /**
+        * @test
+        */
+       public function offsetGetReturnsTheDataAssociatedWithAnObject() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $objectStorage[$object1] = 'foo';
+               $objectStorage->attach($object2);
+               $this->assertEquals($objectStorage->offsetGet($object1), 'foo');
+               $this->assertEquals($objectStorage->offsetGet($object2), NULL);
+       }
+
+       /**
+        * @test
+        */
+       public function offsetExistsChecksWhetherAnObjectExistsInTheStorage() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $objectStorage->attach($object1);
+               $this->assertEquals($objectStorage->offsetExists($object1), TRUE);
+               $this->assertEquals($objectStorage->offsetExists($object2), FALSE);
+       }
+
+       /**
+        * @test
+        */
+       public function getInfoReturnsTheDataAssociatedWithTheCurrentIteratorEntry() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $object3 = new \StdClass();
+               $objectStorage->attach($object1, 42);
+               $objectStorage->attach($object2, 'foo');
+               $objectStorage->attach($object3, array('bar', 'baz'));
+               $objectStorage->rewind();
+               $this->assertEquals($objectStorage->getInfo(), 42);
+               $objectStorage->next();
+               $this->assertEquals($objectStorage->getInfo(), 'foo');
+               $objectStorage->next();
+               $this->assertEquals($objectStorage->getInfo(), array('bar', 'baz'));
+       }
+
+       /**
+        * @test
+        */
+       public function setInfoSetsTheDataAssociatedWithTheCurrentIteratorEntry() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $objectStorage->attach($object1);
+               $objectStorage->attach($object2, 'foo');
+               $objectStorage->rewind();
+               $objectStorage->setInfo(42);
+               $objectStorage->next();
+               $objectStorage->setInfo('bar');
+               $this->assertEquals($objectStorage[$object1], 42);
+               $this->assertEquals($objectStorage[$object2], 'bar');
+       }
+
+       /**
+        * @test
+        */
+       public function removeAllRemovesObjectsContainedInAnotherStorageFromTheCurrentStorage() {
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $objectStorageA = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $objectStorageA->attach($object1, 'foo');
+               $objectStorageB = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $objectStorageB->attach($object1, 'bar');
+               $objectStorageB->attach($object2, 'baz');
+               $this->assertEquals(count($objectStorageB), 2);
+               $objectStorageB->removeAll($objectStorageA);
+               $this->assertEquals(count($objectStorageB), 1);
+       }
+
+       /**
+        * @test
+        */
+       public function addAllAddsAllObjectsFromAnotherStorage() {
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $objectStorageA = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               // It might be better to mock this
+               $objectStorageA->attach($object1, 'foo');
+               $objectStorageB = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $objectStorageB->attach($object2, 'baz');
+               $this->assertEquals($objectStorageB->offsetExists($object1), FALSE);
+               $objectStorageB->addAll($objectStorageA);
+               $this->assertEquals($objectStorageB[$object1], 'foo');
+               $this->assertEquals($objectStorageB[$object2], 'baz');
+       }
+
+       /**
+        * @test
+        */
+       public function theStorageCanBeRetrievedAsArray() {
+               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $object1 = new \StdClass();
+               $object2 = new \StdClass();
+               $objectStorage->attach($object1, 'foo');
+               $objectStorage->attach($object2, 'bar');
+               $this->assertEquals($objectStorage->toArray(), array($object1, $object2));
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/PersistenceManagerTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/PersistenceManagerTest.php
new file mode 100644 (file)
index 0000000..339265b
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Nico de Haen
+ *  All rights reserved
+ *
+ *  This class is a backport of the corresponding class of FLOW3.
+ *  All credits go to the v5 team.
+ *
+ *  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!
+ ***************************************************************/
+/**
+ * A PersistenceManager Test
+ */
+class PersistenceManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @test
+        *
+        * This test and the related Fixtures TxDomainModelTestEntity and
+        * TxDomainRepositoryTestEntityRepository can be removed if we do not need to support
+        * underscore class names instead of namespaced class names
+        */
+       public function persistAllAddsReconstitutedObjectFromSessionToBackendsAggregateRootObjects() {
+               $className = uniqid('BazFixture');
+               eval ('
+                       class Foo_Bar_Domain_Model_' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {}
+               ');
+               eval ('
+                       class Foo_Bar_Domain_Repository_' . $className . 'Repository {}
+               ');
+
+               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
+               $aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $fullClassName = 'Foo_Bar_Domain_Model_' . $className;
+               $entity1 = new $fullClassName();
+               $aggregateRootObjects->attach($entity1);
+               $persistenceSession->registerReconstitutedObject($entity1);
+               $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend'), array('commit', 'setAggregateRootObjects', 'setDeletedObjects'), array(), '', FALSE);
+               $persistenceManager = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'), array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->expects($this->once())
+                       ->method('setAggregateRootObjects')
+                       ->with($this->equalTo($aggregateRootObjects));
+               $persistenceManager->_set('backend', $mockTypo3DbBackend);
+               $persistenceManager->injectSession($persistenceSession);
+               $persistenceManager->persistAll();
+       }
+
+       /**
+        * @test
+        */
+       public function persistAllAddsNamespacedReconstitutedObjectFromSessionToBackendsAggregateRootObjects() {
+               $className = uniqid('BazFixture');
+               eval ('
+                       namespace Foo\\Bar\\Domain\\Model;
+                       class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {}
+               ');
+               eval ('
+                       namespace Foo\\Bar\\Domain\\Repository;
+                       class  ' . $className . 'Repository {}
+               ');
+
+               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
+               $aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $classNameWithNamespace = 'Foo\\Bar\\Domain\\Model\\' . $className;
+               $entity1 = new $classNameWithNamespace();
+               $aggregateRootObjects->attach($entity1);
+               $persistenceSession->registerReconstitutedObject($entity1);
+               $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend'), array('commit', 'setAggregateRootObjects', 'setDeletedObjects'), array(), '', FALSE);
+               $persistenceManager = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'), array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->expects($this->once())
+                       ->method('setAggregateRootObjects')
+                       ->with($this->equalTo($aggregateRootObjects));
+               $persistenceManager->_set('backend', $mockTypo3DbBackend);
+               $persistenceManager->injectSession($persistenceSession);
+               $persistenceManager->persistAll();
+       }
+
+       /**
+        * @test
+        */
+       public function persistAllAddsRemovedObjectsFromRepositoriesToBackendsDeletedObjects() {
+               $this->markTestIncomplete();
+       }
+
+       /**
+        * @test
+        */
+       public function persistAllAddsAddedObjectsFromRepositoriesToBackendsAggregateRootObjects() {
+               $this->markTestIncomplete();
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryFactoryTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryFactoryTest.php
new file mode 100644 (file)
index 0000000..3e13d34
--- /dev/null
@@ -0,0 +1,120 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Alexander Schnitzler <alex.schnitzler@typovision.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 \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
+ *
+ * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
+ * @author Oliver Klee <typo3-coding@oliverklee.de>
+ */
+class QueryFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var string
+        */
+       protected $className = 'Vendor\\Ext\\Domain\\Model\\ClubMate';
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
+        */
+       protected $queryFactory = NULL;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $objectManager = NULL;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $dataMapper = NULL;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject
+        */
+       protected $dataMap;
+
+       protected function setUp() {
+               $this->dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getIsStatic', 'getRootLevel'), array('Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate'));
+
+               $this->queryFactory = new \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory();
+               $this->queryFactory->injectConfigurationManager(
+                       $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface')
+               );
+
+               $this->objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
+               $this->queryFactory->injectObjectManager($this->objectManager);
+
+               $this->dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap', 'convertClassNameToTableName'));
+               $this->dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($this->dataMap));
+               $this->queryFactory->injectDataMapper($this->dataMapper);
+       }
+
+       protected function tearDown() {
+               unset($this->objectManager, $this->dataMapper, $this->queryFactory);
+       }
+
+       public function getStaticAndRootLevelAndExpectedResult() {
+               return array(
+                       'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => array(FALSE, FALSE, TRUE),
+                       'Respect storage page is set when entity is marked as static and rootLevel.' => array(TRUE, TRUE, FALSE),
+                       'Respect storage page is set when entity is marked as static but not rootLevel.' => array(TRUE, FALSE, FALSE),
+                       'Respect storage page is set when entity is not marked as static but as rootLevel.' => array(FALSE, TRUE, FALSE),
+               );
+       }
+
+       /**
+        * @param boolean $static
+        * @param boolean $rootLevel
+        * @param boolean $expectedResult
+        *
+        * @dataProvider getStaticAndRootLevelAndExpectedResult
+        * @test
+        */
+       public function createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult) {
+               $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
+               $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
+
+               $query = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
+               $this->objectManager->expects($this->at(0))->method('create')
+                       ->with('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface')
+                       ->will($this->returnValue($query));
+
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $this->objectManager->expects($this->at(1))->method('create')
+                       ->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface')
+                       ->will($this->returnValue($querySettings));
+               $query->expects($this->once())->method('setQuerySettings')->with($querySettings);
+               $this->queryFactory->create($this->className);
+
+               $this->assertSame(
+                       $expectedResult,
+                       $querySettings->getRespectStoragePage()
+               );
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryResultTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryResultTest.php
new file mode 100644 (file)
index 0000000..50cca65
--- /dev/null
@@ -0,0 +1,182 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010 Bastian Waidelich <bastian@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!
+ ***************************************************************/
+class QueryResultTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult
+        */
+       protected $queryResult;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\QueryInterface
+        */
+       protected $mockQuery;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
+        */
+       protected $mockPersistenceManager;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
+        */
+       protected $mockDataMapper;
+
+       /**
+        * @var array
+        */
+       protected $sampleResult = array();
+
+       /**
+        * Sets up this test case
+        *
+        * @return void
+        */
+       public function setUp() {
+               $this->mockPersistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
+               $this->mockPersistenceManager->expects($this->any())->method('getObjectDataByQuery')->will($this->returnValue(array('one', 'two')));
+               $this->mockPersistenceManager->expects($this->any())->method('getObjectCountByQuery')->will($this->returnValue(2));
+               $this->mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper');
+               $this->mockQuery = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
+               $this->queryResult = new \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult($this->mockQuery);
+               $this->queryResult->injectPersistenceManager($this->mockPersistenceManager);
+               $this->queryResult->injectDataMapper($this->mockDataMapper);
+               $this->sampleResult = array(array('foo' => 'Foo1', 'bar' => 'Bar1'), array('foo' => 'Foo2', 'bar' => 'Bar2'));
+               $this->mockDataMapper->expects($this->any())->method('map')->will($this->returnValue($this->sampleResult));
+       }
+
+       /**
+        * @test
+        */
+       public function getQueryReturnsQueryObject() {
+               $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface', $this->queryResult->getQuery());
+       }
+
+       /**
+        * @test
+        */
+       public function getQueryReturnsAClone() {
+               $this->assertNotSame($this->mockQuery, $this->queryResult->getQuery());
+       }
+
+       /**
+        * @test
+        */
+       public function offsetExistsWorksAsExpected() {
+               $this->assertTrue($this->queryResult->offsetExists(0));
+               $this->assertFalse($this->queryResult->offsetExists(2));
+               $this->assertFalse($this->queryResult->offsetExists('foo'));
+       }
+
+       /**
+        * @test
+        */
+       public function offsetGetWorksAsExpected() {
+               $this->assertEquals(array('foo' => 'Foo1', 'bar' => 'Bar1'), $this->queryResult->offsetGet(0));
+               $this->assertNull($this->queryResult->offsetGet(2));
+               $this->assertNull($this->queryResult->offsetGet('foo'));
+       }
+
+       /**
+        * @test
+        */
+       public function offsetSetWorksAsExpected() {
+               $this->queryResult->offsetSet(0, array('foo' => 'FooOverridden', 'bar' => 'BarOverridden'));
+               $this->assertEquals(array('foo' => 'FooOverridden', 'bar' => 'BarOverridden'), $this->queryResult->offsetGet(0));
+       }
+
+       /**
+        * @test
+        */
+       public function offsetUnsetWorksAsExpected() {
+               $this->queryResult->offsetUnset(0);
+               $this->assertFalse($this->queryResult->offsetExists(0));
+       }
+
+       /**
+        * @test
+        */
+       public function countDoesNotInitializeProxy() {
+               $queryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult', array('initialize'), array($this->mockQuery));
+               $queryResult->injectPersistenceManager($this->mockPersistenceManager);
+               $queryResult->expects($this->never())->method('initialize');
+               $queryResult->count();
+       }
+
+       /**
+        * @test
+        */
+       public function countCallsGetObjectCountByQueryOnPersistenceManager() {
+               $queryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult', array('initialize'), array($this->mockQuery));
+               $queryResult->injectPersistenceManager($this->mockPersistenceManager);
+               $this->assertEquals(2, $queryResult->count());
+       }
+
+       /**
+        * @test
+        */
+       public function iteratorMethodsAreCorrectlyImplemented() {
+               $array1 = array('foo' => 'Foo1', 'bar' => 'Bar1');
+               $array2 = array('foo' => 'Foo2', 'bar' => 'Bar2');
+               $this->assertEquals($array1, $this->queryResult->current());
+               $this->assertTrue($this->queryResult->valid());
+               $this->queryResult->next();
+               $this->assertEquals($array2, $this->queryResult->current());
+               $this->assertTrue($this->queryResult->valid());
+               $this->assertEquals(1, $this->queryResult->key());
+               $this->queryResult->next();
+               $this->assertFalse($this->queryResult->current());
+               $this->assertFalse($this->queryResult->valid());
+               $this->assertNull($this->queryResult->key());
+               $this->queryResult->rewind();
+               $this->assertEquals(0, $this->queryResult->key());
+               $this->assertEquals($array1, $this->queryResult->current());
+       }
+
+       /**
+        * @test
+        */
+       public function initializeExecutesQueryWithArrayFetchMode() {
+               /** @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $queryResult = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult', array('dummy'), array($this->mockQuery));
+               $queryResult->injectPersistenceManager($this->mockPersistenceManager);
+               $queryResult->injectDataMapper($this->mockDataMapper);
+               $this->mockPersistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->mockQuery)->will($this->returnValue(array('FAKERESULT')));
+               $queryResult->_call('initialize');
+       }
+
+       /**
+        * @test
+        */
+       public function usingCurrentOnTheQueryResultReturnsAWarning() {
+               $queryResult = new \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult($this->mockQuery);
+               $expectedResult = 'You should never see this warning. If you do, you probably used PHP array functions like current() on the TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult. To retrieve the first result, you can use the getFirst() method.';
+               $actualResult = current($queryResult);
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/QueryTest.php
new file mode 100644 (file)
index 0000000..5fdb574
--- /dev/null
@@ -0,0 +1,163 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
+ *  (c) 2010 Bastian Waidelich <bastian@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!
+ ***************************************************************/
+class QueryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Query
+        */
+       protected $query;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
+        */
+       protected $querySettings;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
+        */
+       protected $objectManager;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
+        */
+       protected $persistenceManager;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
+        */
+       protected $backend;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
+        */
+       protected $dataMapper;
+
+       /**
+        * Sets up this test case
+        *
+        * @return void
+        */
+       public function setUp() {
+               $this->objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
+               $this->query = new \TYPO3\CMS\Extbase\Persistence\Generic\Query('someType');
+               $this->query->injectObjectManager($this->objectManager);
+               $this->querySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
+               $this->query->setQuerySettings($this->querySettings);
+               $this->persistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
+               $this->backend = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\BackendInterface');
+               $this->backend->expects($this->any())->method('getQomFactory')->will($this->returnValue(NULL));
+               $this->persistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
+               $this->query->injectPersistenceManager($this->persistenceManager);
+               $this->dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper');
+               $this->query->injectDataMapper($this->dataMapper);
+       }
+
+       /**
+        * @test
+        */
+       public function executeReturnsQueryResultInstanceAndInjectsItself() {
+               $queryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult', array(), array(), '', FALSE);
+               $this->objectManager->expects($this->once())->method('create')->with('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface', $this->query)->will($this->returnValue($queryResult));
+               $actualResult = $this->query->execute();
+               $this->assertSame($queryResult, $actualResult);
+       }
+
+       /**
+        * @test
+        */
+       public function executeReturnsRawObjectDataIfRawQueryResultSettingIsTrue() {
+               $this->querySettings->expects($this->once())->method('getReturnRawQueryResult')->will($this->returnValue(TRUE));
+               $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult'));
+               $expectedResult = 'rawQueryResult';
+               $actualResult = $this->query->execute();
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+
+       /**
+        * @test
+        * @expectedException \InvalidArgumentException
+        */
+       public function setLimitAcceptsOnlyIntegers() {
+               $this->query->setLimit(1.5);
+       }
+
+       /**
+        * @test
+        * @expectedException \InvalidArgumentException
+        */
+       public function setLimitRejectsIntegersLessThanOne() {
+               $this->query->setLimit(0);
+       }
+
+       /**
+        * @test
+        * @expectedException \InvalidArgumentException
+        */
+       public function setOffsetAcceptsOnlyIntegers() {
+               $this->query->setOffset(1.5);
+       }
+
+       /**
+        * @test
+        * @expectedException \InvalidArgumentException
+        */
+       public function setOffsetRejectsIntegersLessThanZero() {
+               $this->query->setOffset(-1);
+       }
+
+       /**
+        * @return array
+        */
+       public function equalsForCaseSensitiveFalseLowercasesOperandProvider() {
+               return array(
+                       'Polish alphabet' => array('name', 'ĄĆĘŁŃÓŚŹŻABCDEFGHIJKLMNOPRSTUWYZQXVąćęłńóśźżabcdefghijklmnoprstuwyzqxv', 'ąćęłńóśźżabcdefghijklmnoprstuwyzqxvąćęłńóśźżabcdefghijklmnoprstuwyzqxv'),
+                       'German alphabet' => array('name', 'ßÜÖÄüöä', 'ßüöäüöä'),
+                       'Greek alphabet' => array('name', 'Τάχιστη αλώπηξ βαφής ψημένη γη', 'τάχιστη αλώπηξ βαφής ψημένη γη'),
+                       'Russian alphabet' => array('name', 'АВСТРАЛИЯавстралия', 'австралияавстралия')
+               );
+       }
+
+       /**
+        * Checks if equals condition makes utf-8 argument lowercase correctly
+        *
+        * @test
+        * @dataProvider equalsForCaseSensitiveFalseLowercasesOperandProvider
+        * @param string $propertyName The name of the property to compare against
+        * @param mixed $operand The value to compare with
+        * @param string $expectedOperand
+        */
+       public function equalsForCaseSensitiveFalseLowercasesOperand($propertyName, $operand, $expectedOperand) {
+               /** @var $qomFactory \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory */
+               $qomFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\QueryObjectModelFactory', array('comparison'));
+               $qomFactory->injectObjectManager(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'));
+               $qomFactory->expects($this->once())->method('comparison')->with($this->anything(), $this->anything(), $expectedOperand);
+               $this->query->injectQomFactory($qomFactory);
+               $this->query->equals($propertyName, $operand, FALSE);
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/RepositoryTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/RepositoryTest.php
new file mode 100644 (file)
index 0000000..1e4b95e
--- /dev/null
@@ -0,0 +1,418 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2010 Bastian Waidelich <bastian@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!
+ ***************************************************************/
+class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Repository|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
+        */
+       protected $repository;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
+        */
+       protected $mockObjectManager;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\IdentityMap
+        */
+       protected $mockIdentityMap;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
+        */
+       protected $mockQueryFactory;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
+        */
+       protected $mockBackend;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Session
+        */
+       protected $mockSession;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
+        */
+       protected $mockPersistenceManager;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\QueryInterface
+        */
+       protected $mockQuery;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
+        */
+       protected $querySettings;
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
+        */
+       protected $mockQuerySettings;
+
+       public function setUp() {
+               $this->mockIdentityMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\IdentityMap');
+               $this->mockQueryFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory');
+               $this->mockQuery = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
+               $this->mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
+               $this->mockQuery->expects($this->any())->method('getQuerySettings')->will($this->returnValue($this->mockQuerySettings));
+               $this->mockQueryFactory->expects($this->any())->method('create')->will($this->returnValue($this->mockQuery));
+               $this->mockBackend = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\BackendInterface');
+               $this->mockSession = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Session');
+               $this->mockPersistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
+               $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
+               $this->repository = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Repository', array('dummy'), array($this->mockObjectManager));
+               $this->repository->injectIdentityMap($this->mockIdentityMap);
+               $this->repository->injectQueryFactory($this->mockQueryFactory);
+               $this->repository->injectPersistenceManager($this->mockPersistenceManager);
+               $this->repository->injectBackend($this->mockBackend);
+               $this->repository->injectSession($this->mockSession);
+       }
+
+       /**
+        * @test
+        */
+       public function abstractRepositoryImplementsRepositoryInterface() {
+               $this->assertTrue($this->repository instanceof \TYPO3\CMS\Extbase\Persistence\RepositoryInterface);
+       }
+
+       /**
+        * @test
+        */
+       public function addActuallyAddsAnObjectToTheInternalObjectsArray() {
+               $someObject = new \stdClass();
+               $this->repository->_set('objectType', get_class($someObject));
+               $this->repository->add($someObject);
+               $this->assertTrue($this->repository->getAddedObjects()->contains($someObject));
+       }
+
+       /**
+        * @test
+        */
+       public function removeActuallyRemovesAnObjectFromTheInternalObjectsArray() {
+               $object1 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
+               $object2 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
+               $object3 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
+               $this->repository->_set('objectType', get_class($object1));
+               $this->repository->add($object1);
+               $this->repository->add($object2);
+               $this->repository->add($object3);
+               $this->repository->remove($object2);
+               $this->assertTrue($this->repository->getAddedObjects()->contains($object1));
+               $this->assertFalse($this->repository->getAddedObjects()->contains($object2));
+               $this->assertTrue($this->repository->getAddedObjects()->contains($object3));
+       }
+
+       /**
+        * @test
+        */
+       public function removeRemovesTheRightObjectEvenIfItHasBeenModifiedSinceItsAddition() {
+               $object1 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
+               $object2 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
+               $object3 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
+               $this->repository->_set('objectType', get_class($object1));
+               $this->repository->add($object1);
+               $this->repository->add($object2);
+               $this->repository->add($object3);
+               $object2->setPid(1);
+               $object3->setPid(2);
+               $this->repository->remove($object2);
+               $this->assertTrue($this->repository->getAddedObjects()->contains($object1));
+               $this->assertFalse($this->repository->getAddedObjects()->contains($object2));
+               $this->assertTrue($this->repository->getAddedObjects()->contains($object3));
+       }
+
+       /**
+        * Make sure we remember the objects that are not currently add()ed
+        * but might be in persistent storage.
+        *
+        * @test
+        */
+       public function removeRetainsObjectForObjectsNotInCurrentSession() {
+               $object = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
+               // if the object is not currently add()ed, it is not new
+               $object->expects($this->once())->method('_isNew')->will($this->returnValue(FALSE));
+               $this->repository->_set('objectType', get_class($object));
+               $this->repository->remove($object);
+               $this->assertTrue($this->repository->getRemovedObjects()->contains($object));
+       }
+
+       /**
+        * dataProvider for createQueryCallsQueryFactoryWithExpectedType
+        *
+        * @return array
+        */
+       public function modelAndRepositoryClassNames() {
+               return array(
+                       array('Tx_BlogExample_Domain_Repository_BlogRepository', 'Tx_BlogExample_Domain_Model_Blog'),
+                       array('_Domain_Repository_Content_PageRepository', '_Domain_Model_Content_Page'),
+                       array('Tx_RepositoryExample_Domain_Repository_SomeModelRepository', 'Tx_RepositoryExample_Domain_Model_SomeModel'),
+                       array('Tx_RepositoryExample_Domain_Repository_RepositoryRepository', 'Tx_RepositoryExample_Domain_Model_Repository'),
+                       array('Tx_Repository_Domain_Repository_RepositoryRepository', 'Tx_Repository_Domain_Model_Repository')
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider modelAndRepositoryClassNames
+        * @param string $repositoryClassName
+        * @param string $modelClassName
+        */
+       public function constructSetsObjectTypeFromClassName($repositoryClassName, $modelClassName) {
+               $mockClassName = 'MockRepository' . uniqid();
+               eval('class ' . $mockClassName . ' extends TYPO3\\CMS\\Extbase\\Persistence\\Repository {
+                       protected function getRepositoryClassName() {
+                               return \'' . $repositoryClassName . '\';
+                       }
+                       public function _getObjectType() {
+                               return $this->objectType;
+                       }
+               }');
+               $this->repository = new $mockClassName($this->mockObjectManager);
+               $this->assertEquals($modelClassName, $this->repository->_getObjectType());
+       }
+
+       /**
+        * @test
+        */
+       public function createQueryCallsQueryFactoryWithExpectedClassName() {
+               $this->mockQueryFactory->expects($this->once())->method('create')->with('ExpectedType');
+               $this->repository->_set('objectType', 'ExpectedType');
+               $this->repository->createQuery();
+       }
+
+       /**
+        * @test
+        */
+       public function createQueryReturnsQueryWithUnmodifiedDefaultQuerySettings() {
+               $mockQueryFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory');
+               $mockQuery = new \TYPO3\CMS\Extbase\Persistence\Generic\Query('foo');
+               $mockDefaultQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
+               $this->repository->injectQueryFactory($mockQueryFactory);
+               $this->repository->setDefaultQuerySettings($mockDefaultQuerySettings);
+               $mockQueryFactory->expects($this->once())->method('create')->will($this->returnValue($mockQuery));
+               $this->repository->createQuery();
+               $instanceQuerySettings = $mockQuery->getQuerySettings();
+               $this->assertEquals($mockDefaultQuerySettings, $instanceQuerySettings);
+               $this->assertNotSame($mockDefaultQuerySettings, $instanceQuerySettings);
+       }
+
+       /**
+        * @test
+        */
+       public function findAllCreatesQueryAndReturnsResultOfExecuteCall() {
+               $expectedResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface');
+               $this->mockQuery->expects($this->once())->method('execute')->with()->will($this->returnValue($expectedResult));
+               $this->assertSame($expectedResult, $this->repository->findAll());
+       }
+
+       /**
+        * @test
+        */
+       public function findByUidReturnsResultOfGetObjectByIdentifierCall() {
+               $fakeUid = '123';
+               $object = new \stdClass();
+               $this->repository->_set('objectType', 'someObjectType');
+               $this->mockIdentityMap->expects($this->once())->method('hasIdentifier')->with($fakeUid, 'someObjectType')->will($this->returnValue(TRUE));
+               $this->mockIdentityMap->expects($this->once())->method('getObjectByIdentifier')->with($fakeUid)->will($this->returnValue($object));
+               $expectedResult = $object;
+               $actualResult = $this->repository->findByUid($fakeUid);
+               $this->assertSame($expectedResult, $actualResult);
+       }
+
+       /**
+        * Replacing a reconstituted object (which has a uuid) by a new object
+        * will ask the persistence backend to replace them accordingly in the
+        * identity map.
+        *
+        * @test
+        * @return void
+        */
+       public function replaceReplacesReconstitutedEntityByNewObject() {
+               $existingObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
+               $newObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
+               $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('123'));
+               $this->mockBackend->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);
+               $this->repository->_set('objectType', get_class($newObject));
+               $this->repository->replace($existingObject, $newObject);
+       }
+
+       /**
+        * Replacing a reconstituted object which during this session has been
+        * marked for removal (by calling the repository's remove method)
+        * additionally registers the "newObject" for removal and removes the
+        * "existingObject" from the list of removed objects.
+        *
+        * @test
+        * @return void
+        */
+       public function replaceRemovesReconstitutedObjectWhichIsMarkedToBeRemoved() {
+               $existingObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
+               $newObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
+               $removedObjects = new \SplObjectStorage();
+               $removedObjects->attach($existingObject);
+               $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('123'));
+               $this->mockBackend->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);
+               $this->repository->_set('objectType', get_class($newObject));
+               $this->repository->_set('removedObjects', $removedObjects);
+               $this->repository->replace($existingObject, $newObject);
+               $this->assertFalse($removedObjects->contains($existingObject));
+               $this->assertTrue($removedObjects->contains($newObject));
+       }
+
+       /**
+        * Replacing a new object which has not yet been persisted by another
+        * new object will just replace them in the repository's list of added
+        * objects.
+        *
+        * @test
+        * @return void
+        */
+       public function replaceAddsNewObjectToAddedObjects() {
+               $existingObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
+               $newObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
+               $addedObjects = new \SplObjectStorage();
+               $addedObjects->attach($existingObject);
+               $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue(NULL));
+               $this->mockBackend->expects($this->never())->method('replaceObject');
+               $this->repository->_set('objectType', get_class($newObject));
+               $this->repository->_set('addedObjects', $addedObjects);
+               $this->repository->replace($existingObject, $newObject);
+               $this->assertFalse($addedObjects->contains($existingObject));
+               $this->assertTrue($addedObjects->contains($newObject));
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
+        */
+       public function replaceChecksObjectType() {
+               $this->repository->_set('objectType', 'ExpectedObjectType');
+               $this->repository->replace(new \stdClass(), new \stdClass());
+       }
+
+       /**
+        * @test
+        */
+       public function updateReplacesAnObjectWithTheSameUuidByTheGivenObject() {
+               $existingObject = new \stdClass();
+               $modifiedObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
+               $modifiedObject->expects($this->once())->method('getUid')->will($this->returnValue('123'));
+               /** @var \TYPO3\CMS\Extbase\Persistence\Repository|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $repository = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Repository', array('findByUid', 'replace'), array($this->mockObjectManager));
+               $repository->expects($this->once())->method('findByUid')->with('123')->will($this->returnValue($existingObject));
+               $repository->expects($this->once())->method('replace')->with($existingObject, $modifiedObject);
+               $repository->_set('objectType', get_class($modifiedObject));
+               $repository->update($modifiedObject);
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
+        */
+       public function updateRejectsUnknownObjects() {
+               $someObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
+               $someObject->expects($this->once())->method('getUid')->will($this->returnValue(NULL));
+               $this->repository->_set('objectType', get_class($someObject));
+               $this->repository->update($someObject);
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
+        */
+       public function updateRejectsObjectsOfWrongType() {
+               $this->repository->_set('objectType', 'Foo');
+               $this->repository->update(new \stdClass());
+       }
+
+       /**
+        * @test
+        */
+       public function magicCallMethodAcceptsFindBySomethingCallsAndExecutesAQueryWithThatCriteria() {
+               $mockQueryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface');
+               $this->mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
+               $this->mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($this->mockQuery));
+               $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
+               $this->assertSame($mockQueryResult, $this->repository->findByFoo('bar'));
+       }
+
+       /**
+        * @test
+        */
+       public function magicCallMethodAcceptsFindOneBySomethingCallsAndExecutesAQueryWithThatCriteria() {
+               $object = new \stdClass();
+               $mockQueryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface');
+               $mockQueryResult->expects($this->once())->method('getFirst')->will($this->returnValue($object));
+               $this->mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
+               $this->mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($this->mockQuery));
+               $this->mockQuery->expects($this->once())->method('setLimit')->with(1)->will($this->returnValue($this->mockQuery));
+               $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
+               $this->assertSame($object, $this->repository->findOneByFoo('bar'));
+       }
+
+       /**
+        * @test
+        */
+       public function magicCallMethodAcceptsCountBySomethingCallsAndExecutesAQueryWithThatCriteria() {
+               $mockQueryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface');
+               $mockQueryResult->expects($this->once())->method('count')->will($this->returnValue(2));
+               $this->mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
+               $this->mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($this->mockQuery));
+               $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
+               $this->assertSame(2, $this->repository->countByFoo('bar'));
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException
+        */
+       public function magicCallMethodTriggersAnErrorIfUnknownMethodsAreCalled() {
+               $this->repository->__call('foo', array());
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
+        */
+       public function addChecksObjectType() {
+               $this->repository->_set('objectType', 'ExpectedObjectType');
+               $this->repository->add(new \stdClass());
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
+        */
+       public function removeChecksObjectType() {
+               $this->repository->_set('objectType', 'ExpectedObjectType');
+               $this->repository->remove(new \stdClass());
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/SessionTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/SessionTest.php
new file mode 100644 (file)
index 0000000..fcafa67
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  This class is a backport of the corresponding class of TYPO3 Flow.
+ *  All credits go to the TYPO3 Flow team.
+ *  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!
+ ***************************************************************/
+class SessionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @test
+        */
+       public function newSessionIsEmpty() {
+               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
+               $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
+               $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
+       }
+
+       /**
+        * @test
+        */
+       public function objectCanBeRegisteredAsReconstituted() {
+               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
+               $entity = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity');
+               $persistenceSession->registerReconstitutedObject($entity);
+               $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
+               $this->assertTrue($reconstitutedObjects->contains($entity), 'The object was not registered as reconstituted.');
+       }
+
+       /**
+        * @test
+        */
+       public function objectCanBeUnregisteredAsReconstituted() {
+               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
+               $entity = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity');
+               $persistenceSession->registerReconstitutedObject($entity);
+               $persistenceSession->unregisterReconstitutedObject($entity);
+               $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
+               $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php
new file mode 100644 (file)
index 0000000..1e80ca9
--- /dev/null
@@ -0,0 +1,488 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Storage;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  This class is a backport of the corresponding class of TYPO3 Flow.
+ *  All credits go to the TYPO3 Flow team.
+ *  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!
+ ***************************************************************/
+class Typo3DbBackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * This is the data provider for the statement generation with a basic comparison
+        *
+        * @return array An array of data
+        */
+       public function providerForBasicComparison() {
+               return array(
+                       'equal' => array(
+                               \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_EQUAL_TO,
+                               'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo = \'baz\''
+                       ),
+                       'less' => array(
+                               \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_LESS_THAN,
+                               'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo < \'baz\''
+                       ),
+                       'less or equal' => array(
+                               \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO,
+                               'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo <= \'baz\''
+                       ),
+                       'greater' => array(
+                               \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_GREATER_THAN,
+                               'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo > \'baz\''
+                       ),
+                       'greater or equal' => array(
+                               \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO,
+                               'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo >= \'baz\''
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getStatementWorksWithMinimalisticQueryObjectModel() {
+               $this->markTestIncomplete();
+       }
+
+       /**
+        * @test
+        */
+       public function getStatementWorksWithBasicEqualsCondition() {
+               $this->markTestIncomplete();
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException
+        */
+       public function countRowsWithStatementConstraintResultsInAnException() {
+               $this->markTestIncomplete();
+       }
+
+       /**
+        * @test
+        */
+       public function joinStatementGenerationWorks() {
+               $this->markTestIncomplete();
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForDefaultLanguage() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid'
+               );
+               $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
+               $tsfe->sys_language_content = 0;
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $querySettings->initializeObject();
+               $GLOBALS['TSFE'] = $tsfe;
+               $sql = array();
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForNonDefaultLanguageInFrontend() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid'
+               );
+               $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
+               $tsfe->sys_language_content = 1;
+               $GLOBALS['TSFE'] = $tsfe;
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $querySettings->initializeObject();
+               $sql = array();
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (1,-1))'));
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForNonDefaultLanguageInBackend() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid'
+               );
+               $_GET['L'] = 1;
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $querySettings->initializeObject();
+               $sql = array();
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (1,-1))'));
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksInBackendContextWithNoGlobalTypoScriptFrontendControllerAvailable() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid'
+               );
+               $sql = array();
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForDefaultLanguageWithoutDeleteStatementReturned() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid',
+                       'delete' => 'deleted'
+               );
+               $sql = array();
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $querySettings->setSysLanguageUid(0);
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForForeignLanguageWithoutSubselection() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid'
+               );
+               $sql = array();
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $querySettings->setSysLanguageUid(2);
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (2,-1))'));
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionWithoutDeleteStatementReturned() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid',
+                       'transOrigPointerField' => 'l10n_parent'
+               );
+               $sql = array();
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $querySettings->setSysLanguageUid(2);
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
+               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (2,-1) OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (SELECT ' . $table . '.l10n_parent FROM ' . $table . ' WHERE ' . $table . '.l10n_parent>0 AND ' . $table . '.sys_language_uid>0)))'));
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionTakesDeleteStatementIntoAccountIfNecessary() {
+               $table = uniqid('tx_coretest_table');
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid',
+                       'transOrigPointerField' => 'l10n_parent',
+                       'delete' => 'deleted'
+               );
+               $sql = array();
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $querySettings->setSysLanguageUid(2);
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
+               $expectedSql = array('additionalWhereClause' => array(
+                       '(' . $table . '.sys_language_uid IN (2,-1)' .
+                               ' OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (' .
+                               'SELECT ' . $table . '.l10n_parent FROM ' . $table .
+                               ' WHERE ' . $table . '.l10n_parent>0 AND ' .
+                               $table . '.sys_language_uid>0 AND ' .
+                               $table . '.deleted=0)))')
+               );
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function addSysLanguageStatementWorksInBackendContextWithSubselectionTakesDeleteStatementIntoAccountIfNecessary() {
+               $table = uniqid('tx_coretest_table');
+               $table = 'tt_content';
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'languageField' => 'sys_language_uid',
+                       'transOrigPointerField' => 'l10n_parent',
+                       'delete' => 'deleted'
+               );
+               $sql = array();
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $querySettings->setSysLanguageUid(2);
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
+               $expectedSql = array('additionalWhereClause' => array(
+                       '(' . $table . '.sys_language_uid IN (2,-1)' .
+                               ' OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (' .
+                               'SELECT ' . $table . '.l10n_parent FROM ' . $table .
+                               ' WHERE ' . $table . '.l10n_parent>0 AND ' .
+                               $table . '.sys_language_uid>0 AND ' .
+                               $table . '.deleted=0)))')
+               );
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function orderStatementGenerationWorks() {
+               $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
+               $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
+               $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
+               $mockDataMapper->expects($this->once())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
+               $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', 'Tx_MyExt_ClassName')->will($this->returnValue('converted_fieldname'));
+               $sql = array();
+               $orderings = array('fooProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING);
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
+               $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
+               $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
+               $expectedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC'));
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException
+        */
+       public function orderStatementGenerationThrowsExceptionOnUnsupportedOrder() {
+               $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
+               $mockSource->expects($this->never())->method('getNodeTypeName');
+               $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
+               $mockDataMapper->expects($this->never())->method('convertClassNameToTableName');
+               $mockDataMapper->expects($this->never())->method('convertPropertyNameToColumnName');
+               $sql = array();
+               $orderings = array('fooProperty' => 'unsupported_order');
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
+               $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
+               $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
+       }
+
+       /**
+        * @test
+        */
+       public function orderStatementGenerationWorksWithMultipleOrderings() {
+               $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
+               $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
+               $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
+               $mockDataMapper->expects($this->any())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
+               $mockDataMapper->expects($this->any())->method('convertPropertyNameToColumnName')->will($this->returnValue('converted_fieldname'));
+               $sql = array();
+               $orderings = array(
+                       'fooProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
+                       'barProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
+               );
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
+               $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
+               $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
+               $expectedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC', 'tx_myext_tablename.converted_fieldname DESC'));
+               $this->assertSame($expectedSql, $sql);
+       }
+
+       public function providerForVisibilityConstraintStatement() {
+               return array(
+                       'in be: include all' => array('BE', TRUE, array(), TRUE, NULL),
+                       'in be: ignore enable fields but do not include deleted' => array('BE', TRUE, array(), FALSE, array('tx_foo_table.deleted_column=0')),
+                       'in be: respect enable fields but include deleted' => array('BE', FALSE, array(), TRUE, array('tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789)')),
+                       'in be: respect enable fields and do not include deleted' => array('BE', FALSE, array(), FALSE, array('tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column=0')),
+                       'in fe: include all' => array('FE', TRUE, array(), TRUE, NULL),
+                       'in fe: ignore enable fields but do not include deleted' => array('FE', TRUE, array(), FALSE, array('tx_foo_table.deleted_column=0')),
+                       'in fe: ignore only starttime and do not include deleted' => array('FE', TRUE, array('starttime'), FALSE, array('tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0')),
+                       'in fe: respect enable fields and do not include deleted' => array('FE', FALSE, array(), FALSE, array('tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0 AND tx_foo_table.starttime_column<=123456789'))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider providerForVisibilityConstraintStatement
+        */
+       public function visibilityConstraintStatementIsGeneratedAccordingToTheQuerySettings($mode, $ignoreEnableFields, $enableFieldsToBeIgnored, $deletedValue, $expectedSql) {
+               $tableName = 'tx_foo_table';
+               $GLOBALS['TCA'][$tableName]['ctrl'] = array(
+                       'enablecolumns' => array(
+                               'disabled' => 'disabled_column',
+                               'starttime' => 'starttime_column'
+                       ),
+                       'delete' => 'deleted_column'
+               );
+               $GLOBALS['TSFE'] = new \stdClass();
+               $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
+               $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
+               $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
+               $mockQuerySettings->expects($this->once())->method('getIgnoreEnableFields')->will($this->returnValue($ignoreEnableFields));
+               $mockQuerySettings->expects($this->once())->method('getEnableFieldsToBeIgnored')->will($this->returnValue($enableFieldsToBeIgnored));
+               $mockQuerySettings->expects($this->once())->method('getIncludeDeleted')->will($this->returnValue($deletedValue));
+               $sql = array();
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
+               $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue($mode));
+               $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
+               $this->assertSame($expectedSql, $sql['additionalWhereClause']);
+               unset($GLOBALS['TCA'][$tableName]);
+       }
+
+       public function providerForRespectEnableFields() {
+               return array(
+                       'in be: respectEnableFields=false' => array('BE', FALSE, NULL),
+                       'in be: respectEnableFields=true' => array('BE', TRUE, array('tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column=0')),
+                       'in be: respectEnableFields=false' => array('FE', FALSE, NULL),
+                       'in be: respectEnableFields=true' => array('FE', TRUE, array('tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0 AND tx_foo_table.starttime_column<=123456789'))
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider providerForRespectEnableFields
+        */
+       public function respectEnableFieldsSettingGeneratesCorrectStatement($mode, $respectEnableFields, $expectedSql) {
+               $tableName = 'tx_foo_table';
+               $GLOBALS['TCA'][$tableName]['ctrl'] = array(
+                       'enablecolumns' => array(
+                               'disabled' => 'disabled_column',
+                               'starttime' => 'starttime_column'
+                       ),
+                       'delete' => 'deleted_column'
+               );
+               $GLOBALS['TSFE'] = new \stdClass();
+               $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
+               $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
+               $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('dummy'), array(), '', FALSE);
+               $mockQuerySettings->setRespectEnableFields($respectEnableFields);
+               $sql = array();
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
+               $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue($mode));
+               $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
+               $this->assertSame($expectedSql, $sql['additionalWhereClause']);
+               unset($GLOBALS['TCA'][$tableName]);
+       }
+
+       /**
+        * @test
+        * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InconsistentQuerySettingsException
+        */
+       public function visibilityConstraintStatementGenerationThrowsExceptionIfTheQuerySettingsAreInconsistent() {
+               $tableName = 'tx_foo_table';
+               $GLOBALS['TCA'][$tableName]['ctrl'] = array(
+                       'enablecolumns' => array(
+                               'disabled' => 'disabled_column'
+                       ),
+                       'delete' => 'deleted_column'
+               );
+               $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
+               $mockQuerySettings->expects($this->once())->method('getIgnoreEnableFields')->will($this->returnValue(FALSE));
+               $mockQuerySettings->expects($this->once())->method('getEnableFieldsToBeIgnored')->will($this->returnValue(array()));
+               $mockQuerySettings->expects($this->once())->method('getIncludeDeleted')->will($this->returnValue(TRUE));
+               $sql = array();
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
+               $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue('FE'));
+               $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
+               unset($GLOBALS['TCA'][$tableName]);
+       }
+
+       /**
+        * @test
+        */
+       public function uidOfAlreadyPersistedValueObjectIsDeterminedCorrectly() {
+               $mockValueObject = $this->getMockForAbstractClass('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject', array('_getProperties'), '', FALSE);
+               $mockValueObject->expects($this->any())->method('_getProperties')->will($this->returnValue(array('propertyName' => 'propertyValue')));
+               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('isPersistableProperty', 'getColumnName'), array(), '', FALSE);
+               $mockColumnMap->expects($this->any())->method('getColumnName')->will($this->returnValue('column_name'));
+               $tableName = 'tx_foo_table';
+               $mockDataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('isPersistableProperty', 'getColumnMap', 'getTableName'), array(), '', FALSE);
+               $mockDataMap->expects($this->any())->method('isPersistableProperty')->will($this->returnValue(TRUE));
+               $mockDataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($mockColumnMap));
+               $mockDataMap->expects($this->any())->method('getTableName')->will($this->returnValue($tableName));
+               $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap'), array(), '', FALSE);
+               $mockDataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($mockDataMap));
+               $expectedStatement = 'SELECT * FROM tx_foo_table WHERE column_name=?';
+               $expectedParameters = array('plainPropertyValue');
+               $expectedUid = 52;
+               $mockDataBaseHandle = $this->getMock('t3lib_db', array('sql_query', 'sql_fetch_assoc'), array(), '', FALSE);
+               $mockDataBaseHandle->expects($this->once())->method('sql_query')->will($this->returnValue('resource'));
+               $mockDataBaseHandle->expects($this->any())->method('sql_fetch_assoc')->with('resource')->will($this->returnValue(array('uid' => $expectedUid)));
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getPlainValue', 'checkSqlErrors', 'replacePlaceholders', 'addVisibilityConstraintStatement'), array(), '', FALSE);
+               $mockTypo3DbBackend->expects($this->once())->method('getPlainValue')->will($this->returnValue('plainPropertyValue'));
+               $mockTypo3DbBackend->expects($this->once())->method('addVisibilityConstraintStatement')->with($this->isInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface'), $tableName, $this->isType('array'));
+               $mockTypo3DbBackend->expects($this->once())->method('replacePlaceholders')->with($expectedStatement, $expectedParameters)->will($this->returnValue('plainPropertyValue'));
+               $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
+               $mockTypo3DbBackend->_set('databaseHandle', $mockDataBaseHandle);
+               $result = $mockTypo3DbBackend->_callRef('getUidOfAlreadyPersistedValueObject', $mockValueObject);
+               $this->assertSame($expectedUid, $result);
+       }
+
+       /**
+        * @test
+        */
+       public function doLanguageAndWorkspaceOverlayChangesUidIfInPreview() {
+               $comparisonRow = array(
+                       'uid' => '43',
+                       'pid' => '42',
+                       '_ORIG_pid' => '-1',
+                       '_ORIG_uid' => '43'
+               );
+               $row = array(
+                       'uid' => '42',
+                       'pid' => '42'
+               );
+               $workspaceVersion = array(
+                       'uid' => '43',
+                       'pid' => '-1'
+               );
+               $languageUid = 2;
+               $workspaceUid = 2;
+               $sourceMock = new \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Selector('tx_foo', 'Tx_Foo');
+               /** @var $pageRepositoryMock \TYPO3\CMS\Frontend\Page\PageRepository|\PHPUnit_Framework_MockObject_MockObject */
+               $pageRepositoryMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('movePlhOL', 'getWorkspaceVersionOfRecord'));
+               $pageRepositoryMock->versioningPreview = TRUE;
+               $pageRepositoryMock->expects($this->once())->method('getWorkspaceVersionOfRecord')->with($workspaceUid, 'tx_foo', '42')->will($this->returnValue($workspaceVersion));
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockTypo3DbBackend->_set('pageRepository', $pageRepositoryMock);
+               $this->assertSame(array($comparisonRow), $mockTypo3DbBackend->_call('doLanguageAndWorkspaceOverlay', $sourceMock, array($row), $languageUid, $workspaceUid));
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Mapper/DataMapFactoryTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Mapper/DataMapFactoryTest.php
deleted file mode 100644 (file)
index 7aa21b7..0000000
+++ /dev/null
@@ -1,455 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Mapper;
-
-/***************************************************************
- *  Copyright notice
- *
- *  This class is a backport of the corresponding class of TYPO3 Flow.
- *  All credits go to the TYPO3 Flow team.
- *  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!
- ***************************************************************/
-class DataMapFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
-
-       /**
-        * @return array
-        */
-       public function oneToOneRelation() {
-               return array(
-                       array('Tx_Myext_Domain_Model_Foo'),
-                       array('TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser')
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider oneToOneRelation
-        */
-       public function setRelationsDetectsOneToOneRelation($className) {
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $columnConfiguration = array(
-                       'type' => 'select',
-                       'foreign_table' => 'tx_myextension_bar',
-                       'foreign_field' => 'parentid'
-               );
-               $propertyMetaData = array(
-                       'type' => $className,
-                       'elementType' => NULL
-               );
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->once())->method('setOneToOneRelation');
-               $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
-               $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
-               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
-       }
-
-       /**
-        * @test
-        */
-       public function setRelationsDetectsOneToOneRelationWithIntermediateTable() {
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $columnConfiguration = array(
-                       'type' => 'select',
-                       'foreign_table' => 'tx_myextension_bar',
-                       'MM' => 'tx_myextension_mm'
-               );
-               $propertyMetaData = array(
-                       'type' => 'Tx_Myext_Domain_Model_Foo',
-                       'elementType' => NULL
-               );
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
-               $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
-               $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
-               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
-       }
-
-       /**
-        * @test
-        */
-       public function setRelationsDetectsOneToManyRelation() {
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $columnConfiguration = array(
-                       'type' => 'select',
-                       'foreign_table' => 'tx_myextension_bar',
-                       'foreign_field' => 'parentid',
-                       'foreign_table_field' => 'parenttable'
-               );
-               $propertyMetaData = array(
-                       'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
-                       'elementType' => 'Tx_Myext_Domain_Model_Foo'
-               );
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
-               $mockDataMapFactory->expects($this->once())->method('setOneToManyRelation');
-               $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
-               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
-       }
-
-       /**
-        * @test
-        */
-       public function setRelationsDetectsManyToManyRelationOfTypeSelect() {
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $columnConfiguration = array(
-                       'type' => 'select',
-                       'foreign_table' => 'tx_myextension_bar',
-                       'MM' => 'tx_myextension_mm'
-               );
-               $propertyMetaData = array(
-                       'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
-                       'elementType' => 'Tx_Myext_Domain_Model_Foo'
-               );
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
-               $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
-               $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
-               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
-       }
-
-       /**
-        * @test
-        */
-       public function setRelationsDetectsManyToManyRelationOfTypeInlineWithIntermediateTable() {
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $columnConfiguration = array(
-                       'type' => 'inline',
-                       'foreign_table' => 'tx_myextension_righttable',
-                       'MM' => 'tx_myextension_mm'
-               );
-               $propertyMetaData = array(
-                       'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
-                       'elementType' => 'Tx_Myext_Domain_Model_Foo'
-               );
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
-               $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
-               $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
-               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
-       }
-
-       /**
-        * @test
-        */
-       public function setRelationsDetectsManyToManyRelationOfTypeInlineWithForeignSelector() {
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $columnConfiguration = array(
-                       'type' => 'inline',
-                       'foreign_table' => 'tx_myextension_mm',
-                       'foreign_field' => 'uid_local',
-                       'foreign_selector' => 'uid_foreign'
-               );
-               $propertyMetaData = array(
-                       'type' => 'TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage',
-                       'elementType' => 'Tx_Myext_Domain_Model_Foo'
-               );
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
-               $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
-               $mockDataMapFactory->expects($this->once())->method('setManyToManyRelation');
-               $mockDataMapFactory->_callRef('setRelations', $mockColumnMap, $columnConfiguration, $propertyMetaData);
-       }
-
-       /**
-        * @test
-        */
-       public function columnMapIsInitializedWithManyToManyRelationOfTypeSelect() {
-               $leftColumnsDefinition = array(
-                       'rights' => array(
-                               'type' => 'select',
-                               'foreign_table' => 'tx_myextension_righttable',
-                               'foreign_table_where' => 'WHERE 1=1',
-                               'MM' => 'tx_myextension_mm',
-                               'MM_table_where' => 'WHERE 2=2'
-                       )
-               );
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
-               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
-               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
-               $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with($this->equalTo('WHERE 1=1'));
-               $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
-               $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
-               $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
-               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
-               $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'), array(), '', FALSE);
-               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
-       }
-
-       /**
-        * @test
-        */
-       public function columnMapIsInitializedWithOppositeManyToManyRelationOfTypeSelect() {
-               $rightColumnsDefinition = array(
-                       'lefts' => array(
-                               'type' => 'select',
-                               'foreign_table' => 'tx_myextension_lefttable',
-                               'MM' => 'tx_myextension_mm',
-                               'MM_opposite_field' => 'rights'
-                       )
-               );
-               $leftColumnsDefinition['rights']['MM_opposite_field'] = 'opposite_field';
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
-               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
-               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_lefttable'));
-               $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement')->with(NULL);
-               $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting_foreign'));
-               $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_foreign'));
-               $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
-               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
-               $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'), array(), '', FALSE);
-               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $rightColumnsDefinition['lefts']);
-       }
-
-       /**
-        * @test
-        */
-       public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndIntermediateTable() {
-               $leftColumnsDefinition = array(
-                       'rights' => array(
-                               'type' => 'inline',
-                               'foreign_table' => 'tx_myextension_righttable',
-                               'MM' => 'tx_myextension_mm',
-                               'foreign_sortby' => 'sorting'
-                       )
-               );
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
-               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
-               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
-               $mockColumnMap->expects($this->once())->method('setChildTableWhereStatement');
-               $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
-               $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
-               $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
-               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
-               $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getColumnsDefinition'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->never())->method('getColumnsDefinition');
-               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
-       }
-
-       /**
-        * @test
-        */
-       public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndForeignSelector() {
-               $leftColumnsDefinition = array(
-                       'rights' => array(
-                               'type' => 'inline',
-                               'foreign_table' => 'tx_myextension_mm',
-                               'foreign_field' => 'uid_local',
-                               'foreign_selector' => 'uid_foreign',
-                               'foreign_sortby' => 'sorting'
-                       )
-               );
-               $relationTableColumnsDefiniton = array(
-                       'uid_local' => array(
-                               'config' => array('foreign_table' => 'tx_myextension_localtable')
-                       ),
-                       'uid_foreign' => array(
-                               'config' => array('foreign_table' => 'tx_myextension_righttable')
-                       )
-               );
-               $rightColumnsDefinition = array(
-                       'lefts' => array(
-                               'type' => 'inline',
-                               'foreign_table' => 'tx_myextension_mm',
-                               'foreign_field' => 'uid_foreign',
-                               'foreign_selector' => 'uid_local',
-                               'foreign_sortby' => 'sorting_foreign'
-                       )
-               );
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
-               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
-               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
-               $mockColumnMap->expects($this->never())->method('setChildTableWhereStatement');
-               $mockColumnMap->expects($this->once())->method('setChildSortByFieldName')->with($this->equalTo('sorting'));
-               $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
-               $mockColumnMap->expects($this->never())->method('setParentTableFieldName');
-               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
-               $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getColumnsDefinition'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefiniton));
-               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
-       }
-
-       /**
-        * @test
-        */
-       public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndForeignSelectorWithForeignTableField() {
-               $leftColumnsDefinition = array(
-                       'rights' => array(
-                               'type' => 'inline',
-                               'foreign_table' => 'tx_myextension_mm',
-                               'foreign_field' => 'uid_local',
-                               'foreign_selector' => 'uid_foreign',
-                               'foreign_table_field' => 'tx_myextension_localtable',
-                               'foreign_sortby' => 'sorting'
-                       )
-               );
-               $relationTableColumnsDefinition = array(
-                       'uid_local' => array(
-                               'config' => array('foreign_table' => 'tx_myextension_localtable')
-                       ),
-                       'uid_foreign' => array(
-                               'config' => array('foreign_table' => 'tx_myextension_righttable')
-                       )
-               );
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
-               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
-               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_righttable'));
-               $mockColumnMap->expects($this->never())->method('setChildTableWhereStatement');
-               $mockColumnMap->expects($this->once())->method('setChildSortbyFieldName')->with($this->equalTo('sorting'));
-               $mockColumnMap->expects($this->once())->method('setParentKeyFieldName')->with($this->equalTo('uid_local'));
-               $mockColumnMap->expects($this->once())->method('setParentTableFieldName')->with($this->equalTo('tx_myextension_localtable'));
-               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
-               $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
-
-               $mockDataMapFactory = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory'), array('getColumnsDefinition'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefinition));
-               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
-       }
-
-       /**
-        * @test
-        */
-       public function columnMapIsInitializedWithManyToManyRelationWithoutPidColumn() {
-               $leftColumnsDefinition = array(
-                       'rights' => array(
-                               'type' => 'select',
-                               'foreign_table' => 'tx_myextension_righttable',
-                               'foreign_table_where' => 'WHERE 1=1',
-                               'MM' => 'tx_myextension_mm'
-                       )
-               );
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
-               $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
-               $mockColumnMap->expects($this->never())->method('setrelationTablePageIdColumnName');
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(NULL));
-               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
-       }
-
-       /**
-        * @test
-        */
-       public function columnMapIsInitializedWithManyToManyRelationWithPidColumn() {
-               $leftColumnsDefinition = array(
-                       'rights' => array(
-                               'type' => 'select',
-                               'foreign_table' => 'tx_myextension_righttable',
-                               'foreign_table_where' => 'WHERE 1=1',
-                               'MM' => 'tx_myextension_mm'
-                       )
-               );
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
-               $mockColumnMap->expects($this->once())->method('setRelationTableName')->with($this->equalTo('tx_myextension_mm'));
-               $mockColumnMap->expects($this->once())->method('getRelationTableName')->will($this->returnValue('tx_myextension_mm'));
-               $mockColumnMap->expects($this->once())->method('setrelationTablePageIdColumnName')->with($this->equalTo('pid'));
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
-               $mockDataMapFactory->expects($this->once())->method('getControlSection')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue(array('ctrl' => array('foo' => 'bar'))));
-               $mockDataMapFactory->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
-       }
-
-       /**
-        * @test
-        * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidClassException
-        */
-       public function buildDataMapThrowsExceptionIfClassNameIsNotKnown() {
-               $mockDataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('getControlSection'), array(), '', FALSE);
-               $cacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', array('get'), array(), '', FALSE);
-               $cacheMock->expects($this->any())->method('get')->will($this->returnValue(FALSE));
-               $mockDataMapFactory->_set('dataMapCache', $cacheMock);
-               $mockDataMapFactory->buildDataMap('UnknownObject');
-       }
-
-       /**
-        * @test
-        */
-       public function buildDataMapFetchesSubclassesRecursively() {
-               $configuration = array(
-                       'persistence' => array(
-                               'classes' => array(
-                                       'TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser' => array(
-                                               'subclasses' => array(
-                                                       'Tx_SampleExt_Domain_Model_LevelOne1' => 'Tx_SampleExt_Domain_Model_LevelOne1',
-                                                       'Tx_SampleExt_Domain_Model_LevelOne2' => 'Tx_SampleExt_Domain_Model_LevelOne2'
-                                               )
-                                       ),
-                                       'Tx_SampleExt_Domain_Model_LevelOne1' => array(
-                                               'subclasses' => array(
-                                                       'Tx_SampleExt_Domain_Model_LevelTwo1' => 'Tx_SampleExt_Domain_Model_LevelTwo1',
-                                                       'Tx_SampleExt_Domain_Model_LevelTwo2' => 'Tx_SampleExt_Domain_Model_LevelTwo2'
-                                               )
-                                       ),
-                                       'Tx_SampleExt_Domain_Model_LevelOne2' => array(
-                                               'subclasses' => array()
-                                       )
-                               )
-                       )
-               );
-               $expectedSubclasses = array(
-                       'Tx_SampleExt_Domain_Model_LevelOne1',
-                       'Tx_SampleExt_Domain_Model_LevelTwo1',
-                       'Tx_SampleExt_Domain_Model_LevelTwo2',
-                       'Tx_SampleExt_Domain_Model_LevelOne2'
-               );
-               /** @var $configurationManager \TYPO3\CMS\Extbase\Configuration\ConfigurationManager|\PHPUnit_Framework_MockObject_MockObject */
-               $configurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
-               $configurationManager->expects($this->once())->method('getConfiguration')->with('Framework')->will($this->returnValue($configuration));
-               $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('test'));
-               $dataMapFactory->injectReflectionService(new \TYPO3\CMS\Extbase\Reflection\ReflectionService());
-               $dataMapFactory->injectObjectManager(new \TYPO3\CMS\Extbase\Object\ObjectManager());
-               $dataMapFactory->injectConfigurationManager($configurationManager);
-               $cacheMock = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', array(), array(), '', FALSE);
-               $cacheMock->expects($this->any())->method('get')->will($this->returnValue(FALSE));
-               $dataMapFactory->_set('dataMapCache', $cacheMock);
-               $dataMap = $dataMapFactory->buildDataMap('TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUser');
-               $this->assertSame($dataMap->getSubclasses(), $expectedSubclasses);
-       }
-
-       /**
-        * @return array
-        */
-       public function classNameTableNameMappings() {
-               return array(
-                       'Core classes' => array('TYPO3\\CMS\\Belog\\Domain\\Model\\LogEntry', 'tx_belog_domain_model_logentry'),
-                       'Extension classes' => array('ExtbaseTeam\\BlogExample\\Domain\\Model\\Blog', 'tx_blogexample_domain_model_blog'),
-                       'Extension classes without namespace' => array('Tx_News_Domain_Model_News', 'tx_news_domain_model_news'),
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider classNameTableNameMappings
-        */
-       public function resolveTableNameReturnsExpectedTablenames($className, $expected) {
-               $dataMapFactory = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory', array('dummy'));
-               $this->assertSame($expected, $dataMapFactory->_call('resolveTableName', $className));
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Mapper/DataMapperTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Mapper/DataMapperTest.php
deleted file mode 100644 (file)
index c068eee..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Mapper;
-
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012 Tymoteusz Motylewski <t.motylewski@gmail.com>
- *  All rights reserved
- *
- *  Part of This class is a backport of the corresponding class of TYPO3 Flow.
- *  Credits go to the v5 team.
- *
- *  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 \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
- */
-class DataMapperTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
-
-       /**
-        * @test
-        */
-       public function mapMapsArrayToObjectByCallingmapToObject() {
-               $rows = array(array('uid' => '1234'));
-               $object = new \stdClass();
-               $dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('mapSingleRow', 'getTargetType'));
-               $dataMapper->expects($this->any())->method('getTargetType')->will($this->returnArgument(1));
-               $dataMapFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapFactory');
-               $dataMapper->injectDataMapFactory($dataMapFactory);
-               $dataMapper->expects($this->once())->method('mapSingleRow')->with($rows[0])->will($this->returnValue($object));
-               $dataMapper->map(get_class($object), $rows);
-       }
-
-       /**
-        * @test
-        */
-       public function mapSingleRowReturnsObjectFromIdentityMapIfAvailable() {
-               $row = array('uid' => '1234');
-               $object = new \stdClass();
-               $identityMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\IdentityMap');
-               $identityMap->expects($this->once())->method('hasIdentifier')->with('1234')->will($this->returnValue(TRUE));
-               $identityMap->expects($this->once())->method('getObjectByIdentifier')->with('1234')->will($this->returnValue($object));
-               $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('dummy'));
-               $dataMapper->injectIdentityMap($identityMap);
-               $dataMapper->_call('mapSingleRow', get_class($object), $row);
-       }
-
-       /**
-        * @test
-        */
-       public function thawPropertiesSetsPropertyValues() {
-               $className = 'Class' . md5(uniqid(mt_rand(), TRUE));
-               eval('class ' . $className . ' extends TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity { public $firstProperty; public $secondProperty; public $thirdProperty; public $fourthProperty; }');
-               $object = new $className();
-               $row = array(
-                       'uid' => '1234',
-                       'firstProperty' => 'firstValue',
-                       'secondProperty' => 1234,
-                       'thirdProperty' => 1.234,
-                       'fourthProperty' => FALSE
-               );
-               $columnMaps = array(
-                       'uid' => new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('uid', 'uid'),
-                       'pid' => new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('pid', 'pid'),
-                       'firstProperty' => new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('firstProperty', 'firstProperty'),
-                       'secondProperty' => new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('secondProperty', 'secondProperty'),
-                       'thirdProperty' => new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('thirdProperty', 'thirdProperty')
-               );
-               $dataMap = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('dummy'), array($className, $className));
-               $dataMap->_set('columnMaps', $columnMaps);
-               $dataMaps = array(
-                       $className => $dataMap
-               );
-               $classSchema = new \TYPO3\CMS\Extbase\Reflection\ClassSchema($className);
-               $classSchema->injectTypeHandlingService(new \TYPO3\CMS\Extbase\Service\TypeHandlingService());
-               $classSchema->addProperty('pid', 'integer');
-               $classSchema->addProperty('uid', 'integer');
-               $classSchema->addProperty('firstProperty', 'string');
-               $classSchema->addProperty('secondProperty', 'integer');
-               $classSchema->addProperty('thirdProperty', 'float');
-               $classSchema->addProperty('fourthProperty', 'boolean');
-               $mockReflectionService = $this->getMock('TYPO3\\CMS\\Extbase\\Reflection\\ReflectionService', array('getClassSchema'));
-               $mockReflectionService->expects($this->any())->method('getClassSchema')->will($this->returnValue($classSchema));
-               $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('dummy'));
-               $dataMapper->_set('dataMaps', $dataMaps);
-               $dataMapper->injectReflectionService($mockReflectionService);
-               $dataMapper->_call('thawProperties', $object, $row);
-               $this->assertAttributeEquals('firstValue', 'firstProperty', $object);
-               $this->assertAttributeEquals(1234, 'secondProperty', $object);
-               $this->assertAttributeEquals(1.234, 'thirdProperty', $object);
-               $this->assertAttributeEquals(FALSE, 'fourthProperty', $object);
-       }
-
-       /**
-        * Test if fetchRelatedEager method returns NULL when $fieldValue = '' and relation type == RELATION_HAS_ONE
-        *
-        * @test
-        */
-       public function fetchRelatedEagerReturnsNullForEmptyRelationHasOne() {
-               $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('columnName', 'propertyName');
-               $columnMap->setTypeOfRelation(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_HAS_ONE);
-               $dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getColumnMap'), array(), '', FALSE);
-               $dataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($columnMap));
-               $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap'));
-               $dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($dataMap));
-               $result = $dataMapper->_call('fetchRelatedEager', $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity'), 'SomeName', '');
-               $this->assertEquals(NULL, $result);
-       }
-
-       /**
-        * Test if fetchRelatedEager method returns empty array when $fieldValue = '' and relation type != RELATION_HAS_ONE
-        *
-        * @test
-        */
-       public function fetchRelatedEagerReturnsEmptyArrayForEmptyRelationNotHasOne() {
-               $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('columnName', 'propertyName');
-               $columnMap->setTypeOfRelation(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::RELATION_BELONGS_TO_MANY);
-               $dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getColumnMap'), array(), '', FALSE);
-               $dataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($columnMap));
-               $dataMapper = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap'));
-               $dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($dataMap));
-               $result = $dataMapper->_call('fetchRelatedEager', $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity'), 'SomeName', '');
-               $this->assertEquals(array(), $result);
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/ObjectStorageTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/ObjectStorageTest.php
deleted file mode 100644 (file)
index 8b2d25f..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
-
-/***************************************************************
- *  Copyright notice
- *
- *  This class is a backport of the corresponding class of TYPO3 Flow.
- *  All credits go to the TYPO3 Flow team.
- *  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!
- ***************************************************************/
-class ObjectStorageTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
-
-       /**
-        * @test
-        */
-       public function anObjectCanBeAttached() {
-               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $objectStorage->attach($object1);
-               $objectStorage->attach($object2, 'foo');
-               $this->assertEquals($objectStorage[$object1], NULL);
-               $this->assertEquals($objectStorage[$object2], 'foo');
-       }
-
-       /**
-        * @test
-        */
-       public function anObjectCanBeDetached() {
-               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $objectStorage->attach($object1);
-               $objectStorage->attach($object2, 'foo');
-               $this->assertEquals(count($objectStorage), 2);
-               $objectStorage->detach($object1);
-               $this->assertEquals(count($objectStorage), 1);
-               $objectStorage->detach($object2);
-               $this->assertEquals(count($objectStorage), 0);
-       }
-
-       /**
-        * @test
-        */
-       public function offsetSetAssociatesDataToAnObjectInTheStorage() {
-               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $objectStorage->offsetSet($object1, 'foo');
-               $this->assertEquals(count($objectStorage), 1);
-               $objectStorage[$object2] = 'bar';
-               $this->assertEquals(count($objectStorage), 2);
-       }
-
-       /**
-        * @test
-        */
-       public function offsetUnsetRemovesAnObjectFromTheStorage() {
-               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $objectStorage->attach($object1);
-               $objectStorage->attach($object2, 'foo');
-               $this->assertEquals(count($objectStorage), 2);
-               $objectStorage->offsetUnset($object2);
-               $this->assertEquals(count($objectStorage), 1);
-               $objectStorage->offsetUnset($object1);
-               $this->assertEquals(count($objectStorage), 0);
-       }
-
-       /**
-        * @test
-        */
-       public function offsetGetReturnsTheDataAssociatedWithAnObject() {
-               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $objectStorage[$object1] = 'foo';
-               $objectStorage->attach($object2);
-               $this->assertEquals($objectStorage->offsetGet($object1), 'foo');
-               $this->assertEquals($objectStorage->offsetGet($object2), NULL);
-       }
-
-       /**
-        * @test
-        */
-       public function offsetExistsChecksWhetherAnObjectExistsInTheStorage() {
-               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $objectStorage->attach($object1);
-               $this->assertEquals($objectStorage->offsetExists($object1), TRUE);
-               $this->assertEquals($objectStorage->offsetExists($object2), FALSE);
-       }
-
-       /**
-        * @test
-        */
-       public function getInfoReturnsTheDataAssociatedWithTheCurrentIteratorEntry() {
-               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $object3 = new \StdClass();
-               $objectStorage->attach($object1, 42);
-               $objectStorage->attach($object2, 'foo');
-               $objectStorage->attach($object3, array('bar', 'baz'));
-               $objectStorage->rewind();
-               $this->assertEquals($objectStorage->getInfo(), 42);
-               $objectStorage->next();
-               $this->assertEquals($objectStorage->getInfo(), 'foo');
-               $objectStorage->next();
-               $this->assertEquals($objectStorage->getInfo(), array('bar', 'baz'));
-       }
-
-       /**
-        * @test
-        */
-       public function setInfoSetsTheDataAssociatedWithTheCurrentIteratorEntry() {
-               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $objectStorage->attach($object1);
-               $objectStorage->attach($object2, 'foo');
-               $objectStorage->rewind();
-               $objectStorage->setInfo(42);
-               $objectStorage->next();
-               $objectStorage->setInfo('bar');
-               $this->assertEquals($objectStorage[$object1], 42);
-               $this->assertEquals($objectStorage[$object2], 'bar');
-       }
-
-       /**
-        * @test
-        */
-       public function removeAllRemovesObjectsContainedInAnotherStorageFromTheCurrentStorage() {
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $objectStorageA = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $objectStorageA->attach($object1, 'foo');
-               $objectStorageB = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $objectStorageB->attach($object1, 'bar');
-               $objectStorageB->attach($object2, 'baz');
-               $this->assertEquals(count($objectStorageB), 2);
-               $objectStorageB->removeAll($objectStorageA);
-               $this->assertEquals(count($objectStorageB), 1);
-       }
-
-       /**
-        * @test
-        */
-       public function addAllAddsAllObjectsFromAnotherStorage() {
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $objectStorageA = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               // It might be better to mock this
-               $objectStorageA->attach($object1, 'foo');
-               $objectStorageB = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $objectStorageB->attach($object2, 'baz');
-               $this->assertEquals($objectStorageB->offsetExists($object1), FALSE);
-               $objectStorageB->addAll($objectStorageA);
-               $this->assertEquals($objectStorageB[$object1], 'foo');
-               $this->assertEquals($objectStorageB[$object2], 'baz');
-       }
-
-       /**
-        * @test
-        */
-       public function theStorageCanBeRetrievedAsArray() {
-               $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $object1 = new \StdClass();
-               $object2 = new \StdClass();
-               $objectStorage->attach($object1, 'foo');
-               $objectStorage->attach($object2, 'bar');
-               $this->assertEquals($objectStorage->toArray(), array($object1, $object2));
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/PersistenceManagerTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/PersistenceManagerTest.php
deleted file mode 100644 (file)
index 339265b..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
-
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012 Nico de Haen
- *  All rights reserved
- *
- *  This class is a backport of the corresponding class of FLOW3.
- *  All credits go to the v5 team.
- *
- *  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!
- ***************************************************************/
-/**
- * A PersistenceManager Test
- */
-class PersistenceManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
-
-       /**
-        * @test
-        *
-        * This test and the related Fixtures TxDomainModelTestEntity and
-        * TxDomainRepositoryTestEntityRepository can be removed if we do not need to support
-        * underscore class names instead of namespaced class names
-        */
-       public function persistAllAddsReconstitutedObjectFromSessionToBackendsAggregateRootObjects() {
-               $className = uniqid('BazFixture');
-               eval ('
-                       class Foo_Bar_Domain_Model_' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {}
-               ');
-               eval ('
-                       class Foo_Bar_Domain_Repository_' . $className . 'Repository {}
-               ');
-
-               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
-               $aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $fullClassName = 'Foo_Bar_Domain_Model_' . $className;
-               $entity1 = new $fullClassName();
-               $aggregateRootObjects->attach($entity1);
-               $persistenceSession->registerReconstitutedObject($entity1);
-               $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend'), array('commit', 'setAggregateRootObjects', 'setDeletedObjects'), array(), '', FALSE);
-               $persistenceManager = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'), array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->expects($this->once())
-                       ->method('setAggregateRootObjects')
-                       ->with($this->equalTo($aggregateRootObjects));
-               $persistenceManager->_set('backend', $mockTypo3DbBackend);
-               $persistenceManager->injectSession($persistenceSession);
-               $persistenceManager->persistAll();
-       }
-
-       /**
-        * @test
-        */
-       public function persistAllAddsNamespacedReconstitutedObjectFromSessionToBackendsAggregateRootObjects() {
-               $className = uniqid('BazFixture');
-               eval ('
-                       namespace Foo\\Bar\\Domain\\Model;
-                       class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity {}
-               ');
-               eval ('
-                       namespace Foo\\Bar\\Domain\\Repository;
-                       class  ' . $className . 'Repository {}
-               ');
-
-               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
-               $aggregateRootObjects = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
-               $classNameWithNamespace = 'Foo\\Bar\\Domain\\Model\\' . $className;
-               $entity1 = new $classNameWithNamespace();
-               $aggregateRootObjects->attach($entity1);
-               $persistenceSession->registerReconstitutedObject($entity1);
-               $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend'), array('commit', 'setAggregateRootObjects', 'setDeletedObjects'), array(), '', FALSE);
-               $persistenceManager = $this->getMock($this->buildAccessibleProxy('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'), array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->expects($this->once())
-                       ->method('setAggregateRootObjects')
-                       ->with($this->equalTo($aggregateRootObjects));
-               $persistenceManager->_set('backend', $mockTypo3DbBackend);
-               $persistenceManager->injectSession($persistenceSession);
-               $persistenceManager->persistAll();
-       }
-
-       /**
-        * @test
-        */
-       public function persistAllAddsRemovedObjectsFromRepositoriesToBackendsDeletedObjects() {
-               $this->markTestIncomplete();
-       }
-
-       /**
-        * @test
-        */
-       public function persistAllAddsAddedObjectsFromRepositoriesToBackendsAggregateRootObjects() {
-               $this->markTestIncomplete();
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/QueryFactoryTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/QueryFactoryTest.php
deleted file mode 100644 (file)
index 3e13d34..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
-
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2012 Alexander Schnitzler <alex.schnitzler@typovision.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 \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
- *
- * @author Alexander Schnitzler <alex.schnitzler@typovision.de>
- * @author Oliver Klee <typo3-coding@oliverklee.de>
- */
-class QueryFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
-
-       /**
-        * @var string
-        */
-       protected $className = 'Vendor\\Ext\\Domain\\Model\\ClubMate';
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
-        */
-       protected $queryFactory = NULL;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
-        */
-       protected $objectManager = NULL;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject
-        */
-       protected $dataMapper = NULL;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject
-        */
-       protected $dataMap;
-
-       protected function setUp() {
-               $this->dataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('getIsStatic', 'getRootLevel'), array('Vendor\\Ext\\Domain\\Model\\ClubMate', 'tx_ext_domain_model_clubmate'));
-
-               $this->queryFactory = new \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory();
-               $this->queryFactory->injectConfigurationManager(
-                       $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface')
-               );
-
-               $this->objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
-               $this->queryFactory->injectObjectManager($this->objectManager);
-
-               $this->dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap', 'convertClassNameToTableName'));
-               $this->dataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($this->dataMap));
-               $this->queryFactory->injectDataMapper($this->dataMapper);
-       }
-
-       protected function tearDown() {
-               unset($this->objectManager, $this->dataMapper, $this->queryFactory);
-       }
-
-       public function getStaticAndRootLevelAndExpectedResult() {
-               return array(
-                       'Respect storage page is set when entity is neither marked as static nor as rootLevel.' => array(FALSE, FALSE, TRUE),
-                       'Respect storage page is set when entity is marked as static and rootLevel.' => array(TRUE, TRUE, FALSE),
-                       'Respect storage page is set when entity is marked as static but not rootLevel.' => array(TRUE, FALSE, FALSE),
-                       'Respect storage page is set when entity is not marked as static but as rootLevel.' => array(FALSE, TRUE, FALSE),
-               );
-       }
-
-       /**
-        * @param boolean $static
-        * @param boolean $rootLevel
-        * @param boolean $expectedResult
-        *
-        * @dataProvider getStaticAndRootLevelAndExpectedResult
-        * @test
-        */
-       public function createDoesNotRespectStoragePageIfStaticOrRootLevelIsTrue($static, $rootLevel, $expectedResult) {
-               $this->dataMap->expects($this->any())->method('getIsStatic')->will($this->returnValue($static));
-               $this->dataMap->expects($this->any())->method('getRootLevel')->will($this->returnValue($rootLevel));
-
-               $query = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
-               $this->objectManager->expects($this->at(0))->method('create')
-                       ->with('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface')
-                       ->will($this->returnValue($query));
-
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $this->objectManager->expects($this->at(1))->method('create')
-                       ->with('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface')
-                       ->will($this->returnValue($querySettings));
-               $query->expects($this->once())->method('setQuerySettings')->with($querySettings);
-               $this->queryFactory->create($this->className);
-
-               $this->assertSame(
-                       $expectedResult,
-                       $querySettings->getRespectStoragePage()
-               );
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/QueryResultTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/QueryResultTest.php
deleted file mode 100644 (file)
index 50cca65..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
-
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2010 Bastian Waidelich <bastian@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!
- ***************************************************************/
-class QueryResultTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult
-        */
-       protected $queryResult;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\QueryInterface
-        */
-       protected $mockQuery;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
-        */
-       protected $mockPersistenceManager;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
-        */
-       protected $mockDataMapper;
-
-       /**
-        * @var array
-        */
-       protected $sampleResult = array();
-
-       /**
-        * Sets up this test case
-        *
-        * @return void
-        */
-       public function setUp() {
-               $this->mockPersistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
-               $this->mockPersistenceManager->expects($this->any())->method('getObjectDataByQuery')->will($this->returnValue(array('one', 'two')));
-               $this->mockPersistenceManager->expects($this->any())->method('getObjectCountByQuery')->will($this->returnValue(2));
-               $this->mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper');
-               $this->mockQuery = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
-               $this->queryResult = new \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult($this->mockQuery);
-               $this->queryResult->injectPersistenceManager($this->mockPersistenceManager);
-               $this->queryResult->injectDataMapper($this->mockDataMapper);
-               $this->sampleResult = array(array('foo' => 'Foo1', 'bar' => 'Bar1'), array('foo' => 'Foo2', 'bar' => 'Bar2'));
-               $this->mockDataMapper->expects($this->any())->method('map')->will($this->returnValue($this->sampleResult));
-       }
-
-       /**
-        * @test
-        */
-       public function getQueryReturnsQueryObject() {
-               $this->assertInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface', $this->queryResult->getQuery());
-       }
-
-       /**
-        * @test
-        */
-       public function getQueryReturnsAClone() {
-               $this->assertNotSame($this->mockQuery, $this->queryResult->getQuery());
-       }
-
-       /**
-        * @test
-        */
-       public function offsetExistsWorksAsExpected() {
-               $this->assertTrue($this->queryResult->offsetExists(0));
-               $this->assertFalse($this->queryResult->offsetExists(2));
-               $this->assertFalse($this->queryResult->offsetExists('foo'));
-       }
-
-       /**
-        * @test
-        */
-       public function offsetGetWorksAsExpected() {
-               $this->assertEquals(array('foo' => 'Foo1', 'bar' => 'Bar1'), $this->queryResult->offsetGet(0));
-               $this->assertNull($this->queryResult->offsetGet(2));
-               $this->assertNull($this->queryResult->offsetGet('foo'));
-       }
-
-       /**
-        * @test
-        */
-       public function offsetSetWorksAsExpected() {
-               $this->queryResult->offsetSet(0, array('foo' => 'FooOverridden', 'bar' => 'BarOverridden'));
-               $this->assertEquals(array('foo' => 'FooOverridden', 'bar' => 'BarOverridden'), $this->queryResult->offsetGet(0));
-       }
-
-       /**
-        * @test
-        */
-       public function offsetUnsetWorksAsExpected() {
-               $this->queryResult->offsetUnset(0);
-               $this->assertFalse($this->queryResult->offsetExists(0));
-       }
-
-       /**
-        * @test
-        */
-       public function countDoesNotInitializeProxy() {
-               $queryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult', array('initialize'), array($this->mockQuery));
-               $queryResult->injectPersistenceManager($this->mockPersistenceManager);
-               $queryResult->expects($this->never())->method('initialize');
-               $queryResult->count();
-       }
-
-       /**
-        * @test
-        */
-       public function countCallsGetObjectCountByQueryOnPersistenceManager() {
-               $queryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult', array('initialize'), array($this->mockQuery));
-               $queryResult->injectPersistenceManager($this->mockPersistenceManager);
-               $this->assertEquals(2, $queryResult->count());
-       }
-
-       /**
-        * @test
-        */
-       public function iteratorMethodsAreCorrectlyImplemented() {
-               $array1 = array('foo' => 'Foo1', 'bar' => 'Bar1');
-               $array2 = array('foo' => 'Foo2', 'bar' => 'Bar2');
-               $this->assertEquals($array1, $this->queryResult->current());
-               $this->assertTrue($this->queryResult->valid());
-               $this->queryResult->next();
-               $this->assertEquals($array2, $this->queryResult->current());
-               $this->assertTrue($this->queryResult->valid());
-               $this->assertEquals(1, $this->queryResult->key());
-               $this->queryResult->next();
-               $this->assertFalse($this->queryResult->current());
-               $this->assertFalse($this->queryResult->valid());
-               $this->assertNull($this->queryResult->key());
-               $this->queryResult->rewind();
-               $this->assertEquals(0, $this->queryResult->key());
-               $this->assertEquals($array1, $this->queryResult->current());
-       }
-
-       /**
-        * @test
-        */
-       public function initializeExecutesQueryWithArrayFetchMode() {
-               /** @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
-               $queryResult = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult', array('dummy'), array($this->mockQuery));
-               $queryResult->injectPersistenceManager($this->mockPersistenceManager);
-               $queryResult->injectDataMapper($this->mockDataMapper);
-               $this->mockPersistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->mockQuery)->will($this->returnValue(array('FAKERESULT')));
-               $queryResult->_call('initialize');
-       }
-
-       /**
-        * @test
-        */
-       public function usingCurrentOnTheQueryResultReturnsAWarning() {
-               $queryResult = new \TYPO3\CMS\Extbase\Persistence\Generic\QueryResult($this->mockQuery);
-               $expectedResult = 'You should never see this warning. If you do, you probably used PHP array functions like current() on the TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult. To retrieve the first result, you can use the getFirst() method.';
-               $actualResult = current($queryResult);
-               $this->assertEquals($expectedResult, $actualResult);
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/QueryTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/QueryTest.php
deleted file mode 100644 (file)
index 5fdb574..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
-
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2009 Christopher Hlubek <hlubek@networkteam.com>
- *  (c) 2010 Bastian Waidelich <bastian@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!
- ***************************************************************/
-class QueryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Query
-        */
-       protected $query;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
-        */
-       protected $querySettings;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
-        */
-       protected $objectManager;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
-        */
-       protected $persistenceManager;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
-        */
-       protected $backend;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper
-        */
-       protected $dataMapper;
-
-       /**
-        * Sets up this test case
-        *
-        * @return void
-        */
-       public function setUp() {
-               $this->objectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
-               $this->query = new \TYPO3\CMS\Extbase\Persistence\Generic\Query('someType');
-               $this->query->injectObjectManager($this->objectManager);
-               $this->querySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
-               $this->query->setQuerySettings($this->querySettings);
-               $this->persistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
-               $this->backend = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\BackendInterface');
-               $this->backend->expects($this->any())->method('getQomFactory')->will($this->returnValue(NULL));
-               $this->persistenceManager->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
-               $this->query->injectPersistenceManager($this->persistenceManager);
-               $this->dataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper');
-               $this->query->injectDataMapper($this->dataMapper);
-       }
-
-       /**
-        * @test
-        */
-       public function executeReturnsQueryResultInstanceAndInjectsItself() {
-               $queryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryResult', array(), array(), '', FALSE);
-               $this->objectManager->expects($this->once())->method('create')->with('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface', $this->query)->will($this->returnValue($queryResult));
-               $actualResult = $this->query->execute();
-               $this->assertSame($queryResult, $actualResult);
-       }
-
-       /**
-        * @test
-        */
-       public function executeReturnsRawObjectDataIfRawQueryResultSettingIsTrue() {
-               $this->querySettings->expects($this->once())->method('getReturnRawQueryResult')->will($this->returnValue(TRUE));
-               $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult'));
-               $expectedResult = 'rawQueryResult';
-               $actualResult = $this->query->execute();
-               $this->assertEquals($expectedResult, $actualResult);
-       }
-
-       /**
-        * @test
-        * @expectedException \InvalidArgumentException
-        */
-       public function setLimitAcceptsOnlyIntegers() {
-               $this->query->setLimit(1.5);
-       }
-
-       /**
-        * @test
-        * @expectedException \InvalidArgumentException
-        */
-       public function setLimitRejectsIntegersLessThanOne() {
-               $this->query->setLimit(0);
-       }
-
-       /**
-        * @test
-        * @expectedException \InvalidArgumentException
-        */
-       public function setOffsetAcceptsOnlyIntegers() {
-               $this->query->setOffset(1.5);
-       }
-
-       /**
-        * @test
-        * @expectedException \InvalidArgumentException
-        */
-       public function setOffsetRejectsIntegersLessThanZero() {
-               $this->query->setOffset(-1);
-       }
-
-       /**
-        * @return array
-        */
-       public function equalsForCaseSensitiveFalseLowercasesOperandProvider() {
-               return array(
-                       'Polish alphabet' => array('name', 'ĄĆĘŁŃÓŚŹŻABCDEFGHIJKLMNOPRSTUWYZQXVąćęłńóśźżabcdefghijklmnoprstuwyzqxv', 'ąćęłńóśźżabcdefghijklmnoprstuwyzqxvąćęłńóśźżabcdefghijklmnoprstuwyzqxv'),
-                       'German alphabet' => array('name', 'ßÜÖÄüöä', 'ßüöäüöä'),
-                       'Greek alphabet' => array('name', 'Τάχιστη αλώπηξ βαφής ψημένη γη', 'τάχιστη αλώπηξ βαφής ψημένη γη'),
-                       'Russian alphabet' => array('name', 'АВСТРАЛИЯавстралия', 'австралияавстралия')
-               );
-       }
-
-       /**
-        * Checks if equals condition makes utf-8 argument lowercase correctly
-        *
-        * @test
-        * @dataProvider equalsForCaseSensitiveFalseLowercasesOperandProvider
-        * @param string $propertyName The name of the property to compare against
-        * @param mixed $operand The value to compare with
-        * @param string $expectedOperand
-        */
-       public function equalsForCaseSensitiveFalseLowercasesOperand($propertyName, $operand, $expectedOperand) {
-               /** @var $qomFactory \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory */
-               $qomFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\QueryObjectModelFactory', array('comparison'));
-               $qomFactory->injectObjectManager(\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'));
-               $qomFactory->expects($this->once())->method('comparison')->with($this->anything(), $this->anything(), $expectedOperand);
-               $this->query->injectQomFactory($qomFactory);
-               $this->query->equals($propertyName, $operand, FALSE);
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/RepositoryTest.php
deleted file mode 100644 (file)
index 1e4b95e..0000000
+++ /dev/null
@@ -1,418 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
-
-/***************************************************************
- *  Copyright notice
- *
- *  (c) 2010 Bastian Waidelich <bastian@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!
- ***************************************************************/
-class RepositoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Repository|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
-        */
-       protected $repository;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
-        */
-       protected $mockObjectManager;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\IdentityMap
-        */
-       protected $mockIdentityMap;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QueryFactory
-        */
-       protected $mockQueryFactory;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
-        */
-       protected $mockBackend;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\Session
-        */
-       protected $mockSession;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
-        */
-       protected $mockPersistenceManager;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\QueryInterface
-        */
-       protected $mockQuery;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
-        */
-       protected $querySettings;
-
-       /**
-        * @var \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface
-        */
-       protected $mockQuerySettings;
-
-       public function setUp() {
-               $this->mockIdentityMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\IdentityMap');
-               $this->mockQueryFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory');
-               $this->mockQuery = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryInterface');
-               $this->mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
-               $this->mockQuery->expects($this->any())->method('getQuerySettings')->will($this->returnValue($this->mockQuerySettings));
-               $this->mockQueryFactory->expects($this->any())->method('create')->will($this->returnValue($this->mockQuery));
-               $this->mockBackend = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\BackendInterface');
-               $this->mockSession = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Session');
-               $this->mockPersistenceManager = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface');
-               $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
-               $this->repository = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Repository', array('dummy'), array($this->mockObjectManager));
-               $this->repository->injectIdentityMap($this->mockIdentityMap);
-               $this->repository->injectQueryFactory($this->mockQueryFactory);
-               $this->repository->injectPersistenceManager($this->mockPersistenceManager);
-               $this->repository->injectBackend($this->mockBackend);
-               $this->repository->injectSession($this->mockSession);
-       }
-
-       /**
-        * @test
-        */
-       public function abstractRepositoryImplementsRepositoryInterface() {
-               $this->assertTrue($this->repository instanceof \TYPO3\CMS\Extbase\Persistence\RepositoryInterface);
-       }
-
-       /**
-        * @test
-        */
-       public function addActuallyAddsAnObjectToTheInternalObjectsArray() {
-               $someObject = new \stdClass();
-               $this->repository->_set('objectType', get_class($someObject));
-               $this->repository->add($someObject);
-               $this->assertTrue($this->repository->getAddedObjects()->contains($someObject));
-       }
-
-       /**
-        * @test
-        */
-       public function removeActuallyRemovesAnObjectFromTheInternalObjectsArray() {
-               $object1 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
-               $object2 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
-               $object3 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
-               $this->repository->_set('objectType', get_class($object1));
-               $this->repository->add($object1);
-               $this->repository->add($object2);
-               $this->repository->add($object3);
-               $this->repository->remove($object2);
-               $this->assertTrue($this->repository->getAddedObjects()->contains($object1));
-               $this->assertFalse($this->repository->getAddedObjects()->contains($object2));
-               $this->assertTrue($this->repository->getAddedObjects()->contains($object3));
-       }
-
-       /**
-        * @test
-        */
-       public function removeRemovesTheRightObjectEvenIfItHasBeenModifiedSinceItsAddition() {
-               $object1 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
-               $object2 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
-               $object3 = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
-               $this->repository->_set('objectType', get_class($object1));
-               $this->repository->add($object1);
-               $this->repository->add($object2);
-               $this->repository->add($object3);
-               $object2->setPid(1);
-               $object3->setPid(2);
-               $this->repository->remove($object2);
-               $this->assertTrue($this->repository->getAddedObjects()->contains($object1));
-               $this->assertFalse($this->repository->getAddedObjects()->contains($object2));
-               $this->assertTrue($this->repository->getAddedObjects()->contains($object3));
-       }
-
-       /**
-        * Make sure we remember the objects that are not currently add()ed
-        * but might be in persistent storage.
-        *
-        * @test
-        */
-       public function removeRetainsObjectForObjectsNotInCurrentSession() {
-               $object = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractDomainObject');
-               // if the object is not currently add()ed, it is not new
-               $object->expects($this->once())->method('_isNew')->will($this->returnValue(FALSE));
-               $this->repository->_set('objectType', get_class($object));
-               $this->repository->remove($object);
-               $this->assertTrue($this->repository->getRemovedObjects()->contains($object));
-       }
-
-       /**
-        * dataProvider for createQueryCallsQueryFactoryWithExpectedType
-        *
-        * @return array
-        */
-       public function modelAndRepositoryClassNames() {
-               return array(
-                       array('Tx_BlogExample_Domain_Repository_BlogRepository', 'Tx_BlogExample_Domain_Model_Blog'),
-                       array('_Domain_Repository_Content_PageRepository', '_Domain_Model_Content_Page'),
-                       array('Tx_RepositoryExample_Domain_Repository_SomeModelRepository', 'Tx_RepositoryExample_Domain_Model_SomeModel'),
-                       array('Tx_RepositoryExample_Domain_Repository_RepositoryRepository', 'Tx_RepositoryExample_Domain_Model_Repository'),
-                       array('Tx_Repository_Domain_Repository_RepositoryRepository', 'Tx_Repository_Domain_Model_Repository')
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider modelAndRepositoryClassNames
-        * @param string $repositoryClassName
-        * @param string $modelClassName
-        */
-       public function constructSetsObjectTypeFromClassName($repositoryClassName, $modelClassName) {
-               $mockClassName = 'MockRepository' . uniqid();
-               eval('class ' . $mockClassName . ' extends TYPO3\\CMS\\Extbase\\Persistence\\Repository {
-                       protected function getRepositoryClassName() {
-                               return \'' . $repositoryClassName . '\';
-                       }
-                       public function _getObjectType() {
-                               return $this->objectType;
-                       }
-               }');
-               $this->repository = new $mockClassName($this->mockObjectManager);
-               $this->assertEquals($modelClassName, $this->repository->_getObjectType());
-       }
-
-       /**
-        * @test
-        */
-       public function createQueryCallsQueryFactoryWithExpectedClassName() {
-               $this->mockQueryFactory->expects($this->once())->method('create')->with('ExpectedType');
-               $this->repository->_set('objectType', 'ExpectedType');
-               $this->repository->createQuery();
-       }
-
-       /**
-        * @test
-        */
-       public function createQueryReturnsQueryWithUnmodifiedDefaultQuerySettings() {
-               $mockQueryFactory = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QueryFactory');
-               $mockQuery = new \TYPO3\CMS\Extbase\Persistence\Generic\Query('foo');
-               $mockDefaultQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface');
-               $this->repository->injectQueryFactory($mockQueryFactory);
-               $this->repository->setDefaultQuerySettings($mockDefaultQuerySettings);
-               $mockQueryFactory->expects($this->once())->method('create')->will($this->returnValue($mockQuery));
-               $this->repository->createQuery();
-               $instanceQuerySettings = $mockQuery->getQuerySettings();
-               $this->assertEquals($mockDefaultQuerySettings, $instanceQuerySettings);
-               $this->assertNotSame($mockDefaultQuerySettings, $instanceQuerySettings);
-       }
-
-       /**
-        * @test
-        */
-       public function findAllCreatesQueryAndReturnsResultOfExecuteCall() {
-               $expectedResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface');
-               $this->mockQuery->expects($this->once())->method('execute')->with()->will($this->returnValue($expectedResult));
-               $this->assertSame($expectedResult, $this->repository->findAll());
-       }
-
-       /**
-        * @test
-        */
-       public function findByUidReturnsResultOfGetObjectByIdentifierCall() {
-               $fakeUid = '123';
-               $object = new \stdClass();
-               $this->repository->_set('objectType', 'someObjectType');
-               $this->mockIdentityMap->expects($this->once())->method('hasIdentifier')->with($fakeUid, 'someObjectType')->will($this->returnValue(TRUE));
-               $this->mockIdentityMap->expects($this->once())->method('getObjectByIdentifier')->with($fakeUid)->will($this->returnValue($object));
-               $expectedResult = $object;
-               $actualResult = $this->repository->findByUid($fakeUid);
-               $this->assertSame($expectedResult, $actualResult);
-       }
-
-       /**
-        * Replacing a reconstituted object (which has a uuid) by a new object
-        * will ask the persistence backend to replace them accordingly in the
-        * identity map.
-        *
-        * @test
-        * @return void
-        */
-       public function replaceReplacesReconstitutedEntityByNewObject() {
-               $existingObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-               $newObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-               $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('123'));
-               $this->mockBackend->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);
-               $this->repository->_set('objectType', get_class($newObject));
-               $this->repository->replace($existingObject, $newObject);
-       }
-
-       /**
-        * Replacing a reconstituted object which during this session has been
-        * marked for removal (by calling the repository's remove method)
-        * additionally registers the "newObject" for removal and removes the
-        * "existingObject" from the list of removed objects.
-        *
-        * @test
-        * @return void
-        */
-       public function replaceRemovesReconstitutedObjectWhichIsMarkedToBeRemoved() {
-               $existingObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-               $newObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-               $removedObjects = new \SplObjectStorage();
-               $removedObjects->attach($existingObject);
-               $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue('123'));
-               $this->mockBackend->expects($this->once())->method('replaceObject')->with($existingObject, $newObject);
-               $this->repository->_set('objectType', get_class($newObject));
-               $this->repository->_set('removedObjects', $removedObjects);
-               $this->repository->replace($existingObject, $newObject);
-               $this->assertFalse($removedObjects->contains($existingObject));
-               $this->assertTrue($removedObjects->contains($newObject));
-       }
-
-       /**
-        * Replacing a new object which has not yet been persisted by another
-        * new object will just replace them in the repository's list of added
-        * objects.
-        *
-        * @test
-        * @return void
-        */
-       public function replaceAddsNewObjectToAddedObjects() {
-               $existingObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-               $newObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-               $addedObjects = new \SplObjectStorage();
-               $addedObjects->attach($existingObject);
-               $this->mockPersistenceManager->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue(NULL));
-               $this->mockBackend->expects($this->never())->method('replaceObject');
-               $this->repository->_set('objectType', get_class($newObject));
-               $this->repository->_set('addedObjects', $addedObjects);
-               $this->repository->replace($existingObject, $newObject);
-               $this->assertFalse($addedObjects->contains($existingObject));
-               $this->assertTrue($addedObjects->contains($newObject));
-       }
-
-       /**
-        * @test
-        * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
-        */
-       public function replaceChecksObjectType() {
-               $this->repository->_set('objectType', 'ExpectedObjectType');
-               $this->repository->replace(new \stdClass(), new \stdClass());
-       }
-
-       /**
-        * @test
-        */
-       public function updateReplacesAnObjectWithTheSameUuidByTheGivenObject() {
-               $existingObject = new \stdClass();
-               $modifiedObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-               $modifiedObject->expects($this->once())->method('getUid')->will($this->returnValue('123'));
-               /** @var \TYPO3\CMS\Extbase\Persistence\Repository|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
-               $repository = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Repository', array('findByUid', 'replace'), array($this->mockObjectManager));
-               $repository->expects($this->once())->method('findByUid')->with('123')->will($this->returnValue($existingObject));
-               $repository->expects($this->once())->method('replace')->with($existingObject, $modifiedObject);
-               $repository->_set('objectType', get_class($modifiedObject));
-               $repository->update($modifiedObject);
-       }
-
-       /**
-        * @test
-        * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
-        */
-       public function updateRejectsUnknownObjects() {
-               $someObject = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface');
-               $someObject->expects($this->once())->method('getUid')->will($this->returnValue(NULL));
-               $this->repository->_set('objectType', get_class($someObject));
-               $this->repository->update($someObject);
-       }
-
-       /**
-        * @test
-        * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
-        */
-       public function updateRejectsObjectsOfWrongType() {
-               $this->repository->_set('objectType', 'Foo');
-               $this->repository->update(new \stdClass());
-       }
-
-       /**
-        * @test
-        */
-       public function magicCallMethodAcceptsFindBySomethingCallsAndExecutesAQueryWithThatCriteria() {
-               $mockQueryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface');
-               $this->mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
-               $this->mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($this->mockQuery));
-               $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
-               $this->assertSame($mockQueryResult, $this->repository->findByFoo('bar'));
-       }
-
-       /**
-        * @test
-        */
-       public function magicCallMethodAcceptsFindOneBySomethingCallsAndExecutesAQueryWithThatCriteria() {
-               $object = new \stdClass();
-               $mockQueryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface');
-               $mockQueryResult->expects($this->once())->method('getFirst')->will($this->returnValue($object));
-               $this->mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
-               $this->mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($this->mockQuery));
-               $this->mockQuery->expects($this->once())->method('setLimit')->with(1)->will($this->returnValue($this->mockQuery));
-               $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
-               $this->assertSame($object, $this->repository->findOneByFoo('bar'));
-       }
-
-       /**
-        * @test
-        */
-       public function magicCallMethodAcceptsCountBySomethingCallsAndExecutesAQueryWithThatCriteria() {
-               $mockQueryResult = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface');
-               $mockQueryResult->expects($this->once())->method('count')->will($this->returnValue(2));
-               $this->mockQuery->expects($this->once())->method('equals')->with('foo', 'bar')->will($this->returnValue('matchCriteria'));
-               $this->mockQuery->expects($this->once())->method('matching')->with('matchCriteria')->will($this->returnValue($this->mockQuery));
-               $this->mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
-               $this->assertSame(2, $this->repository->countByFoo('bar'));
-       }
-
-       /**
-        * @test
-        * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException
-        */
-       public function magicCallMethodTriggersAnErrorIfUnknownMethodsAreCalled() {
-               $this->repository->__call('foo', array());
-       }
-
-       /**
-        * @test
-        * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
-        */
-       public function addChecksObjectType() {
-               $this->repository->_set('objectType', 'ExpectedObjectType');
-               $this->repository->add(new \stdClass());
-       }
-
-       /**
-        * @test
-        * @expectedException \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
-        */
-       public function removeChecksObjectType() {
-               $this->repository->_set('objectType', 'ExpectedObjectType');
-               $this->repository->remove(new \stdClass());
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/SessionTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/SessionTest.php
deleted file mode 100644 (file)
index fcafa67..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence;
-
-/***************************************************************
- *  Copyright notice
- *
- *  This class is a backport of the corresponding class of TYPO3 Flow.
- *  All credits go to the TYPO3 Flow team.
- *  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!
- ***************************************************************/
-class SessionTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
-
-       /**
-        * @test
-        */
-       public function newSessionIsEmpty() {
-               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
-               $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
-               $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
-       }
-
-       /**
-        * @test
-        */
-       public function objectCanBeRegisteredAsReconstituted() {
-               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
-               $entity = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity');
-               $persistenceSession->registerReconstitutedObject($entity);
-               $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
-               $this->assertTrue($reconstitutedObjects->contains($entity), 'The object was not registered as reconstituted.');
-       }
-
-       /**
-        * @test
-        */
-       public function objectCanBeUnregisteredAsReconstituted() {
-               $persistenceSession = new \TYPO3\CMS\Extbase\Persistence\Generic\Session();
-               $entity = $this->getMock('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractEntity');
-               $persistenceSession->registerReconstitutedObject($entity);
-               $persistenceSession->unregisterReconstitutedObject($entity);
-               $reconstitutedObjects = $persistenceSession->getReconstitutedObjects();
-               $this->assertEquals(0, count($reconstitutedObjects), 'The reconstituted objects storage was not empty.');
-       }
-}
-
-?>
\ No newline at end of file
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Storage/Typo3DbBackendTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Storage/Typo3DbBackendTest.php
deleted file mode 100644 (file)
index 1e80ca9..0000000
+++ /dev/null
@@ -1,488 +0,0 @@
-<?php
-namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Storage;
-
-/***************************************************************
- *  Copyright notice
- *
- *  This class is a backport of the corresponding class of TYPO3 Flow.
- *  All credits go to the TYPO3 Flow team.
- *  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!
- ***************************************************************/
-class Typo3DbBackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
-
-       /**
-        * This is the data provider for the statement generation with a basic comparison
-        *
-        * @return array An array of data
-        */
-       public function providerForBasicComparison() {
-               return array(
-                       'equal' => array(
-                               \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_EQUAL_TO,
-                               'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo = \'baz\''
-                       ),
-                       'less' => array(
-                               \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_LESS_THAN,
-                               'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo < \'baz\''
-                       ),
-                       'less or equal' => array(
-                               \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO,
-                               'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo <= \'baz\''
-                       ),
-                       'greater' => array(
-                               \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_GREATER_THAN,
-                               'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo > \'baz\''
-                       ),
-                       'greater or equal' => array(
-                               \TYPO3\CMS\Extbase\Persistence\QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO,
-                               'SELECT table_name_from_selector.* FROM table_name_from_selector WHERE table_name_from_property.foo >= \'baz\''
-                       )
-               );
-       }
-
-       /**
-        * @test
-        */
-       public function getStatementWorksWithMinimalisticQueryObjectModel() {
-               $this->markTestIncomplete();
-       }
-
-       /**
-        * @test
-        */
-       public function getStatementWorksWithBasicEqualsCondition() {
-               $this->markTestIncomplete();
-       }
-
-       /**
-        * @test
-        * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException
-        */
-       public function countRowsWithStatementConstraintResultsInAnException() {
-               $this->markTestIncomplete();
-       }
-
-       /**
-        * @test
-        */
-       public function joinStatementGenerationWorks() {
-               $this->markTestIncomplete();
-       }
-
-       /**
-        * @test
-        */
-       public function addSysLanguageStatementWorksForDefaultLanguage() {
-               $table = uniqid('tx_coretest_table');
-               $GLOBALS['TCA'][$table]['ctrl'] = array(
-                       'languageField' => 'sys_language_uid'
-               );
-               $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
-               $tsfe->sys_language_content = 0;
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->initializeObject();
-               $GLOBALS['TSFE'] = $tsfe;
-               $sql = array();
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function addSysLanguageStatementWorksForNonDefaultLanguageInFrontend() {
-               $table = uniqid('tx_coretest_table');
-               $GLOBALS['TCA'][$table]['ctrl'] = array(
-                       'languageField' => 'sys_language_uid'
-               );
-               $tsfe = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array(), '', FALSE);
-               $tsfe->sys_language_content = 1;
-               $GLOBALS['TSFE'] = $tsfe;
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->initializeObject();
-               $sql = array();
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (1,-1))'));
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function addSysLanguageStatementWorksForNonDefaultLanguageInBackend() {
-               $table = uniqid('tx_coretest_table');
-               $GLOBALS['TCA'][$table]['ctrl'] = array(
-                       'languageField' => 'sys_language_uid'
-               );
-               $_GET['L'] = 1;
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->initializeObject();
-               $sql = array();
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (1,-1))'));
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function addSysLanguageStatementWorksInBackendContextWithNoGlobalTypoScriptFrontendControllerAvailable() {
-               $table = uniqid('tx_coretest_table');
-               $GLOBALS['TCA'][$table]['ctrl'] = array(
-                       'languageField' => 'sys_language_uid'
-               );
-               $sql = array();
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function addSysLanguageStatementWorksForDefaultLanguageWithoutDeleteStatementReturned() {
-               $table = uniqid('tx_coretest_table');
-               $GLOBALS['TCA'][$table]['ctrl'] = array(
-                       'languageField' => 'sys_language_uid',
-                       'delete' => 'deleted'
-               );
-               $sql = array();
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->setSysLanguageUid(0);
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (0,-1))'));
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function addSysLanguageStatementWorksForForeignLanguageWithoutSubselection() {
-               $table = uniqid('tx_coretest_table');
-               $GLOBALS['TCA'][$table]['ctrl'] = array(
-                       'languageField' => 'sys_language_uid'
-               );
-               $sql = array();
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->setSysLanguageUid(2);
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (2,-1))'));
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionWithoutDeleteStatementReturned() {
-               $table = uniqid('tx_coretest_table');
-               $GLOBALS['TCA'][$table]['ctrl'] = array(
-                       'languageField' => 'sys_language_uid',
-                       'transOrigPointerField' => 'l10n_parent'
-               );
-               $sql = array();
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->setSysLanguageUid(2);
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array('(' . $table . '.sys_language_uid IN (2,-1) OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (SELECT ' . $table . '.l10n_parent FROM ' . $table . ' WHERE ' . $table . '.l10n_parent>0 AND ' . $table . '.sys_language_uid>0)))'));
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function addSysLanguageStatementWorksForForeignLanguageWithSubselectionTakesDeleteStatementIntoAccountIfNecessary() {
-               $table = uniqid('tx_coretest_table');
-               $GLOBALS['TCA'][$table]['ctrl'] = array(
-                       'languageField' => 'sys_language_uid',
-                       'transOrigPointerField' => 'l10n_parent',
-                       'delete' => 'deleted'
-               );
-               $sql = array();
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->setSysLanguageUid(2);
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array(
-                       '(' . $table . '.sys_language_uid IN (2,-1)' .
-                               ' OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (' .
-                               'SELECT ' . $table . '.l10n_parent FROM ' . $table .
-                               ' WHERE ' . $table . '.l10n_parent>0 AND ' .
-                               $table . '.sys_language_uid>0 AND ' .
-                               $table . '.deleted=0)))')
-               );
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function addSysLanguageStatementWorksInBackendContextWithSubselectionTakesDeleteStatementIntoAccountIfNecessary() {
-               $table = uniqid('tx_coretest_table');
-               $table = 'tt_content';
-               $GLOBALS['TCA'][$table]['ctrl'] = array(
-                       'languageField' => 'sys_language_uid',
-                       'transOrigPointerField' => 'l10n_parent',
-                       'delete' => 'deleted'
-               );
-               $sql = array();
-               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
-               $querySettings->setSysLanguageUid(2);
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_callRef('addSysLanguageStatement', $table, $sql, $querySettings);
-               $expectedSql = array('additionalWhereClause' => array(
-                       '(' . $table . '.sys_language_uid IN (2,-1)' .
-                               ' OR (' . $table . '.sys_language_uid=0 AND ' . $table . '.uid NOT IN (' .
-                               'SELECT ' . $table . '.l10n_parent FROM ' . $table .
-                               ' WHERE ' . $table . '.l10n_parent>0 AND ' .
-                               $table . '.sys_language_uid>0 AND ' .
-                               $table . '.deleted=0)))')
-               );
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function orderStatementGenerationWorks() {
-               $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
-               $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
-               $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
-               $mockDataMapper->expects($this->once())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
-               $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', 'Tx_MyExt_ClassName')->will($this->returnValue('converted_fieldname'));
-               $sql = array();
-               $orderings = array('fooProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING);
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
-               $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
-               $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
-               $expectedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC'));
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       /**
-        * @test
-        * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException
-        */
-       public function orderStatementGenerationThrowsExceptionOnUnsupportedOrder() {
-               $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
-               $mockSource->expects($this->never())->method('getNodeTypeName');
-               $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
-               $mockDataMapper->expects($this->never())->method('convertClassNameToTableName');
-               $mockDataMapper->expects($this->never())->method('convertPropertyNameToColumnName');
-               $sql = array();
-               $orderings = array('fooProperty' => 'unsupported_order');
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
-               $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
-               $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function orderStatementGenerationWorksWithMultipleOrderings() {
-               $mockSource = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Qom\\Selector', array('getNodeTypeName'), array(), '', FALSE);
-               $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
-               $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('convertPropertyNameToColumnName', 'convertClassNameToTableName'), array(), '', FALSE);
-               $mockDataMapper->expects($this->any())->method('convertClassNameToTableName')->with('Tx_MyExt_ClassName')->will($this->returnValue('tx_myext_tablename'));
-               $mockDataMapper->expects($this->any())->method('convertPropertyNameToColumnName')->will($this->returnValue('converted_fieldname'));
-               $sql = array();
-               $orderings = array(
-                       'fooProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
-                       'barProperty' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
-               );
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('parserOrderings'), array(), '', FALSE);
-               $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
-               $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
-               $expectedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC', 'tx_myext_tablename.converted_fieldname DESC'));
-               $this->assertSame($expectedSql, $sql);
-       }
-
-       public function providerForVisibilityConstraintStatement() {
-               return array(
-                       'in be: include all' => array('BE', TRUE, array(), TRUE, NULL),
-                       'in be: ignore enable fields but do not include deleted' => array('BE', TRUE, array(), FALSE, array('tx_foo_table.deleted_column=0')),
-                       'in be: respect enable fields but include deleted' => array('BE', FALSE, array(), TRUE, array('tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789)')),
-                       'in be: respect enable fields and do not include deleted' => array('BE', FALSE, array(), FALSE, array('tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column=0')),
-                       'in fe: include all' => array('FE', TRUE, array(), TRUE, NULL),
-                       'in fe: ignore enable fields but do not include deleted' => array('FE', TRUE, array(), FALSE, array('tx_foo_table.deleted_column=0')),
-                       'in fe: ignore only starttime and do not include deleted' => array('FE', TRUE, array('starttime'), FALSE, array('tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0')),
-                       'in fe: respect enable fields and do not include deleted' => array('FE', FALSE, array(), FALSE, array('tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0 AND tx_foo_table.starttime_column<=123456789'))
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider providerForVisibilityConstraintStatement
-        */
-       public function visibilityConstraintStatementIsGeneratedAccordingToTheQuerySettings($mode, $ignoreEnableFields, $enableFieldsToBeIgnored, $deletedValue, $expectedSql) {
-               $tableName = 'tx_foo_table';
-               $GLOBALS['TCA'][$tableName]['ctrl'] = array(
-                       'enablecolumns' => array(
-                               'disabled' => 'disabled_column',
-                               'starttime' => 'starttime_column'
-                       ),
-                       'delete' => 'deleted_column'
-               );
-               $GLOBALS['TSFE'] = new \stdClass();
-               $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
-               $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
-               $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
-               $mockQuerySettings->expects($this->once())->method('getIgnoreEnableFields')->will($this->returnValue($ignoreEnableFields));
-               $mockQuerySettings->expects($this->once())->method('getEnableFieldsToBeIgnored')->will($this->returnValue($enableFieldsToBeIgnored));
-               $mockQuerySettings->expects($this->once())->method('getIncludeDeleted')->will($this->returnValue($deletedValue));
-               $sql = array();
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
-               $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue($mode));
-               $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
-               $this->assertSame($expectedSql, $sql['additionalWhereClause']);
-               unset($GLOBALS['TCA'][$tableName]);
-       }
-
-       public function providerForRespectEnableFields() {
-               return array(
-                       'in be: respectEnableFields=false' => array('BE', FALSE, NULL),
-                       'in be: respectEnableFields=true' => array('BE', TRUE, array('tx_foo_table.disabled_column=0 AND (tx_foo_table.starttime_column<=123456789) AND tx_foo_table.deleted_column=0')),
-                       'in be: respectEnableFields=false' => array('FE', FALSE, NULL),
-                       'in be: respectEnableFields=true' => array('FE', TRUE, array('tx_foo_table.deleted_column=0 AND tx_foo_table.disabled_column=0 AND tx_foo_table.starttime_column<=123456789'))
-               );
-       }
-
-       /**
-        * @test
-        * @dataProvider providerForRespectEnableFields
-        */
-       public function respectEnableFieldsSettingGeneratesCorrectStatement($mode, $respectEnableFields, $expectedSql) {
-               $tableName = 'tx_foo_table';
-               $GLOBALS['TCA'][$tableName]['ctrl'] = array(
-                       'enablecolumns' => array(
-                               'disabled' => 'disabled_column',
-                               'starttime' => 'starttime_column'
-                       ),
-                       'delete' => 'deleted_column'
-               );
-               $GLOBALS['TSFE'] = new \stdClass();
-               $GLOBALS['TSFE']->sys_page = new \TYPO3\CMS\Frontend\Page\PageRepository();
-               $GLOBALS['SIM_ACCESS_TIME'] = 123456789;
-               $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('dummy'), array(), '', FALSE);
-               $mockQuerySettings->setRespectEnableFields($respectEnableFields);
-               $sql = array();
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
-               $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue($mode));
-               $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
-               $this->assertSame($expectedSql, $sql['additionalWhereClause']);
-               unset($GLOBALS['TCA'][$tableName]);
-       }
-
-       /**
-        * @test
-        * @expectedException \TYPO3\CMS\Extbase\Persistence\Generic\Exception\InconsistentQuerySettingsException
-        */
-       public function visibilityConstraintStatementGenerationThrowsExceptionIfTheQuerySettingsAreInconsistent() {
-               $tableName = 'tx_foo_table';
-               $GLOBALS['TCA'][$tableName]['ctrl'] = array(
-                       'enablecolumns' => array(
-                               'disabled' => 'disabled_column'
-                       ),
-                       'delete' => 'deleted_column'
-               );
-               $mockQuerySettings = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Typo3QuerySettings', array('getIgnoreEnableFields', 'getEnableFieldsToBeIgnored', 'getIncludeDeleted'), array(), '', FALSE);
-               $mockQuerySettings->expects($this->once())->method('getIgnoreEnableFields')->will($this->returnValue(FALSE));
-               $mockQuerySettings->expects($this->once())->method('getEnableFieldsToBeIgnored')->will($this->returnValue(array()));
-               $mockQuerySettings->expects($this->once())->method('getIncludeDeleted')->will($this->returnValue(TRUE));
-               $sql = array();
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getTypo3Mode'), array(), '', FALSE);
-               $mockTypo3DbBackend->expects($this->any())->method('getTypo3Mode')->will($this->returnValue('FE'));
-               $mockTypo3DbBackend->_callRef('addVisibilityConstraintStatement', $mockQuerySettings, $tableName, $sql);
-               unset($GLOBALS['TCA'][$tableName]);
-       }
-
-       /**
-        * @test
-        */
-       public function uidOfAlreadyPersistedValueObjectIsDeterminedCorrectly() {
-               $mockValueObject = $this->getMockForAbstractClass('TYPO3\\CMS\\Extbase\\DomainObject\\AbstractValueObject', array('_getProperties'), '', FALSE);
-               $mockValueObject->expects($this->any())->method('_getProperties')->will($this->returnValue(array('propertyName' => 'propertyValue')));
-               $mockColumnMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('isPersistableProperty', 'getColumnName'), array(), '', FALSE);
-               $mockColumnMap->expects($this->any())->method('getColumnName')->will($this->returnValue('column_name'));
-               $tableName = 'tx_foo_table';
-               $mockDataMap = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array('isPersistableProperty', 'getColumnMap', 'getTableName'), array(), '', FALSE);
-               $mockDataMap->expects($this->any())->method('isPersistableProperty')->will($this->returnValue(TRUE));
-               $mockDataMap->expects($this->any())->method('getColumnMap')->will($this->returnValue($mockColumnMap));
-               $mockDataMap->expects($this->any())->method('getTableName')->will($this->returnValue($tableName));
-               $mockDataMapper = $this->getMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper', array('getDataMap'), array(), '', FALSE);
-               $mockDataMapper->expects($this->any())->method('getDataMap')->will($this->returnValue($mockDataMap));
-               $expectedStatement = 'SELECT * FROM tx_foo_table WHERE column_name=?';
-               $expectedParameters = array('plainPropertyValue');
-               $expectedUid = 52;
-               $mockDataBaseHandle = $this->getMock('t3lib_db', array('sql_query', 'sql_fetch_assoc'), array(), '', FALSE);
-               $mockDataBaseHandle->expects($this->once())->method('sql_query')->will($this->returnValue('resource'));
-               $mockDataBaseHandle->expects($this->any())->method('sql_fetch_assoc')->with('resource')->will($this->returnValue(array('uid' => $expectedUid)));
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('getPlainValue', 'checkSqlErrors', 'replacePlaceholders', 'addVisibilityConstraintStatement'), array(), '', FALSE);
-               $mockTypo3DbBackend->expects($this->once())->method('getPlainValue')->will($this->returnValue('plainPropertyValue'));
-               $mockTypo3DbBackend->expects($this->once())->method('addVisibilityConstraintStatement')->with($this->isInstanceOf('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\QuerySettingsInterface'), $tableName, $this->isType('array'));
-               $mockTypo3DbBackend->expects($this->once())->method('replacePlaceholders')->with($expectedStatement, $expectedParameters)->will($this->returnValue('plainPropertyValue'));
-               $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
-               $mockTypo3DbBackend->_set('databaseHandle', $mockDataBaseHandle);
-               $result = $mockTypo3DbBackend->_callRef('getUidOfAlreadyPersistedValueObject', $mockValueObject);
-               $this->assertSame($expectedUid, $result);
-       }
-
-       /**
-        * @test
-        */
-       public function doLanguageAndWorkspaceOverlayChangesUidIfInPreview() {
-               $comparisonRow = array(
-                       'uid' => '43',
-                       'pid' => '42',
-                       '_ORIG_pid' => '-1',
-                       '_ORIG_uid' => '43'
-               );
-               $row = array(
-                       'uid' => '42',
-                       'pid' => '42'
-               );
-               $workspaceVersion = array(
-                       'uid' => '43',
-                       'pid' => '-1'
-               );
-               $languageUid = 2;
-               $workspaceUid = 2;
-               $sourceMock = new \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Selector('tx_foo', 'Tx_Foo');
-               /** @var $pageRepositoryMock \TYPO3\CMS\Frontend\Page\PageRepository|\PHPUnit_Framework_MockObject_MockObject */
-               $pageRepositoryMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository', array('movePlhOL', 'getWorkspaceVersionOfRecord'));
-               $pageRepositoryMock->versioningPreview = TRUE;
-               $pageRepositoryMock->expects($this->once())->method('getWorkspaceVersionOfRecord')->with($workspaceUid, 'tx_foo', '42')->will($this->returnValue($workspaceVersion));
-               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
-               $mockTypo3DbBackend->_set('pageRepository', $pageRepositoryMock);
-               $this->assertSame(array($comparisonRow), $mockTypo3DbBackend->_call('doLanguageAndWorkspaceOverlay', $sourceMock, array($row), $languageUid, $workspaceUid));
-       }
-}
-
-?>
\ No newline at end of file