[BUGFIX] DataMapperFactory respects foreign_table_field
authorPeter Niederlag(office) <netservice@niekom.de>
Thu, 21 Jul 2011 13:23:53 +0000 (15:23 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Wed, 14 Nov 2012 23:19:33 +0000 (00:19 +0100)
- add foreign_table_field if present in $TCA
- add a corresponding unit test

Change-Id: I02eac46a7e4b17c001fe30fb9469e1e94b3dfb0f
Resolves: #28369
Releases: 4.7, 6.0
Reviewed-on: http://review.typo3.org/3454
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Stefan Neufeind
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php
typo3/sysext/extbase/Tests/Unit/Persistence/Mapper/DataMapFactoryTest.php

index 3aefb71..5308506 100644 (file)
@@ -408,6 +408,9 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface {
                        $columnMap->setParentKeyFieldName($columnConfiguration['foreign_field']);
                        $columnMap->setChildKeyFieldName($childKeyFieldName);
                        $columnMap->setChildSortByFieldName($columnConfiguration['foreign_sortby']);
+                       if (!empty($columnConfiguration['foreign_table_field'])) {
+                               $columnMap->setParentTableFieldName($columnConfiguration['foreign_table_field']);
+                       }
                } else {
                        throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedRelationException('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);
                }
index 2f3f17b..fbf46b2 100644 (file)
@@ -297,6 +297,44 @@ class DataMapFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @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(