[BUGFIX] Fix using contains in query on property of group 57/54057/2
authorŁukasz Uznański <l.uznanski@macopedia.pl>
Fri, 8 Sep 2017 09:29:36 +0000 (11:29 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 9 Sep 2017 13:11:09 +0000 (15:11 +0200)
Related: master, 8.7
Resolves: #80215
Change-Id: I6f5c88650d6167550a46ad2200c846ec9d11d34a
Reviewed-on: https://review.typo3.org/54057
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapFactoryTest.php

index 1ae0504..007ba4c 100644 (file)
@@ -339,6 +339,11 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface
                 )
             ) {
                 $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_MANY);
+            } elseif (
+                isset($columnConfiguration['type']) && $columnConfiguration['type'] === 'group'
+                && (!isset($columnConfiguration['maxitems']) || $columnConfiguration['maxitems'] > 1)
+            ) {
+                $columnMap->setTypeOfRelation(ColumnMap::RELATION_HAS_MANY);
             } else {
                 $columnMap->setTypeOfRelation(ColumnMap::RELATION_NONE);
             }
index 977ffa9..d2ca16f 100644 (file)
@@ -66,8 +66,8 @@ class DataMapFactoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     {
         $mockColumnMap = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class);
         $matchFields = [
-                'fieldname' => 'foo_model'
-            ];
+            'fieldname' => 'foo_model'
+        ];
         $columnConfiguration = [
             'type' => 'select',
             'foreign_table' => 'tx_myextension_bar',
@@ -89,8 +89,8 @@ class DataMapFactoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     {
         $mockColumnMap = $this->createMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class);
         $matchFields = [
-                'fieldname' => 'foo_model'
-            ];
+            'fieldname' => 'foo_model'
+        ];
         $columnConfiguration = [
             'type' => 'select',
             'foreign_table' => 'tx_myextension_bar',
@@ -175,6 +175,45 @@ class DataMapFactoryTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     }
 
     /**
+     * @return array
+     */
+    public function columnConfigurationIsInitializedWithMaxItemsEvaluationForTypeGroupDataProvider()
+    {
+        return [
+            'maxitems not set' => ['', 'RELATION_HAS_MANY'],
+            'maxitems equals 1' => ['1', 'RELATION_NONE'],
+            'maxitems higher than 1' => ['10', 'RELATION_HAS_MANY']
+        ];
+    }
+
+    /**
+     * @test
+     *
+     * @dataProvider columnConfigurationIsInitializedWithMaxItemsEvaluationForTypeGroupDataProvider
+     */
+    public function setRelationsDetectsTypeGroupAndRelationManyToMany($maxitems, $relation)
+    {
+        $columnMap = new \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap('foo', 'foo');
+        if (empty($maxitems)) {
+            $columnConfiguration = [
+                'type' => 'group',
+            ];
+        } else {
+            $columnConfiguration = [
+                'type' => 'group',
+                'maxitems' => $maxitems
+            ];
+        }
+        $propertyMetaData = [];
+        $mockDataMapFactory = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class, ['setOneToOneRelation', 'setOneToManyRelation', 'setManyToManyRelation'], [], '', false);
+        $mockDataMapFactory->expects($this->never())->method('setOneToOneRelation');
+        $mockDataMapFactory->expects($this->never())->method('setOneToManyRelation');
+        $mockDataMapFactory->expects($this->never())->method('setManyToManyRelation');
+        $actualColumnMap = $mockDataMapFactory->_callRef('setRelations', $columnMap, $columnConfiguration, $propertyMetaData);
+        $this->assertSame($relation, $actualColumnMap->getTypeOfRelation());
+    }
+
+    /**
      * @test
      */
     public function setRelationsDetectsManyToManyRelationOfTypeSelect()