[BUGFIX] Show correct label for IRRE records
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaGroupTest.php
index 43e65e9..d1d09c5 100644 (file)
@@ -14,11 +14,12 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
  * The TYPO3 project - inspiring people to share!
  */
 
-
 use Prophecy\Prophecy\ObjectProphecy;
+use TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup;
 use TYPO3\CMS\Core\Database\RelationHandler;
+use TYPO3\CMS\Core\Resource\Folder;
+use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Tests\UnitTestCase;
-use TYPO3\CMS\Backend\Form\FormDataProvider\TcaGroup;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -31,9 +32,21 @@ class TcaGroupTest extends UnitTestCase
      */
     protected $subject;
 
+    /**
+     * @var array
+     */
+    protected $singletonInstances;
+
     protected function setUp()
     {
         $this->subject = new TcaGroup();
+        $this->singletonInstances = GeneralUtility::getSingletonInstances();
+    }
+
+    protected function tearDown()
+    {
+        GeneralUtility::resetSingletonInstances($this->singletonInstances);
+        parent::tearDown();
     }
 
     /**
@@ -45,7 +58,7 @@ class TcaGroupTest extends UnitTestCase
             'databaseRow' => [
                 'aField' => 'aValue',
             ],
-            'vanillaTableTca' => [
+            'processedTca' => [
                 'columns' => [
                     'aField' => [
                         'config' => [
@@ -62,10 +75,10 @@ class TcaGroupTest extends UnitTestCase
     /**
      * @test
      */
-    public function addDataThrowsExceptionWithTypeGroupAndNoValiInternalType()
+    public function addDataThrowsExceptionWithTypeGroupAndNoValidInternalType()
     {
         $input = [
-            'vanillaTableTca' => [
+            'processedTca' => [
                 'columns' => [
                     'aField' => [
                         'config' => [
@@ -89,7 +102,7 @@ class TcaGroupTest extends UnitTestCase
             'databaseRow' => [
                 'aField' => '/aDir/aFile.txt,/anotherDir/anotherFile.css',
             ],
-            'vanillaTableTca' => [
+            'processedTca' => [
                 'columns' => [
                     'aField' => [
                         'config' => [
@@ -108,6 +121,43 @@ class TcaGroupTest extends UnitTestCase
     /**
      * @test
      */
+    public function addDataSetsFolderData()
+    {
+        $input = [
+            'databaseRow' => [
+                'aField' => '1:/aFolder/anotherFolder/',
+            ],
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'group',
+                            'internal_type' => 'folder',
+                        ],
+                    ],
+                ],
+            ],
+        ];
+
+        /** @var Folder|ObjectProphecy $relationHandlerProphecy */
+        $folderProphecy = $this->prophesize(Folder::class);
+        $folderProphecy->getIdentifier()->shouldBeCalled()->willReturn('anotherFolder');
+
+        /** @var ResourceFactory|ObjectProphecy $relationHandlerProphecy */
+        $resourceFactoryProphecy = $this->prophesize(ResourceFactory::class);
+        GeneralUtility::setSingletonInstance(ResourceFactory::class, $resourceFactoryProphecy->reveal());
+        $resourceFactoryProphecy->retrieveFileOrFolderObject('1:/aFolder/anotherFolder/')
+            ->shouldBeCalled()
+            ->willReturn($folderProphecy->reveal());
+
+        $expected = $input;
+        $expected['databaseRow']['aField'] = '1%3A%2FaFolder%2FanotherFolder%2F|anotherFolder';
+        $this->assertSame($expected, $this->subject->addData($input));
+    }
+
+    /**
+     * @test
+     */
     public function addDataSetsDatabaseData()
     {
         $aFieldConfig = [
@@ -122,7 +172,7 @@ class TcaGroupTest extends UnitTestCase
                 'uid' => 42,
                 'aField' => '1,2',
             ],
-            'vanillaTableTca' => [
+            'processedTca' => [
                 'columns' => [
                     'aField' => [
                         'config' => $aFieldConfig,