[BUGFIX] Show correct label for IRRE records
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Form / FormDataProvider / TcaRadioItemsTest.php
index e511a7a..35e0c8a 100644 (file)
@@ -16,398 +16,409 @@ namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
 
 use Prophecy\Argument;
 use Prophecy\Prophecy\ObjectProphecy;
-use TYPO3\CMS\Core\Tests\UnitTestCase;
 use TYPO3\CMS\Backend\Form\FormDataProvider\TcaRadioItems;
-use TYPO3\CMS\Lang\LanguageService;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
-use TYPO3\CMS\Core\Messaging\FlashMessageService;
 use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
+use TYPO3\CMS\Core\Messaging\FlashMessageService;
+use TYPO3\CMS\Core\Tests\UnitTestCase;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Lang\LanguageService;
 
 /**
  * Test case
  */
-class TcaRadioItemsTest extends UnitTestCase {
-
-       /**
-        * @var TcaRadioItems
-        */
-       protected $subject;
-
-       /**
-        * @var array A backup of registered singleton instances
-        */
-       protected $singletonInstances = array();
-
-       protected function setUp() {
-               $this->singletonInstances = GeneralUtility::getSingletonInstances();
-               $this->subject = new TcaRadioItems();
-       }
-
-       protected function tearDown() {
-               GeneralUtility::purgeInstances();
-               GeneralUtility::resetSingletonInstances($this->singletonInstances);
-               parent::tearDown();
-       }
-
-       /**
-        * @test
-        */
-       public function addDataThrowsExceptionIfRadioItemsNotDefined() {
-               $input = [
-                       'processedTca' => [
-                               'columns' => [
-                                       'aField' => [
-                                               'config' => [
-                                                       'type' => 'radio',
-                                               ],
-                                       ],
-                               ],
-                       ],
-               ];
-               $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438594829);
-               $this->subject->addData($input);
-       }
-
-       /**
-        * @test
-        */
-       public function addDataKeepExistingItems() {
-               $input = [
-                       'processedTca' => [
-                               'columns' => [
-                                       'aField' => [
-                                               'config' => [
-                                                       'type' => 'radio',
-                                                       'items' => [
-                                                               0 => [
-                                                                       'foo',
-                                                                       'bar',
-                                                               ],
-                                                       ],
-                                               ],
-                                       ],
-                               ],
-                       ],
-               ];
-               $languageService = $this->prophesize(LanguageService::class);
-               $GLOBALS['LANG'] = $languageService->reveal();
-               $languageService->sL(Argument::cetera())->willReturnArgument(0);
-
-               $expected = $input;
-               $this->assertSame($expected, $this->subject->addData($input));
-       }
-
-       /**
-        * @test
-        */
-       public function addDataThrowsExceptionIfItemsAreNoArray() {
-               $input = [
-                       'processedTca' => [
-                               'columns' => [
-                                       'aField' => [
-                                               'config' => [
-                                                       'type' => 'radio',
-                                                       'items' => [
-                                                               0 => 'aoeu',
-                                                       ],
-                                               ],
-                                       ],
-                               ],
-                       ],
-               ];
-               $this->setExpectedException(\UnexpectedValueException::class, $this->any(), 1438607163);
-               $this->subject->addData($input);
-       }
-
-       /**
-        * @test
-        */
-       public function addDataThrowsExceptionIfItemLabelIsNotSet() {
-               $input = [
-                       'processedTca' => [
-                               'columns' => [
-                                       'aField' => [
-                                               'config' => [
-                                                       'type' => 'radio',
-                                                       'items' => [
-                                                               0 => [
-                                                                       'funnyKey' => 'funnyValue',
-                                                               ],
-                                                       ],
-                                               ],
-                                       ],
-                               ],
-                       ],
-               ];
-               $this->setExpectedException(\UnexpectedValueException::class, $this->any(), 1438607164);
-               $this->subject->addData($input);
-       }
-
-       /**
-        * @test
-        */
-       public function addDataThrowsExceptionIfItemValueIsNotSet() {
-               $input = [
-                       'processedTca' => [
-                               'columns' => [
-                                       'aField' => [
-                                               'config' => [
-                                                       'type' => 'radio',
-                                                       'items' => [
-                                                               0 => [
-                                                                       0 => 'aLabel',
-                                                               ],
-                                                       ],
-                                               ],
-                                       ],
-                               ],
-                       ],
-               ];
-               $this->setExpectedException(\UnexpectedValueException::class, $this->any(), 1438607165);
-               $this->subject->addData($input);
-       }
-
-       /**
-        * @test
-        */
-       public function addDataTranslatesItemLabels() {
-               $input = [
-                       'processedTca' => [
-                               'columns' => [
-                                       'aField' => [
-                                               'config' => [
-                                                       'type' => 'radio',
-                                                       'items' => [
-                                                               0 => [
-                                                                       0 => 'aLabel',
-                                                                       1 => 'aValue',
-                                                               ],
-                                                       ],
-                                               ],
-                                       ],
-                               ],
-                       ],
-               ];
-
-               /** @var LanguageService|ObjectProphecy $languageService */
-               $languageService = $this->prophesize(LanguageService::class);
-               $GLOBALS['LANG'] = $languageService->reveal();
-
-               $languageService->sL('aLabel')->shouldBeCalled()->willReturn('translated');
-
-               $expected = $input;
-               $expected['processedTca']['columns']['aField']['config']['items'][0][0] = 'translated';
-
-               $this->assertSame($expected, $this->subject->addData($input));
-               $this->subject->addData($input);
-       }
-
-       /**
-        * @test
-        */
-       public function addDataCallsItemsProcFunc() {
-               $input = [
-                       'tableName' => 'aTable',
-                       'databaseRow' => [],
-                       'processedTca' => [
-                               'columns' => [
-                                       'aField' => [
-                                               'config' => [
-                                                       'type' => 'radio',
-                                                       'items' => [],
-                                                       'itemsProcFunc' => function (array $parameters, $pObj) {
-                                                               $parameters['items'] = [
-                                                                       'foo' => 'bar',
-                                                               ];
-                                                       },
-                                               ],
-                                       ],
-                               ],
-                       ],
-               ];
-               $expected = $input;
-               $expected['processedTca']['columns']['aField']['config'] = [
-                       'type' => 'radio',
-                       'items' => [
-                               'foo' => 'bar',
-                       ],
-               ];
-               $this->assertSame($expected, $this->subject->addData($input));
-       }
-
-       /**
-        * @test
-        */
-       public function addDataItemsProcFuncReceivesParameters() {
-               $input = [
-                       'tableName' => 'aTable',
-                       'databaseRow' => [
-                               'aField' => 'aValue',
-                       ],
-                       'pageTsConfigMerged' => [
-                               'TCEFORM.' => [
-                                       'aTable.' => [
-                                               'aField.' => [
-                                                       'itemsProcFunc.' => [
-                                                               'itemParamKey' => 'itemParamValue',
-                                                       ],
-                                               ]
-                                       ],
-                               ],
-                       ],
-                       'processedTca' => [
-                               'columns' => [
-                                       'aField' => [
-                                               'config' => [
-                                                       'type' => 'radio',
-                                                       'aKey' => 'aValue',
-                                                       'items' => [
-                                                               0 => [
-                                                                       'foo',
-                                                                       'bar',
-                                                               ],
-                                                       ],
-                                                       'itemsProcFunc' => function (array $parameters, $pObj) {
-                                                               if ($parameters['items'] !== [ 0 => [ 'foo', 'bar'] ]
-                                                                       || $parameters['config']['aKey'] !== 'aValue'
-                                                                       || $parameters['TSconfig'] !== [ 'itemParamKey' => 'itemParamValue' ]
-                                                                       || $parameters['table'] !== 'aTable'
-                                                                       || $parameters['row'] !== [ 'aField' => 'aValue' ]
-                                                                       || $parameters['field'] !== 'aField'
-                                                               ) {
-                                                                       throw new \UnexpectedValueException('broken', 1438604329);
-                                                               }
-                                                       },
-                                               ],
-                                       ],
-                               ],
-                       ],
-               ];
-
-               $languageService = $this->prophesize(LanguageService::class);
-               $GLOBALS['LANG'] = $languageService->reveal();
-               $languageService->sL(Argument::cetera())->willReturnArgument(0);
-               /** @var FlashMessage|ObjectProphecy $flashMessage */
-               $flashMessage = $this->prophesize(FlashMessage::class);
-               GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal());
-               /** @var FlashMessageService|ObjectProphecy $flashMessageService */
-               $flashMessageService = $this->prophesize(FlashMessageService::class);
-               GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal());
-               /** @var FlashMessageQueue|ObjectProphecy $flashMessageQueue */
-               $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
-               $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
-
-               // itemsProcFunc must NOT have raised an exception
-               $flashMessageQueue->enqueue($flashMessage)->shouldNotBeCalled();
-
-               $this->subject->addData($input);
-       }
-
-       /**
-        * @test
-        */
-       public function addDataItemsProcFuncEnqueuesFlashMessageOnException() {
-               $input = [
-                       'tableName' => 'aTable',
-                       'databaseRow' => [
-                               'aField' => 'aValue',
-                       ],
-                       'pageTsConfigMerged' => [
-                               'TCEFORM.' => [
-                                       'aTable.' => [
-                                               'aField.' => [
-                                                       'itemsProcFunc.' => [
-                                                               'itemParamKey' => 'itemParamValue',
-                                                       ],
-                                               ]
-                                       ],
-                               ],
-                       ],
-                       'processedTca' => [
-                               'columns' => [
-                                       'aField' => [
-                                               'config' => [
-                                                       'type' => 'radio',
-                                                       'aKey' => 'aValue',
-                                                       'items' => [
-                                                               0 => [
-                                                                       'foo',
-                                                                       'bar',
-                                                               ],
-                                                       ],
-                                                       'itemsProcFunc' => function (array $parameters, $pObj) {
-                                                               throw new \UnexpectedValueException('anException', 1438604329);
-                                                       },
-                                               ],
-                                       ],
-                               ],
-                       ],
-               ];
-
-               $languageService = $this->prophesize(LanguageService::class);
-               $GLOBALS['LANG'] = $languageService->reveal();
-               /** @var FlashMessage|ObjectProphecy $flashMessage */
-               $flashMessage = $this->prophesize(FlashMessage::class);
-               GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal());
-               /** @var FlashMessageService|ObjectProphecy $flashMessageService */
-               $flashMessageService = $this->prophesize(FlashMessageService::class);
-               GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal());
-               /** @var FlashMessageQueue|ObjectProphecy $flashMessageQueue */
-               $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
-               $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
-
-               $flashMessageQueue->enqueue($flashMessage)->shouldBeCalled();
-
-               $this->subject->addData($input);
-       }
-
-       /**
-        * @test
-        */
-       public function addDataTranslatesItemLabelsFromPageTsConfig() {
-               $input = [
-                       'tableName' => 'aTable',
-                       'processedTca' => [
-                               'columns' => [
-                                       'aField' => [
-                                               'config' => [
-                                                       'type' => 'radio',
-                                                       'items' => [
-                                                               0 => [
-                                                                       0 => 'aLabel',
-                                                                       1 => 'aValue',
-                                                               ],
-                                                       ],
-                                               ],
-                                       ],
-                               ],
-                       ],
-                       'pageTsConfigMerged' => [
-                               'TCEFORM.' => [
-                                       'aTable.' => [
-                                               'aField.' => [
-                                                       'altLabels.' => [
-                                                               0 => 'labelOverride',
-                                                       ],
-                                               ]
-                                       ],
-                               ],
-                       ],
-               ];
-
-               /** @var LanguageService|ObjectProphecy $languageService */
-               $languageService = $this->prophesize(LanguageService::class);
-               $GLOBALS['LANG'] = $languageService->reveal();
-               $languageService->sL('aLabel')->willReturnArgument(0);
-
-               $languageService->sL('labelOverride')->shouldBeCalled()->willReturnArgument(0);
-
-               $expected = $input;
-               $expected['processedTca']['columns']['aField']['config']['items'][0][0] = 'labelOverride';
-
-               $this->assertSame($expected, $this->subject->addData($input));
-               $this->subject->addData($input);
-       }
-
+class TcaRadioItemsTest extends UnitTestCase
+{
+    /**
+     * @var TcaRadioItems
+     */
+    protected $subject;
+
+    /**
+     * @var array A backup of registered singleton instances
+     */
+    protected $singletonInstances = array();
+
+    protected function setUp()
+    {
+        $this->singletonInstances = GeneralUtility::getSingletonInstances();
+        $this->subject = new TcaRadioItems();
+    }
+
+    protected function tearDown()
+    {
+        GeneralUtility::purgeInstances();
+        GeneralUtility::resetSingletonInstances($this->singletonInstances);
+        parent::tearDown();
+    }
+
+    /**
+     * @test
+     */
+    public function addDataThrowsExceptionIfRadioItemsNotDefined()
+    {
+        $input = [
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'radio',
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1438594829);
+        $this->subject->addData($input);
+    }
+
+    /**
+     * @test
+     */
+    public function addDataKeepExistingItems()
+    {
+        $input = [
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'radio',
+                            'items' => [
+                                0 => [
+                                    'foo',
+                                    'bar',
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $languageService = $this->prophesize(LanguageService::class);
+        $GLOBALS['LANG'] = $languageService->reveal();
+        $languageService->sL(Argument::cetera())->willReturnArgument(0);
+
+        $expected = $input;
+        $this->assertSame($expected, $this->subject->addData($input));
+    }
+
+    /**
+     * @test
+     */
+    public function addDataThrowsExceptionIfItemsAreNoArray()
+    {
+        $input = [
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'radio',
+                            'items' => [
+                                0 => 'aoeu',
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $this->setExpectedException(\UnexpectedValueException::class, $this->any(), 1438607163);
+        $this->subject->addData($input);
+    }
+
+    /**
+     * @test
+     */
+    public function addDataThrowsExceptionIfItemLabelIsNotSet()
+    {
+        $input = [
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'radio',
+                            'items' => [
+                                0 => [
+                                    'funnyKey' => 'funnyValue',
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $this->setExpectedException(\UnexpectedValueException::class, $this->any(), 1438607164);
+        $this->subject->addData($input);
+    }
+
+    /**
+     * @test
+     */
+    public function addDataThrowsExceptionIfItemValueIsNotSet()
+    {
+        $input = [
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'radio',
+                            'items' => [
+                                0 => [
+                                    0 => 'aLabel',
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $this->setExpectedException(\UnexpectedValueException::class, $this->any(), 1438607165);
+        $this->subject->addData($input);
+    }
+
+    /**
+     * @test
+     */
+    public function addDataTranslatesItemLabels()
+    {
+        $input = [
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'radio',
+                            'items' => [
+                                0 => [
+                                    0 => 'aLabel',
+                                    1 => 'aValue',
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ];
+
+        /** @var LanguageService|ObjectProphecy $languageService */
+        $languageService = $this->prophesize(LanguageService::class);
+        $GLOBALS['LANG'] = $languageService->reveal();
+
+        $languageService->sL('aLabel')->shouldBeCalled()->willReturn('translated');
+
+        $expected = $input;
+        $expected['processedTca']['columns']['aField']['config']['items'][0][0] = 'translated';
+
+        $this->assertSame($expected, $this->subject->addData($input));
+        $this->subject->addData($input);
+    }
+
+    /**
+     * @test
+     */
+    public function addDataCallsItemsProcFunc()
+    {
+        $input = [
+            'tableName' => 'aTable',
+            'databaseRow' => [],
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'radio',
+                            'items' => [],
+                            'itemsProcFunc' => function (array $parameters, $pObj) {
+                                $parameters['items'] = [
+                                    'foo' => 'bar',
+                                ];
+                            },
+                        ],
+                    ],
+                ],
+            ],
+        ];
+        $expected = $input;
+        $expected['processedTca']['columns']['aField']['config'] = [
+            'type' => 'radio',
+            'items' => [
+                'foo' => 'bar',
+            ],
+        ];
+        $this->assertSame($expected, $this->subject->addData($input));
+    }
+
+    /**
+     * @test
+     */
+    public function addDataItemsProcFuncReceivesParameters()
+    {
+        $input = [
+            'tableName' => 'aTable',
+            'databaseRow' => [
+                'aField' => 'aValue',
+            ],
+            'pageTsConfig' => [
+                'TCEFORM.' => [
+                    'aTable.' => [
+                        'aField.' => [
+                            'itemsProcFunc.' => [
+                                'itemParamKey' => 'itemParamValue',
+                            ],
+                        ]
+                    ],
+                ],
+            ],
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'radio',
+                            'aKey' => 'aValue',
+                            'items' => [
+                                0 => [
+                                    'foo',
+                                    'bar',
+                                ],
+                            ],
+                            'itemsProcFunc' => function (array $parameters, $pObj) {
+                                if ($parameters['items'] !== [ 0 => [ 'foo', 'bar'] ]
+                                    || $parameters['config']['aKey'] !== 'aValue'
+                                    || $parameters['TSconfig'] !== [ 'itemParamKey' => 'itemParamValue' ]
+                                    || $parameters['table'] !== 'aTable'
+                                    || $parameters['row'] !== [ 'aField' => 'aValue' ]
+                                    || $parameters['field'] !== 'aField'
+                                ) {
+                                    throw new \UnexpectedValueException('broken', 1438604329);
+                                }
+                            },
+                        ],
+                    ],
+                ],
+            ],
+        ];
+
+        $languageService = $this->prophesize(LanguageService::class);
+        $GLOBALS['LANG'] = $languageService->reveal();
+        $languageService->sL(Argument::cetera())->willReturnArgument(0);
+        /** @var FlashMessage|ObjectProphecy $flashMessage */
+        $flashMessage = $this->prophesize(FlashMessage::class);
+        GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal());
+        /** @var FlashMessageService|ObjectProphecy $flashMessageService */
+        $flashMessageService = $this->prophesize(FlashMessageService::class);
+        GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal());
+        /** @var FlashMessageQueue|ObjectProphecy $flashMessageQueue */
+        $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
+        $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
+
+        // itemsProcFunc must NOT have raised an exception
+        $flashMessageQueue->enqueue($flashMessage)->shouldNotBeCalled();
+
+        $this->subject->addData($input);
+    }
+
+    /**
+     * @test
+     */
+    public function addDataItemsProcFuncEnqueuesFlashMessageOnException()
+    {
+        $input = [
+            'tableName' => 'aTable',
+            'databaseRow' => [
+                'aField' => 'aValue',
+            ],
+            'pageTsConfig' => [
+                'TCEFORM.' => [
+                    'aTable.' => [
+                        'aField.' => [
+                            'itemsProcFunc.' => [
+                                'itemParamKey' => 'itemParamValue',
+                            ],
+                        ]
+                    ],
+                ],
+            ],
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'radio',
+                            'aKey' => 'aValue',
+                            'items' => [
+                                0 => [
+                                    'foo',
+                                    'bar',
+                                ],
+                            ],
+                            'itemsProcFunc' => function (array $parameters, $pObj) {
+                                throw new \UnexpectedValueException('anException', 1438604329);
+                            },
+                        ],
+                    ],
+                ],
+            ],
+        ];
+
+        $languageService = $this->prophesize(LanguageService::class);
+        $GLOBALS['LANG'] = $languageService->reveal();
+        /** @var FlashMessage|ObjectProphecy $flashMessage */
+        $flashMessage = $this->prophesize(FlashMessage::class);
+        GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal());
+        /** @var FlashMessageService|ObjectProphecy $flashMessageService */
+        $flashMessageService = $this->prophesize(FlashMessageService::class);
+        GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal());
+        /** @var FlashMessageQueue|ObjectProphecy $flashMessageQueue */
+        $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
+        $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
+
+        $flashMessageQueue->enqueue($flashMessage)->shouldBeCalled();
+
+        $this->subject->addData($input);
+    }
+
+    /**
+     * @test
+     */
+    public function addDataTranslatesItemLabelsFromPageTsConfig()
+    {
+        $input = [
+            'tableName' => 'aTable',
+            'processedTca' => [
+                'columns' => [
+                    'aField' => [
+                        'config' => [
+                            'type' => 'radio',
+                            'items' => [
+                                0 => [
+                                    0 => 'aLabel',
+                                    1 => 'aValue',
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+            'pageTsConfig' => [
+                'TCEFORM.' => [
+                    'aTable.' => [
+                        'aField.' => [
+                            'altLabels.' => [
+                                0 => 'labelOverride',
+                            ],
+                        ]
+                    ],
+                ],
+            ],
+        ];
+
+        /** @var LanguageService|ObjectProphecy $languageService */
+        $languageService = $this->prophesize(LanguageService::class);
+        $GLOBALS['LANG'] = $languageService->reveal();
+        $languageService->sL('aLabel')->willReturnArgument(0);
+
+        $languageService->sL('labelOverride')->shouldBeCalled()->willReturnArgument(0);
+
+        $expected = $input;
+        $expected['processedTca']['columns']['aField']['config']['items'][0][0] = 'labelOverride';
+
+        $this->assertSame($expected, $this->subject->addData($input));
+        $this->subject->addData($input);
+    }
 }