[BUGFIX] MM_match_fields is ignored when persisting MM relations
authorKai Vogel <kai.vogel@speedprogs.de>
Wed, 21 Nov 2012 14:19:48 +0000 (15:19 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 4 Dec 2012 16:09:29 +0000 (17:09 +0100)
With this patch MM_match_fields will be stored into MM table when
persisting MM relations between Extbase objects.

Change-Id: I8270f05c5dda4d15c42ad187efe9bc93be003c5a
Resolves: #43198
Releases: 6.1, 6.0
Reviewed-on: http://review.typo3.org/16854
Reviewed-by: Kai Vogel
Tested-by: Kai Vogel
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/BackendTest.php [new file with mode: 0644]

index 5b49d95..9eee192 100644 (file)
@@ -643,6 +643,12 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                if ($columnMap->getRelationTablePageIdColumnName() !== NULL) {
                        $row[$columnMap->getRelationTablePageIdColumnName()] = $this->determineStoragePageIdForNewRecord();
                }
+               $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
+               if (count($relationTableMatchFields)) {
+                       foreach ($relationTableMatchFields as $matchField => $matchValue) {
+                               $row[$matchField] = $matchValue;
+                       }
+               }
                $relationTableInsertFields = $columnMap->getRelationTableInsertFields();
                if (count($relationTableInsertFields)) {
                        foreach ($relationTableInsertFields as $insertField => $insertValue) {
diff --git a/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/BackendTest.php b/typo3/sysext/extbase/Tests/Unit/Persistence/Generic/BackendTest.php
new file mode 100644 (file)
index 0000000..b902a7b
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic;
+
+/***********************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Kai Vogel <kai.vogel@speedprogs.de>, Speedprogs.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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ **********************************************************************/
+
+/**
+ * Test case
+ */
+class BackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+
+       /**
+        * @test
+        */
+       public function insertRelationInRelationtableSetsMmMatchFieldsInRow() {
+               /* \TYPO3\CMS\Extbase\Persistence\Generic\Backend|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */
+               $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Backend', array('dummy'), array(), '', FALSE);
+               /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper|\PHPUnit_Framework_MockObject_MockObject */
+               $dataMapper = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Mapper\\DataMapper');
+               /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap|\PHPUnit_Framework_MockObject_MockObject */
+               $dataMap = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Mapper\\DataMap', array(), array(), '', FALSE);
+               /* \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap|\PHPUnit_Framework_MockObject_MockObject */
+               $columnMap = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Mapper\\ColumnMap', array(), array(), '', FALSE);
+               /* \TYPO3\CMS\Extbase\Persistence\Generic\Storage\BackendInterface|\PHPUnit_Framework_MockObject_MockObject */
+               $storageBackend = $this->getMock('TYPO3\\CMS\Extbase\\Persistence\\Generic\\Storage\\BackendInterface');
+               /* \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
+               $domainObject = $this->getMock('TYPO3\\CMS\Extbase\\DomainObject\\DomainObjectInterface');
+
+               $mmMatchFields = array(
+                       'identifier' => 'myTable:myField',
+               );
+
+               $expectedRow = array(
+                       'identifier' => 'myTable:myField',
+                       '' => 0
+               );
+
+               $columnMap
+                       ->expects($this->once())
+                       ->method('getRelationTableMatchFields')
+                       ->will($this->returnValue($mmMatchFields));
+               $columnMap
+                       ->expects($this->any())
+                       ->method('getChildSortByFieldName')
+                       ->will($this->returnValue(''));
+               $dataMap
+                       ->expects($this->any())
+                       ->method('getColumnMap')
+                       ->will($this->returnValue($columnMap));
+               $dataMapper
+                       ->expects($this->any())
+                       ->method('getDataMap')
+                       ->will($this->returnValue($dataMap));
+               $storageBackend
+                       ->expects($this->once())
+                       ->method('addRow')
+                       ->with(NULL, $expectedRow, TRUE);
+
+               $fixture->_set('dataMapper', $dataMapper);
+               $fixture->_set('storageBackend', $storageBackend);
+               $fixture->_call('insertRelationInRelationtable', $domainObject, $domainObject, '');
+       }
+
+}
+?>
\ No newline at end of file