2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
17 use Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
19 use TYPO3\CMS\Core\Tests\UnitTestCase;
77 $languageService = $this->prophesize(LanguageService::class);
78 $GLOBALS[
'LANG'] = $languageService->reveal();
79 $languageService->sL(Argument::cetera())->willReturnArgument(0);
82 $this->assertSame($expected, $this->subject->addData($input));
104 $this->setExpectedException(\UnexpectedValueException::class, $this->any(), 1440499337);
105 $this->subject->addData($input);
121 'funnyKey' =>
'funnyValue',
129 $this->setExpectedException(\UnexpectedValueException::class, $this->any(), 1440499338);
130 $this->subject->addData($input);
136 public function addDataTranslatesItemLabels()
157 $languageService = $this->prophesize(LanguageService::class);
158 $GLOBALS[
'LANG'] = $languageService->reveal();
160 $languageService->sL(
'aLabel')->shouldBeCalled()->willReturn(
'translated');
163 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][0][0] =
'translated';
165 $this->assertSame($expected, $this->subject->addData($input));
166 $this->subject->addData($input);
175 'tableName' =>
'aTable',
183 'itemsProcFunc' =>
function (array $parameters, $pObj) {
184 $parameters[
'items'] = [
194 $expected[
'processedTca'][
'columns'][
'aField'][
'config'] = [
200 $this->assertSame($expected, $this->subject->addData($input));
206 public function addDataItemsProcFuncReceivesParameters()
209 'tableName' =>
'aTable',
211 'aField' =>
'aValue',
217 'itemsProcFunc.' => [
218 'itemParamKey' =>
'itemParamValue',
224 'flexParentDatabaseRow' => [
225 'aParentDatabaseRowFieldName' =>
'aParentDatabaseRowFieldValue',
239 'itemsProcFunc' =>
function (array $parameters, $pObj) {
240 if ($parameters[
'items'] !== [ 0 => [
'foo',
'bar'] ]
241 || $parameters[
'config'][
'aKey'] !==
'aValue'
242 || $parameters[
'TSconfig'] !== [
'itemParamKey' =>
'itemParamValue' ]
243 || $parameters[
'table'] !==
'aTable'
244 || $parameters[
'row'] !== [
'aField' =>
'aValue' ]
245 || $parameters[
'field'] !==
'aField'
246 || $parameters[
'flexParentDatabaseRow'][
'aParentDatabaseRowFieldName'] !==
'aParentDatabaseRowFieldValue'
248 throw new \UnexpectedValueException(
'broken', 1438604329);
257 $languageService = $this->prophesize(LanguageService::class);
258 $GLOBALS[
'LANG'] = $languageService->reveal();
259 $languageService->sL(Argument::cetera())->willReturnArgument(0);
261 $flashMessage = $this->prophesize(FlashMessage::class);
264 $flashMessageService = $this->prophesize(FlashMessageService::class);
267 $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
268 $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
271 $flashMessageQueue->enqueue($flashMessage)->shouldNotBeCalled();
273 $this->subject->addData($input);
279 public function addDataItemsProcFuncEnqueuesFlashMessageOnException()
282 'tableName' =>
'aTable',
284 'aField' =>
'aValue',
290 'itemsProcFunc.' => [
291 'itemParamKey' =>
'itemParamValue',
309 'itemsProcFunc' =>
function (array $parameters, $pObj) {
310 throw new \UnexpectedValueException(
'anException', 1438604329);
318 $languageService = $this->prophesize(LanguageService::class);
319 $GLOBALS[
'LANG'] = $languageService->reveal();
321 $flashMessage = $this->prophesize(FlashMessage::class);
324 $flashMessageService = $this->prophesize(FlashMessageService::class);
327 $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
328 $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
330 $flashMessageQueue->enqueue($flashMessage)->shouldBeCalled();
332 $this->subject->addData($input);
338 public function addDataTranslatesItemLabelsFromPageTsConfig()
341 'tableName' =>
'aTable',
362 0 =>
'labelOverride',
371 $languageService = $this->prophesize(LanguageService::class);
372 $GLOBALS[
'LANG'] = $languageService->reveal();
373 $languageService->sL(
'aLabel')->willReturnArgument(0);
375 $languageService->sL(
'labelOverride')->shouldBeCalled()->willReturnArgument(0);
378 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][0][0] =
'labelOverride';
380 $this->assertSame($expected, $this->subject->addData($input));
381 $this->subject->addData($input);