[+BUGFIX] Extbase (Persistence): Fixed broken IRRE setups. The type of relation is...
authorJochen Rau <j.rau@web.de>
Tue, 30 Mar 2010 09:28:45 +0000 (09:28 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 30 Mar 2010 09:28:45 +0000 (09:28 +0000)
typo3/sysext/extbase/Classes/Persistence/Exception/UnsupportedRelation.php [new file with mode: 0644]
typo3/sysext/extbase/Classes/Persistence/Mapper/ColumnMap.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMap.php
typo3/sysext/extbase/Classes/Persistence/QOM/QueryObjectModelConstantsInterface.php
typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php
typo3/sysext/extbase/Tests/Persistence/Mapper/DataMap_testcase.php
typo3/sysext/extbase/Tests/Persistence/Storage/Typo3DbBackend_testcase.php

diff --git a/typo3/sysext/extbase/Classes/Persistence/Exception/UnsupportedRelation.php b/typo3/sysext/extbase/Classes/Persistence/Exception/UnsupportedRelation.php
new file mode 100644 (file)
index 0000000..0b1cd85
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
+*  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!
+***************************************************************/
+
+/**
+ * An "Unsupported Order" exception: The order you specified in the query is not supported by now.
+ *
+ * @package Extbase
+ * @subpackage Persistence\Exception
+ * @version $ID:$
+ */
+class Tx_Extbase_Persistence_Exception_UnsupportedRelation extends Tx_Extbase_Persistence_Exception {
+}
+
+?>
\ No newline at end of file
index f12d66f..20e039d 100644 (file)
@@ -38,6 +38,7 @@ class Tx_Extbase_Persistence_Mapper_ColumnMap {
        const RELATION_NONE = 'RELATION_NONE';
        const RELATION_HAS_ONE = 'RELATION_HAS_ONE';
        const RELATION_HAS_MANY = 'RELATION_HAS_MANY';
+       const RELATION_BELONGS_TO_MANY = 'RELATION_BELONGS_TO_MANY';
        const RELATION_HAS_AND_BELONGS_TO_MANY = 'RELATION_HAS_AND_BELONGS_TO_MANY';
 
        /**
@@ -170,6 +171,7 @@ class Tx_Extbase_Persistence_Mapper_ColumnMap {
                        case self::RELATION_NONE;
                        case self::RELATION_HAS_ONE;
                        case self::RELATION_HAS_MANY;
+                       case self::RELATION_BELONGS_TO_MANY;
                        case self::RELATION_HAS_AND_BELONGS_TO_MANY;
                                $this->typeOfRelation = $typeOfRelation;
                                break;
index a0223a8..c269be3 100644 (file)
@@ -213,14 +213,16 @@ class Tx_Extbase_Persistence_Mapper_DataMap {
         */
        protected function setRelations(Tx_Extbase_Persistence_Mapper_ColumnMap &$columnMap, $columnConfiguration) {
                if (isset($columnConfiguration) && $columnConfiguration['type'] !== 'passthrough') {
-                       if (isset($columnConfiguration['foreign_table']) && !isset($columnConfiguration['MM']) && !isset($columnConfiguration['foreign_selector'])) {
-                               if ($columnConfiguration['maxitems'] == 1) {
-                                       $this->setOneToOneRelation($columnMap, $columnConfiguration);
+                       if (isset($columnConfiguration['foreign_table'])) {
+                               if (isset($columnConfiguration['MM']) || isset($columnConfiguration['foreign_selector'])) {
+                                       $this->setManyToManyRelation($columnMap, $columnConfiguration);
                                } else {
-                                       $this->setOneToManyRelation($columnMap, $columnConfiguration);
+                                       if ($columnConfiguration['maxitems'] == 1) {
+                                               $this->setOneToOneRelation($columnMap, $columnConfiguration);
+                                       } else {
+                                               $this->setOneToManyRelation($columnMap, $columnConfiguration);
+                                       }
                                }
-                       } elseif (isset($columnConfiguration['MM']) || isset($columnConfiguration['foreign_selector'])) {
-                               $this->setManyToManyRelation($columnMap, $columnConfiguration);
                        } else {
                                $columnMap->setTypeOfRelation(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_NONE);
                        }
@@ -272,15 +274,7 @@ class Tx_Extbase_Persistence_Mapper_DataMap {
        protected function setManyToManyRelation(Tx_Extbase_Persistence_Mapper_ColumnMap &$columnMap, $columnConfiguration) {
                // TODO support multi table relationships
                $columnMap->setTypeOfRelation(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY);
-               if ($columnConfiguration['type'] === 'inline') {
-                       $columns = $this->getColumnsDefinition($columnConfiguration['foreign_table']);
-                       $childKeyFieldName = $this->determineChildKeyFieldName($columnConfiguration);
-                       $columnMap->setChildTableName($columns[$childKeyFieldName]['config']['foreign_table']);
-                       $columnMap->setRelationTableName($columnConfiguration['foreign_table']);
-                       $columnMap->setParentKeyFieldName($columnConfiguration['foreign_field']);
-                       $columnMap->setChildKeyFieldName($childKeyFieldName);
-                       $columnMap->setChildSortByFieldName($columnConfiguration['foreign_sortby']);
-               } else {
+               if (isset($columnConfiguration['MM'])) {
                        $columnMap->setChildTableName($columnConfiguration['foreign_table']);
                        $columnMap->setChildTableWhereStatement($columnConfiguration['foreign_table_where']);
                        $columnMap->setRelationTableName($columnConfiguration['MM']);
@@ -300,25 +294,21 @@ class Tx_Extbase_Persistence_Mapper_DataMap {
                                $columnMap->setChildKeyFieldName('uid_foreign');
                                $columnMap->setChildSortByFieldName('sorting');
                        }
-               }
-       }
-       
-       /**
-        * This method returns the foreign key field name in the relation table. For IRRE setups it will return
-        * the foreign_label; if not present the foreign_selector. Default is uid_foreign.
-        *
-        * @param string $columnConfiguration The column configuration of the parent table relation field
-        * @return string The foreign key field name of the relation table
-        */
-       public function determineChildKeyFieldName($columnConfiguration) {
-               if (isset($columnConfiguration['foreign_label'])) {
-                       $childKeyFieldName = $columnConfiguration['foreign_label'];
                } elseif (isset($columnConfiguration['foreign_selector'])) {
-                       $childKeyFieldName = $columnConfiguration['foreign_selector'];
+                       $columns = $this->getColumnsDefinition($columnConfiguration['foreign_table']);
+                       if (isset($columnConfiguration['foreign_selector'])) {
+                               $childKeyFieldName = $columnConfiguration['foreign_selector'];
+                       } else {
+                               $childKeyFieldName = 'uid_foreign';
+                       }
+                       $columnMap->setChildTableName($columns[$childKeyFieldName]['config']['foreign_table']);
+                       $columnMap->setRelationTableName($columnConfiguration['foreign_table']);
+                       $columnMap->setParentKeyFieldName($columnConfiguration['foreign_field']);
+                       $columnMap->setChildKeyFieldName($childKeyFieldName);
+                       $columnMap->setChildSortByFieldName($columnConfiguration['foreign_sortby']);
                } else {
-                       $childKeyFieldName = 'uid_foreign';
+                       throw new Tx_Extbase_Persistence_Exception_UnsupportedRelation('The given information to build a many-to-many-relation was not sufficient. Check your TCA definitions. mm-relations with IRRE must have at least a defined "MM" or "foreign_selector".', 1268817963);
                }
-               return $childKeyFieldName;
        }
        
        /**
index 7eda8bf..f51b253 100644 (file)
@@ -31,6 +31,7 @@
  * @package Extbase
  * @subpackage Persistence\QOM
  * @version $Id$
+ * @deprecated since Extbase 1.1; use Tx_Extbase_Persistence_QueryInterface::* instead
  */
 interface Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface {
 
index 9b631b0..9abf2b2 100644 (file)
@@ -167,6 +167,7 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                if (!$isRelation) {
                        $this->clearPageCache($tableName, $uid, $isRelation);
                }
+               // debug($statement, -2);
                $returnValue = $this->databaseHandle->sql_query($statement);
                $this->checkSqlErrors();
                return $returnValue;
@@ -474,10 +475,6 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                                $sql['where'][] = '1<>1';
                        } else {
                                $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters, NULL, $operand2);
-                               $items = array();
-                               foreach ($operand2 as $value) {
-                                       $items[] = $this->getPlainValue($value);
-                               }
                                $parameters[] = $items;
                        }
                } elseif ($operator === Tx_Extbase_Persistence_QueryInterface::OPERATOR_CONTAINS) {
@@ -785,6 +782,18 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
         */
        protected function parseOrderings(array $orderings, Tx_Extbase_Persistence_QOM_SourceInterface $source, array &$sql) {
                foreach ($orderings as $propertyName => $order) {
+                       switch ($order) {
+                               case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING: // Deprecated since Extbase 1.1
+                               case Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING:
+                                       $order = 'ASC';
+                                       break;
+                               case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING: // Deprecated since Extbase 1.1
+                               case Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING:
+                                       $order = 'DESC';
+                                       break;
+                               default:
+                                       throw new Tx_Extbase_Persistence_Exception_UnsupportedOrder('Unsupported order encountered.', 1242816074);
+                       }
                        if ($source instanceof Tx_Extbase_Persistence_QOM_SelectorInterface) {
                                $className = $source->getNodeTypeName();
                                $tableName = $this->dataMapper->convertClassNameToTableName($className);
index 517ff03..eb718a1 100644 (file)
@@ -278,13 +278,30 @@ class Tx_Extbase_Persistence_Mapper_DataMap_testcase extends Tx_Extbase_BaseTest
        /**
         * @test
         */
-       public function setRelationsDetectsManyToManyRelationOfTypeInline() {
+       public function setRelationsDetectsManyToManyRelationOfTypeInlineWithIntermediateTable() {
+               $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
+           $columnConfiguration = array(
+                       'type' => 'inline',
+                       'foreign_table' => 'tx_myextension_righttable',
+                       'MM' => 'tx_myextension_mm'
+                       );
+               $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
+               $mockDataMap->expects($this->never())->method('setOneToOneRelation');
+               $mockDataMap->expects($this->never())->method('setOneToManyRelation');
+               $mockDataMap->expects($this->once())->method('setManyToManyRelation');
+               $mockDataMap->_callRef('setRelations', $mockColumnMap, $columnConfiguration);
+       }
+       
+       /**
+        * @test
+        */
+       public function setRelationsDetectsManyToManyRelationOfTypeInlineWithForeignSelector() {
                $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
            $columnConfiguration = array(
                        'type' => 'inline',
                        'foreign_table' => 'tx_myextension_mm',
                        'foreign_field' => 'uid_local',
-                       'foreign_label' => 'uid_foreign'
+                       'foreign_selector' => 'uid_foreign'
                        );
                $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'), array(), '', FALSE);
                $mockDataMap->expects($this->never())->method('setOneToOneRelation');
@@ -350,63 +367,40 @@ class Tx_Extbase_Persistence_Mapper_DataMap_testcase extends Tx_Extbase_BaseTest
        /**
         * @test
         */
-       public function uid_foreignIsReturnedAsDefaultForChildKeyFieldName() {
+       public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndIntermediateTable() {
            $leftColumnsDefinition = array(
                        'rights' => array(
                                'type' => 'inline',
-                               'foreign_table' => 'tx_myextension_mm',
-                               'foreign_field' => 'uid_local',
-                               )
-                       );
-               $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('dummy'), array(), '', FALSE);
-               $result = $mockDataMap->_callRef('determineChildKeyFieldName', $leftColumnsDefinition['rights']);
-               $this->assertEquals('uid_foreign', $result);
-       }
-       
-       /**
-        * @test
-        */
-       public function theChildKeyFieldNameIsReturnedForForeignLabel() {
-           $leftColumnsDefinition = array(
-                       'rights' => array(
-                               'type' => 'inline',
-                               'foreign_table' => 'tx_myextension_mm',
-                               'foreign_field' => 'uid_local',
-                               'foreign_label' => 'the_child_key_field_name',
-                               )
-                       );
-               $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('dummy'), array(), '', FALSE);
-               $result = $mockDataMap->_callRef('determineChildKeyFieldName', $leftColumnsDefinition['rights']);
-               $this->assertEquals('the_child_key_field_name', $result);
-       }
-       
-       /**
-        * @test
-        */
-       public function theChildKeyFieldNameIsReturnedForForeignSelector() {
-           $leftColumnsDefinition = array(
-                       'rights' => array(
-                               'type' => 'inline',
-                               'foreign_table' => 'tx_myextension_mm',
-                               'foreign_field' => 'uid_local',
-                               'foreign_selector' => 'the_child_key_field_name',
+                               'foreign_table' => 'tx_myextension_righttable',
+                               'MM' => 'tx_myextension_mm',
+                               'foreign_sortby' => 'sorting'
                                )
                        );
-               $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('dummy'), array(), '', FALSE);
-               $result = $mockDataMap->_callRef('determineChildKeyFieldName', $leftColumnsDefinition['rights']);
-               $this->assertEquals('the_child_key_field_name', $result);
+               $mockColumnMap = $this->getMock('Tx_Extbase_Persistence_Mapper_ColumnMap', array(), array(), '', FALSE);
+               $mockColumnMap->expects($this->once())->method('setTypeOfRelation')->with($this->equalTo(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY));
+               $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');
+               
+               $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('getColumnsDefinition'), array(), '', FALSE);
+               $mockDataMap->expects($this->never())->method('getColumnsDefinition');
+               $mockDataMap->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
        }
-       
+
        /**
         * @test
         */
-       public function columnMapIsInitializedWithManyToManyRelationOfTypeInline() {
+       public function columnMapIsInitializedWithManyToManyRelationOfTypeInlineAndForeignSelector() {
            $leftColumnsDefinition = array(
                        'rights' => array(
                                'type' => 'inline',
                                'foreign_table' => 'tx_myextension_mm',
                                'foreign_field' => 'uid_local',
-                               'foreign_label' => 'uid_foreign',
+                               'foreign_selector' => 'uid_foreign',
                                'foreign_sortby' => 'sorting'
                                )
                        );
@@ -423,7 +417,7 @@ class Tx_Extbase_Persistence_Mapper_DataMap_testcase extends Tx_Extbase_BaseTest
                                'type' => 'inline',
                                'foreign_table' => 'tx_myextension_mm',
                                'foreign_field' => 'uid_foreign',
-                               'foreign_label' => 'uid_local',
+                               'foreign_selector' => 'uid_local',
                                'foreign_sortby' => 'sorting_foreign'
                                )
                        );
@@ -437,7 +431,7 @@ class Tx_Extbase_Persistence_Mapper_DataMap_testcase extends Tx_Extbase_BaseTest
                $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
                $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
                
-               $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('getColumnsDefinition', 'determineChildClassName'), array(), '', FALSE);
+               $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('getColumnsDefinition'), array(), '', FALSE);
                $mockDataMap->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefiniton));
                $mockDataMap->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
        }
index 9b003ce..beef4a0 100644 (file)
@@ -91,28 +91,20 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend_testcase extends Tx_Extbase_
         * @test
         */
        public function orderStatementGenerationWorks() {
-               $mockPropertyValue = $this->getMock('Tx_Extbase_Persistence_QOM_PropertyValue', array('getPropertyName', 'getSelectorname'), array(), '', FALSE);
-               $mockPropertyValue->expects($this->once())->method('getPropertyName')->will($this->returnValue('fooProperty'));
-               $mockPropertyValue->expects($this->once())->method('getSelectorName')->will($this->returnValue('tx_myext_tablenamefromproperty'));
-               
-               $mockOrdering1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_QOM_Ordering'), array('getOrder', 'getOperand'), array(), '', FALSE);
-               $mockOrdering1->expects($this->once())->method('getOrder')->will($this->returnValue(Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING));
-               $mockOrdering1->expects($this->once())->method('getOperand')->will($this->returnValue($mockPropertyValue));
-               $orderings = array($mockOrdering1);
-
-               $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getSelectorName', 'getNodeTypeName'), array(), '', FALSE);
-               $mockSource->expects($this->any())->method('getSelectorName')->will($this->returnValue('tx_myext_tablename'));
+               $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
                $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
 
-               $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName'), array(), '', FALSE);
+               $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_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' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING);
                $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);               
                $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
                $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
                        
-               $expecedSql = array('orderings' => array('tx_myext_tablenamefromproperty.converted_fieldname ASC'));
+               $expecedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC'));
                $this->assertSame($expecedSql, $sql);
        }
 
@@ -121,22 +113,15 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend_testcase extends Tx_Extbase_
         * @expectedException Tx_Extbase_Persistence_Exception_UnsupportedOrder
         */
        public function orderStatementGenerationThrowsExceptionOnUnsupportedOrder() {
-               $mockPropertyValue = $this->getMock('Tx_Extbase_Persistence_QOM_PropertyValue', array('getPropertyName', 'getSelectorname'), array(), '', FALSE);
-               $mockPropertyValue->expects($this->never())->method('getPropertyName');
-               $mockPropertyValue->expects($this->never())->method('getSelectorName');
-               
-               $mockOrdering1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_QOM_Ordering'), array('getOrder', 'getOperand'), array(), '', FALSE);
-               $mockOrdering1->expects($this->once())->method('getOrder')->will($this->returnValue('unsupported_order'));
-               $mockOrdering1->expects($this->once())->method('getOperand')->will($this->returnValue($mockPropertyValue));
-               $orderings = array($mockOrdering1);
+               $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
+               $mockSource->expects($this->never())->method('getNodeTypeName');
 
-               $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getSelectorName', 'getNodeTypeName'), array(), '', FALSE);
-               $mockSource->expects($this->any())->method('getSelectorName')->will($this->returnValue('tx_myext_tablename'));
-               
-               $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName'), array(), '', FALSE);
+               $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_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->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);               
                $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
                $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
@@ -146,89 +131,25 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend_testcase extends Tx_Extbase_
         * @test
         */
        public function orderStatementGenerationWorksWithMultipleOrderings() {
-               $mockPropertyValue1 = $this->getMock('Tx_Extbase_Persistence_QOM_PropertyValue', array('getPropertyName', 'getSelectorname'), array(), '', FALSE);
-               $mockPropertyValue1->expects($this->atLeastOnce())->method('getPropertyName')->will($this->returnValue('fooProperty'));
-               $mockPropertyValue1->expects($this->atLeastOnce())->method('getSelectorName')->will($this->returnValue('tx_myext_bar'));
-               
-               $mockPropertyValue2 = $this->getMock('Tx_Extbase_Persistence_QOM_PropertyValue', array('getPropertyName', 'getSelectorname'), array(), '', FALSE);
-               $mockPropertyValue2->expects($this->atLeastOnce())->method('getPropertyName')->will($this->returnValue('barProperty'));
-               $mockPropertyValue2->expects($this->atLeastOnce())->method('getSelectorName')->will($this->returnValue('tx_myext_blub'));
-               
-               $mockOrdering1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_QOM_Ordering'), array('getOrder', 'getOperand'), array(), '', FALSE);
-               $mockOrdering1->expects($this->once())->method('getOrder')->will($this->returnValue(Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING));
-               $mockOrdering1->expects($this->once())->method('getOperand')->will($this->returnValue($mockPropertyValue1));
-               $mockOrdering2 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_QOM_Ordering'), array('getOrder', 'getOperand'), array(), '', FALSE);
-               $mockOrdering2->expects($this->once())->method('getOrder')->will($this->returnValue(Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING));
-               $mockOrdering2->expects($this->once())->method('getOperand')->will($this->returnValue($mockPropertyValue2));
-               $orderings = array($mockOrdering1, $mockOrdering2);
-
-               $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array(), array(), '', FALSE);
-
-               $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName'), array(), '', FALSE);
-               $mockDataMapper->expects($this->atLeastOnce())->method('convertPropertyNameToColumnName')->will($this->returnValue('foo_field'));
-               
-               $sql = array();
-               $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);               
-               $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
-               $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
-               
-               $expecedSql = array('orderings' => array('tx_myext_bar.foo_field ASC', 'tx_myext_blub.foo_field DESC'));
-               $this->assertEquals($expecedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function orderStatementGenerationWorksWithDescendingOrder() {
-               $mockPropertyValue = $this->getMock('Tx_Extbase_Persistence_QOM_PropertyValue', array('getPropertyName', 'getSelectorname'), array(), '', FALSE);
-               $mockPropertyValue->expects($this->once())->method('getPropertyName')->will($this->returnValue('fooProperty'));
-               $mockPropertyValue->expects($this->once())->method('getSelectorName')->will($this->returnValue(''));
-               
-               $mockOrdering1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_QOM_Ordering'), array('getOrder', 'getOperand'), array(), '', FALSE);
-               $mockOrdering1->expects($this->once())->method('getOrder')->will($this->returnValue(Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING));
-               $mockOrdering1->expects($this->once())->method('getOperand')->will($this->returnValue($mockPropertyValue));
-               $orderings = array($mockOrdering1);
-
-               $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array(), array(), '', FALSE);
-
-               $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName'), array(), '', FALSE);
-               $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', '')->will($this->returnValue('bar_property'));
-               
-               $sql = array();
-               $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);               
-               $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
-               $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
-               
-               $expecedSql = array('orderings' => array('bar_property DESC'));
-               $this->assertEquals($expecedSql, $sql);
-       }
-
-       /**
-        * @test
-        */
-       public function orderStatementGenerationWorksWithTheSourceSelectorNameIfNotSpecifiedInThePropertyValue() {
-               $mockPropertyValue = $this->getMock('Tx_Extbase_Persistence_QOM_PropertyValue', array('getPropertyName', 'getSelectorname'), array(), '', FALSE);
-               $mockPropertyValue->expects($this->once())->method('getPropertyName')->will($this->returnValue('fooProperty'));
-               $mockPropertyValue->expects($this->once())->method('getSelectorName')->will($this->returnValue(''));
-               
-               $mockOrdering1 = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_QOM_Ordering'), array('getOrder', 'getOperand'), array(), '', FALSE);
-               $mockOrdering1->expects($this->once())->method('getOrder')->will($this->returnValue(Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING));
-               $mockOrdering1->expects($this->once())->method('getOperand')->will($this->returnValue($mockPropertyValue));
-               $orderings = array($mockOrdering1);
-
-               $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array(), array(), '', FALSE);
+               $mockSource = $this->getMock('Tx_Extbase_Persistence_QOM_Selector', array('getNodeTypeName'), array(), '', FALSE);
+               $mockSource->expects($this->any())->method('getNodeTypeName')->will($this->returnValue('Tx_MyExt_ClassName'));
 
-               $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_Mapper_DataMapper', array('convertPropertyNameToColumnName'), array(), '', FALSE);
-               $mockDataMapper->expects($this->once())->method('convertPropertyNameToColumnName')->with('fooProperty', '')->will($this->returnValue('bar_property'));
+               $mockDataMapper = $this->getMock('Tx_Extbase_Persistence_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' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_ASCENDING,
+                       'barProperty' => Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_ORDER_DESCENDING
+                       );
                $mockTypo3DbBackend = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Storage_Typo3DbBackend'), array('parserOrderings'), array(), '', FALSE);               
                $mockTypo3DbBackend->_set('dataMapper', $mockDataMapper);
                $mockTypo3DbBackend->_callRef('parseOrderings', $orderings, $mockSource, $sql);
-               
-               $expecedSql = array('orderings' => array('bar_property ASC'));
-               $this->assertEquals($expecedSql, $sql);
+                       
+               $expecedSql = array('orderings' => array('tx_myext_tablename.converted_fieldname ASC', 'tx_myext_tablename.converted_fieldname DESC'));
+               $this->assertSame($expecedSql, $sql);
        }
-
+       
 }
 ?>
\ No newline at end of file