From 065d604212b9165d50307e95c39d76cb73bdfa58 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20E=C3=9Fl?= <indy.essl@gmail.com>
Date: Sat, 7 Mar 2020 16:26:43 +0100
Subject: [PATCH] [BUGFIX] Take recordType into account for extbase persistence
 config

The changes made in #87623 made it impossible to resolve the
"recordType" of extbase objects in the php persistence configuration.

Resolves: #90560
Releases: master
Change-Id: If309a8e0f3156902a02af1d98909d79ad248cb02
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63604
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Alexander Schnitzler <git@alexanderschnitzler.de>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Alexander Schnitzler <git@alexanderschnitzler.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
---
 .../Generic/Mapper/DataMapFactory.php         |  2 +-
 .../Generic/Mapper/DataMapFactoryTest.php     | 70 +++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 typo3/sysext/extbase/Tests/Functional/Persistence/Generic/Mapper/DataMapFactoryTest.php

diff --git a/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php b/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php
index dc17ebb3cd95..fa87eba013ef 100644
--- a/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php
+++ b/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php
@@ -138,7 +138,7 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface
             $classSettings = $this->classesConfiguration->getConfigurationFor($className);
             $subclasses = $this->classesConfiguration->getSubClasses($className);
             if (isset($classSettings['recordType']) && $classSettings['recordType'] !== '') {
-                $recordType = $classSettings['mapping']['recordType'];
+                $recordType = $classSettings['recordType'];
             }
             if (isset($classSettings['tableName']) && $classSettings['tableName'] !== '') {
                 $tableName = $classSettings['tableName'];
diff --git a/typo3/sysext/extbase/Tests/Functional/Persistence/Generic/Mapper/DataMapFactoryTest.php b/typo3/sysext/extbase/Tests/Functional/Persistence/Generic/Mapper/DataMapFactoryTest.php
new file mode 100644
index 000000000000..39865c60dd69
--- /dev/null
+++ b/typo3/sysext/extbase/Tests/Functional/Persistence/Generic/Mapper/DataMapFactoryTest.php
@@ -0,0 +1,70 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Functional\Persistence\Generic\Mapper;
+
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
+class DataMapFactoryTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
+{
+    /**
+     * @var \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory
+     */
+    protected $dataMapFactory;
+
+    /**
+     * @var array
+     */
+    protected $testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
+
+    /**
+     * @var array
+     */
+    protected $coreExtensionsToLoad = ['extbase', 'fluid'];
+
+    /**
+     * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface The object manager
+     */
+    protected $objectManager;
+
+    /**
+     * Sets up this test suite.
+     */
+    protected function setUp(): void
+    {
+        parent::setUp();
+
+        $this->objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
+        $this->dataMapFactory = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapFactory::class);
+
+        $GLOBALS['BE_USER'] = new BackendUserAuthentication();
+    }
+
+    /**
+     * @test
+     */
+    public function classSettingsAreResolved()
+    {
+        $dataMap = $this->dataMapFactory->buildDataMap(\ExtbaseTeam\BlogExample\Domain\Model\Administrator::class);
+
+        self::assertInstanceOf(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class, $dataMap);
+        self::assertEquals('ExtbaseTeam\BlogExample\Domain\Model\Administrator', $dataMap->getRecordType());
+        self::assertEquals('fe_users', $dataMap->getTableName());
+    }
+
+    /**
+     * @test
+     */
+    public function columnMapPropertiesAreResolved()
+    {
+        $dataMap = $this->dataMapFactory->buildDataMap(\ExtbaseTeam\BlogExample\Domain\Model\TtContent::class);
+
+        self::assertInstanceOf(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class, $dataMap);
+        self::assertNull($dataMap->getColumnMap('thisPropertyDoesNotExist'));
+
+        $headerColumnMap = $dataMap->getColumnMap('header');
+
+        self::assertInstanceOf(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap::class, $headerColumnMap);
+        self::assertEquals('header', $headerColumnMap->getPropertyName());
+        self::assertEquals('header', $headerColumnMap->getColumnName());
+    }
+}
-- 
GitLab