[+BUGFIX] Extbase (Persistence): Implemented support for mm-relations configured...
authorJochen Rau <j.rau@web.de>
Mon, 26 Oct 2009 09:54:48 +0000 (09:54 +0000)
committerJochen Rau <j.rau@web.de>
Mon, 26 Oct 2009 09:54:48 +0000 (09:54 +0000)
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMap.php
typo3/sysext/extbase/Tests/Persistence/Mapper/DataMap_testcase.php

index 994f405..b886656 100644 (file)
@@ -280,15 +280,12 @@ class Tx_Extbase_Persistence_Mapper_DataMap {
                $columnMap->setTypeOfRelation(Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY);
                if ($columnConfiguration['type'] === 'inline') {
                        $columns = $this->getColumnsDefinition($columnConfiguration['foreign_table']);
-                       var_dump($columns);
-                       var_dump($columnConfiguration['foreign_label']);
                        $columnMap->setChildClassName($this->determineChildClassName($columns[$columnConfiguration['foreign_label']]));
                        $columnMap->setChildTableName($columns[$columnConfiguration['foreign_label']]['foreign_table']);
-                       $columnMap->setChildTableWhereStatement($columns[$columnConfiguration['foreign_label']]['foreign_table_where']);
                        $columnMap->setRelationTableName($columnConfiguration['foreign_table']);
                        $columnMap->setParentKeyFieldName($columnConfiguration['foreign_field']);
                        $columnMap->setChildKeyFieldName($columnConfiguration['foreign_label']);
-                       $columnMap->setChildSortByFieldName($columns[$columnConfiguration['foreign_label']]['foreign_table']);
+                       $columnMap->setChildSortByFieldName($columnConfiguration['foreign_sortby']);
                } else {
                        $columnMap->setChildClassName($this->determineChildClassName($columnConfiguration));
                        $columnMap->setChildTableName($columnConfiguration['foreign_table']);
@@ -301,7 +298,7 @@ class Tx_Extbase_Persistence_Mapper_DataMap {
                                $columnMap->setRelationTableInsertFields($columnConfiguration['MM_insert_fields']);
                        }
                        $columnMap->setRelationTableWhereStatement($columnConfiguration['MM_table_where']);
-                       if ($columnConfiguration['MM_opposite_field']) {
+                       if (!empty($columnConfiguration['MM_opposite_field'])) {
                                $columnMap->setParentKeyFieldName('uid_foreign');
                                $columnMap->setChildKeyFieldName('uid_local');
                                $columnMap->setChildSortByFieldName('sorting_foreign');
index 7a94ed2..cc0e7eb 100644 (file)
@@ -41,7 +41,7 @@ class Tx_Extbase_Persistence_Mapper_DataMap_testcase extends Tx_Extbase_BaseTest
                
                
                $GLOBALS['TSFE']->fe_user->user['uid'] = 999;
-               $GLOBALS['TSFE']->id = 42;              
+               $GLOBALS['TSFE']->id = 42;
        }
        
        public function setupTCA() {
@@ -297,78 +297,108 @@ class Tx_Extbase_Persistence_Mapper_DataMap_testcase extends Tx_Extbase_BaseTest
         * @test
         */
        public function columnMapIsInitializedWithManyToManyRelationOfTypeSelect() {
-           $columnConfiguration = array(
-                       'type' => 'select',
-                       'foreign_class' => 'Tx_MyExtension_Class',
-                       'foreign_table' => 'tx_myextension_table',
-                       'foreign_table_where' => 'WHERE 1=1',
-                       'MM' => 'tx_myextension_mm',
-                       'MM_match_fields' => array('match_field' => 'value'),
-                       // 'MM_insert_fields' => array('insert_field' => 'value'),
-                       'MM_table_where' => 'WHERE 2=2',
-                       // 'MM_opposite_field' => 'opposite_field'
+               $leftColumnsDefinition = array(
+                       'rights' => array(
+                               'type' => 'select',
+                               'foreign_class' => 'Tx_MyExtension_RightClass',
+                               'foreign_table' => 'tx_myextension_righttable',
+                               'foreign_table_where' => 'WHERE 1=1',
+                               'MM' => 'tx_myextension_mm',
+                               'MM_table_where' => 'WHERE 2=2',
+                               ),
                        );
                $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('setChildClassName')->with($this->equalTo('Tx_MyExtension_Class'));
-               $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_table'));
+               $mockColumnMap->expects($this->once())->method('setChildClassName')->with($this->equalTo('Tx_MyExtension_RightClass'));
+               $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->once())->method('setRelationTableMatchFields')->with($this->equalTo(array('match_field' => 'value')));
+               $mockColumnMap->expects($this->never())->method('setRelationTableMatchFields');
                $mockColumnMap->expects($this->never())->method('setRelationTableInsertFields');
                
                $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('dummy'), array(), '', FALSE);
-               $mockDataMap->_callRef('setManyToManyRelation', $mockColumnMap, $columnConfiguration);
+               $mockDataMap->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
        }
        
-       // /**
-       //  * @test
-       //  */
-       // public function columnMapIsInitializedWithManyToManyRelationOfTypeInline() {
-       //     $parentColumnConfiguration = array(
-       //              'type' => 'inline',
-       //              'foreign_table' => 'tx_myextension_mm',
-       //              'foreign_field' => 'uid_local',
-       //              'foreign_label' => 'uid_foreign'
-       //              );
-       //     $relationTableColumnsDefiniton = array(
-       //              'uid_local' => array(
-       //                      'foreign_class' => 'Tx_MyExtension_ParentClass',
-       //                      'foreign_table' => 'tx_myextension_parenttable'
-       //                      ),
-       //              'uid_foreign' => array(
-       //                      'foreign_class' => 'Tx_MyExtension_ChildClass',
-       //                      'foreign_table' => 'tx_myextension_childtable'
-       //                      )
-       //              );
-       //     $childColumnsDefinition = array(
-       //              array(
-       //                      'uid_local' => array(
-       //                              'type' => 'inline',
-       //                              'foreign_table' => 'tx_myextension_mm',
-       //                              'foreign_field' => 'uid_local',
-       //                              'foreign_label' => 'uid_foreign'
-       //                              )
-       //                      )
-       //              );
-       //      $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('setChildClassName')->with($this->equalTo('Tx_MyExtension_Class'));
-       //      $mockColumnMap->expects($this->once())->method('setChildTableName')->with($this->equalTo('tx_myextension_table'));
-       //      $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');
-       //      
-       //      $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('getColumnsDefinition', 'determineChildClassName'), array(), '', FALSE);
-       //      $mockDataMap->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefiniton));
-       //      $mockDataMap->expects($this->once())->method('determineChildClassName')->with($this->equalTo($relationTableColumnsDefiniton))->will($this->returnValue('Tx_MyExtension_Class'));
-       //      $mockDataMap->_callRef('setManyToManyRelation', $mockColumnMap, $parentColumnConfiguration);
-       // }
+       /**
+        * @test
+        */
+       public function columnMapIsInitializedWithOppositeManyToManyRelationOfTypeSelect() {
+               $rightColumnsDefinition = array(
+                       'lefts' => array(
+                               'type' => 'select',
+                               'foreign_class' => 'Tx_MyExtension_LeftClass',
+                               'foreign_table' => 'tx_myextension_lefttable',
+                               'MM' => 'tx_myextension_mm',
+                               'MM_opposite_field' => 'rights'
+                               ),
+                       );
+               $leftColumnsDefinition['rights']['MM_opposite_field'] = 'opposite_field';               
+               $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('setChildClassName')->with($this->equalTo('Tx_MyExtension_LeftClass'));
+               $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');
+               
+               $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('dummy'), array(), '', FALSE);
+               $mockDataMap->_callRef('setManyToManyRelation', $mockColumnMap, $rightColumnsDefinition['lefts']);
+       }
+       
+       /**
+        * @test
+        */
+       public function columnMapIsInitializedWithManyToManyRelationOfTypeInline() {
+           $leftColumnsDefinition = array(
+                       'rights' => array(
+                               'type' => 'inline',
+                               'foreign_table' => 'tx_myextension_mm',
+                               'foreign_field' => 'uid_local',
+                               'foreign_label' => 'uid_foreign',
+                               'foreign_sortby' => 'sorting'
+                               )
+                       );
+           $relationTableColumnsDefiniton = array(
+                       'uid_local' => array(
+                               'foreign_class' => 'Tx_MyExtension_LocalClass',
+                               'foreign_table' => 'tx_myextension_localtable'
+                               ),
+                       'uid_foreign' => array(
+                               'foreign_class' => 'Tx_MyExtension_RightClass',
+                               'foreign_table' => 'tx_myextension_righttable'
+                               )
+                       );
+           $rightColumnsDefinition = array(
+                       'lefts' => array(
+                               'type' => 'inline',
+                               'foreign_table' => 'tx_myextension_mm',
+                               'foreign_field' => 'uid_foreign',
+                               'foreign_label' => 'uid_local',
+                               'foreign_sortby' => 'sorting_foreign'
+                               )
+                       );
+               $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('setChildClassName')->with($this->equalTo('Tx_MyExtension_RightClass'));
+               $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');
+               
+               $mockDataMap = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Persistence_Mapper_DataMap'), array('getColumnsDefinition', 'determineChildClassName'), array(), '', FALSE);
+               $mockDataMap->expects($this->once())->method('getColumnsDefinition')->with($this->equalTo('tx_myextension_mm'))->will($this->returnValue($relationTableColumnsDefiniton));
+               $mockDataMap->expects($this->once())->method('determineChildClassName')->with($this->equalTo($relationTableColumnsDefiniton['uid_foreign']))->will($this->returnValue('Tx_MyExtension_RightClass'));
+               $mockDataMap->_callRef('setManyToManyRelation', $mockColumnMap, $leftColumnsDefinition['rights']);
+       }
        
 }
 ?>
\ No newline at end of file