2 declare(strict_types = 1);
18 use Doctrine\DBAL\Driver\Statement;
19 use Prophecy\Argument;
52 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
71 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
72 $cacheProphecy = $this->prophesize(FrontendInterface::class);
73 $cacheManagerProphecy->getCache(
'cache_runtime')->willReturn($cacheProphecy->reveal());
74 $cacheProphecy->get(Argument::cetera())->willReturn(
false);
75 $cacheProphecy->set(Argument::cetera())->willReturn(
false);
76 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
84 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
85 DataStructureIdentifierPreProcessHookThrowException::class,
87 $this->expectException(\RuntimeException::class);
88 $this->expectExceptionCode(1478098527);
89 (
new FlexFormTools())->getDataStructureIdentifier([],
'aTableName',
'aFieldName', []);
97 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
98 DataStructureIdentifierPreProcessHookReturnString::class
100 $this->expectException(\RuntimeException::class);
101 $this->expectExceptionCode(1478096535);
102 (
new FlexFormTools())->getDataStructureIdentifier([],
'aTableName',
'aFieldName', []);
113 'default' =>
'<T3DataStructure>...'
117 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
118 DataStructureIdentifierPreProcessHookReturnEmptyArray::class
120 $expected =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
121 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', []));
129 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
130 DataStructureIdentifierPreProcessHookReturnArray::class
132 $expected =
'{"type":"myExtension","further":"data"}';
133 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier([],
'aTableName',
'aFieldName', []));
141 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
142 DataStructureIdentifierPreProcessHookReturnEmptyArray::class,
143 DataStructureIdentifierPreProcessHookReturnArray::class,
144 DataStructureIdentifierPreProcessHookThrowException::class
146 $expected =
'{"type":"myExtension","further":"data"}';
147 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier([],
'aTableName',
'aFieldName', []));
158 'default' =>
'<T3DataStructure>...'
162 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
163 DataStructureIdentifierPostProcessHookThrowException::class,
165 $this->expectException(\RuntimeException::class);
166 $this->expectExceptionCode(1478342067);
167 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', []);
178 'default' =>
'<T3DataStructure>...'
182 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
183 DataStructureIdentifierPostProcessHookReturnString::class
185 $this->expectException(\RuntimeException::class);
186 $this->expectExceptionCode(1478350835);
187 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', []);
198 'default' =>
'<T3DataStructure>...'
202 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
203 DataStructureIdentifierPostProcessHookReturnEmptyArray::class
205 $this->expectException(\RuntimeException::class);
206 $this->expectExceptionCode(1478350835);
207 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', []);
218 'default' =>
'<T3DataStructure>...'
222 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
223 DataStructureIdentifierPostProcessHookReturnArray::class
225 $expected =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default","myExtensionData":"foo"}';
226 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', []));
236 'ds' =>
'someStringOnly',
240 $this->expectException(\RuntimeException::class);
241 $this->expectExceptionCode(1463826960);
242 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', []);
253 'default' =>
'<T3DataStructure>...'
257 $expected =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
258 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', []));
271 $this->expectException(InvalidTcaException::class);
272 $this->expectExceptionCode(1463652560);
273 $this->assertSame(
'default', (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', []));
284 'ds_pointerField' =>
'first,second,third',
287 $this->expectException(\RuntimeException::class);
288 $this->expectExceptionCode(1463577497);
289 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', []);
300 'ds_pointerField' =>
'notExist',
306 $this->expectException(\RuntimeException::class);
307 $this->expectExceptionCode(1463578899);
308 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row);
319 'ds_pointerField' =>
'notExist,second',
325 $this->expectException(\RuntimeException::class);
326 $this->expectExceptionCode(1463578899);
327 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row);
338 'ds_pointerField' =>
'first,notExist',
344 $this->expectException(\RuntimeException::class);
345 $this->expectExceptionCode(1463578900);
346 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row);
357 'thePointerValue' =>
'FILE:...'
359 'ds_pointerField' =>
'aField'
363 'aField' =>
'thePointerValue',
365 $expected =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"thePointerValue"}';
366 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row));
377 'default' =>
'theDataStructure'
379 'ds_pointerField' =>
'aField'
383 'aField' =>
'thePointerValue',
385 $expected =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
386 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row));
397 'aDifferentDataStructure' =>
'aDataStructure'
399 'ds_pointerField' =>
'aField'
404 'aField' =>
'aNotDefinedDataStructure',
406 $this->expectException(InvalidSinglePointerFieldException::class);
407 $this->expectExceptionCode(1463653197);
408 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row);
417 'direct match of two fields' => [
420 'firstField' =>
'firstValue',
421 'secondField' =>
'secondValue',
425 'firstValue,secondValue' =>
'',
428 '{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"firstValue,secondValue"}'
430 'match on first field, * for second' => [
432 'firstField' =>
'firstValue',
433 'secondField' =>
'secondValue',
436 'firstValue,*' =>
'',
438 '{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"firstValue,*"}'
440 'match on second field, * for first' => [
442 'firstField' =>
'firstValue',
443 'secondField' =>
'secondValue',
446 '*,secondValue' =>
'',
448 '{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"*,secondValue"}'
450 'match on first field only' => [
452 'firstField' =>
'firstValue',
453 'secondField' =>
'secondValue',
458 '{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"firstValue"}'
460 'fallback to default' => [
462 'firstField' =>
'firstValue',
463 'secondField' =>
'secondValue',
468 '{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}'
470 'chain falls through with no match on second value to *' => [
472 'firstField' =>
'firstValue',
473 'secondField' =>
'noMatch',
476 'firstValue,secondValue' =>
'',
477 'firstValue,*' =>
'',
479 '{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"firstValue,*"}'
481 'chain falls through with no match on first value to *' => [
483 'firstField' =>
'noMatch',
484 'secondField' =>
'secondValue',
487 'firstValue,secondValue' =>
'',
488 '*,secondValue' =>
'',
490 '{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"*,secondValue"}'
492 'chain falls through with no match on any field to default' => [
494 'firstField' =>
'noMatch',
495 'secondField' =>
'noMatchToo',
498 'firstValue,secondValue' =>
'',
499 'secondValue,*' =>
'',
502 '{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}'
519 'ds_pointerField' =>
'firstField,secondField'
522 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row));
533 'firstValue,secondValue' =>
'',
535 'ds_pointerField' =>
'firstField,secondField'
540 'firstField' =>
'noMatch',
541 'secondField' =>
'noMatchToo',
543 $this->expectException(InvalidCombinedPointerFieldException::class);
544 $this->expectExceptionCode(1463678524);
545 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row);
555 'ds_pointerField' =>
'tx_templavoila_ds',
556 'ds_pointerField_searchParent' =>
'pid',
562 'tx_templavoila_ds' =>
null,
566 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
567 $queryBuilderRevelation = $queryBuilderProphecy->reveal();
568 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
569 $queryRestrictionContainerProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
570 $queryRestrictionContainerRevelation = $queryRestrictionContainerProphecy->reveal();
571 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
572 $statementProphecy = $this->prophesize(Statement::class);
575 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
578 $connectionPoolProphecy->getQueryBuilderForTable(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
579 $queryRestrictionContainerProphecy->removeAll()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
580 $queryRestrictionContainerProphecy->add(Argument::cetera())->shouldBeCalled();
581 $queryBuilderProphecy->getRestrictions()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
582 $queryBuilderProphecy->select(
'uid',
'pid',
'tx_templavoila_ds')->shouldBeCalled();
583 $queryBuilderProphecy->from(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
584 $queryBuilderProphecy->expr()->shouldBeCalled()->willReturn($expressionBuilderProphecy->reveal());
585 $queryBuilderProphecy->createNamedParameter(42, 1)->willReturn(42);
586 $expressionBuilderProphecy->eq(
'uid', 42)->shouldBeCalled()->willReturn(
'uid = 42');
587 $queryBuilderProphecy->where(
'uid = 42')->shouldBeCalled()->willReturn($queryBuilderRevelation);
588 $queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
591 $queryBuilderProphecy->count(
'uid')->shouldBeCalled()->willReturn($queryBuilderProphecy);
592 $this->expectException(InvalidParentRowException::class);
593 $this->expectExceptionCode(1463833794);
594 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row);
606 'ds_pointerField' =>
'tx_templavoila_ds',
607 'ds_pointerField_searchParent' =>
'pid',
613 'tx_templavoila_ds' =>
null,
618 'tx_templavoila_ds' =>
null,
623 'tx_templavoila_ds' =>
null,
627 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
628 $queryBuilderRevelation = $queryBuilderProphecy->reveal();
629 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
630 $queryRestrictionContainerProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
631 $queryRestrictionContainerRevelation = $queryRestrictionContainerProphecy->reveal();
632 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
633 $statementProphecy = $this->prophesize(Statement::class);
637 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
638 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
641 $connectionPoolProphecy->getQueryBuilderForTable(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
642 $queryRestrictionContainerProphecy->removeAll()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
643 $queryRestrictionContainerProphecy->add(Argument::cetera())->shouldBeCalled();
644 $queryBuilderProphecy->getRestrictions()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
645 $queryBuilderProphecy->select(
'uid',
'pid',
'tx_templavoila_ds')->shouldBeCalled();
646 $queryBuilderProphecy->from(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
647 $queryBuilderProphecy->expr()->shouldBeCalled()->willReturn($expressionBuilderProphecy->reveal());
648 $queryBuilderProphecy->createNamedParameter(2, 1)->willReturn(2);
649 $queryBuilderProphecy->createNamedParameter(1, 1)->willReturn(1);
650 $expressionBuilderProphecy->eq(
'uid', 2)->shouldBeCalled()->willReturn(
'uid = 2');
651 $expressionBuilderProphecy->eq(
'uid', 1)->shouldBeCalled()->willReturn(
'uid = 1');
652 $queryBuilderProphecy->where(
'uid = 2')->shouldBeCalled()->willReturn($queryBuilderRevelation);
653 $queryBuilderProphecy->where(
'uid = 1')->shouldBeCalled()->willReturn($queryBuilderRevelation);
654 $queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
655 $queryBuilderProphecy->count(
'uid')->shouldBeCalled()->willReturn($queryBuilderProphecy);
658 $statementProphecy->fetchColumn(0)->willReturn(1);
659 $statementProphecy->fetch()->willReturn($secondRow, $thirdRow);
661 $this->expectException(InvalidParentRowLoopException::class);
662 $this->expectExceptionCode(1464110956);
663 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $initialRow);
675 'ds_pointerField' =>
'tx_templavoila_ds',
676 'ds_pointerField_searchParent' =>
'pid',
682 'tx_templavoila_ds' =>
null,
687 'tx_templavoila_ds' =>
null,
692 'tx_templavoila_ds' =>
null,
696 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
697 $queryBuilderRevelation = $queryBuilderProphecy->reveal();
698 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
699 $queryRestrictionContainerProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
700 $queryRestrictionContainerRevelation = $queryRestrictionContainerProphecy->reveal();
701 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
702 $statementProphecy = $this->prophesize(Statement::class);
706 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
707 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
710 $connectionPoolProphecy->getQueryBuilderForTable(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
711 $queryRestrictionContainerProphecy->removeAll()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
712 $queryRestrictionContainerProphecy->add(Argument::cetera())->shouldBeCalled();
713 $queryBuilderProphecy->getRestrictions()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
714 $queryBuilderProphecy->select(
'uid',
'pid',
'tx_templavoila_ds')->shouldBeCalled();
715 $queryBuilderProphecy->from(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
716 $queryBuilderProphecy->expr()->shouldBeCalled()->willReturn($expressionBuilderProphecy->reveal());
717 $queryBuilderProphecy->createNamedParameter(2, 1)->willReturn(2);
718 $queryBuilderProphecy->createNamedParameter(1, 1)->willReturn(1);
719 $expressionBuilderProphecy->eq(
'uid', 2)->shouldBeCalled()->willReturn(
'uid = 2');
720 $expressionBuilderProphecy->eq(
'uid', 1)->shouldBeCalled()->willReturn(
'uid = 1');
721 $queryBuilderProphecy->where(
'uid = 2')->shouldBeCalled()->willReturn($queryBuilderRevelation);
722 $queryBuilderProphecy->where(
'uid = 1')->shouldBeCalled()->willReturn($queryBuilderRevelation);
723 $queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
724 $queryBuilderProphecy->count(
'uid')->shouldBeCalled()->willReturn($queryBuilderRevelation);
725 $statementProphecy->fetchColumn(0)->shouldBeCalled()->willReturn(1);
728 $statementProphecy->fetch()->willReturn($secondRow, $thirdRow);
730 $this->expectException(InvalidParentRowRootException::class);
731 $this->expectExceptionCode(1464112555);
732 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $initialRow);
742 'ds_pointerField' =>
'aPointerField',
746 'aPointerField' =>
null,
748 $this->expectException(InvalidPointerFieldValueException::class);
749 $this->expectExceptionCode(1464114011);
750 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row);
760 'ds_pointerField' =>
'aPointerField',
764 'aPointerField' => 3,
766 $this->expectException(InvalidTcaException::class);
767 $this->expectExceptionCode(1464115639);
768 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row);
778 'ds_pointerField' =>
'aPointerField',
779 'ds_tableField' =>
'misconfigured',
783 'aPointerField' => 3,
785 $this->expectException(InvalidTcaException::class);
786 $this->expectExceptionCode(1464116002);
787 (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row);
797 'ds_pointerField' =>
'aPointerField',
802 'aPointerField' =>
'<T3DataStructure>...',
804 $expected =
'{"type":"record","tableName":"aTableName","uid":42,"fieldName":"aPointerField"}';
805 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row));
817 'ds_pointerField' =>
'tx_templavoila_ds',
818 'ds_pointerField_searchParent' =>
'pid',
824 'tx_templavoila_ds' =>
null,
829 'tx_templavoila_ds' => 0,
834 'tx_templavoila_ds' =>
'<T3DataStructure>...',
838 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
839 $queryBuilderRevelation = $queryBuilderProphecy->reveal();
840 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
841 $queryRestrictionContainerProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
842 $queryRestrictionContainerRevelation = $queryRestrictionContainerProphecy->reveal();
843 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
844 $statementProphecy = $this->prophesize(Statement::class);
848 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
849 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
852 $connectionPoolProphecy->getQueryBuilderForTable(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
853 $queryRestrictionContainerProphecy->removeAll()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
854 $queryRestrictionContainerProphecy->add(Argument::cetera())->shouldBeCalled();
855 $queryBuilderProphecy->getRestrictions()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
856 $queryBuilderProphecy->select(
'uid',
'pid',
'tx_templavoila_ds')->shouldBeCalled();
857 $queryBuilderProphecy->from(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
858 $queryBuilderProphecy->expr()->shouldBeCalled()->willReturn($expressionBuilderProphecy->reveal());
859 $queryBuilderProphecy->createNamedParameter(2, 1)->willReturn(2);
860 $queryBuilderProphecy->createNamedParameter(1, 1)->willReturn(1);
861 $expressionBuilderProphecy->eq(
'uid', 2)->shouldBeCalled()->willReturn(
'uid = 2');
862 $expressionBuilderProphecy->eq(
'uid', 1)->shouldBeCalled()->willReturn(
'uid = 1');
863 $queryBuilderProphecy->where(
'uid = 2')->shouldBeCalled()->willReturn($queryBuilderRevelation);
864 $queryBuilderProphecy->where(
'uid = 1')->shouldBeCalled()->willReturn($queryBuilderRevelation);
865 $queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
866 $queryBuilderProphecy->count(
'uid')->shouldBeCalled()->willReturn($queryBuilderRevelation);
867 $statementProphecy->fetchColumn(0)->shouldBeCalled()->willReturn(1);
870 $statementProphecy->fetch()->willReturn($secondRow, $thirdRow);
872 $expected =
'{"type":"record","tableName":"aTableName","uid":1,"fieldName":"tx_templavoila_ds"}';
873 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $initialRow));
885 'ds_pointerField' =>
'tx_templavoila_ds',
886 'ds_pointerField_searchParent' =>
'pid',
892 'tx_templavoila_ds' =>
null,
897 'tx_templavoila_ds' =>
'<T3DataStructure>...',
901 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
902 $queryBuilderRevelation = $queryBuilderProphecy->reveal();
903 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
904 $queryRestrictionContainerProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
905 $queryRestrictionContainerRevelation = $queryRestrictionContainerProphecy->reveal();
906 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
907 $statementProphecy = $this->prophesize(Statement::class);
911 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
914 $connectionPoolProphecy->getQueryBuilderForTable(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
915 $queryRestrictionContainerProphecy->removeAll()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
916 $queryRestrictionContainerProphecy->add(Argument::cetera())->shouldBeCalled();
917 $queryBuilderProphecy->getRestrictions()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
918 $queryBuilderProphecy->select(
'uid',
'pid',
'tx_templavoila_ds')->shouldBeCalled();
919 $queryBuilderProphecy->from(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
920 $queryBuilderProphecy->expr()->shouldBeCalled()->willReturn($expressionBuilderProphecy->reveal());
921 $queryBuilderProphecy->createNamedParameter(2, 1)->willReturn(2);
922 $expressionBuilderProphecy->eq(
'uid', 2)->shouldBeCalled()->willReturn(
'uid = 2');
923 $queryBuilderProphecy->where(
'uid = 2')->shouldBeCalled()->willReturn($queryBuilderRevelation);
924 $queryBuilderProphecy->count(
'uid')->shouldBeCalled()->willReturn($queryBuilderRevelation);
925 $queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
926 $statementProphecy->fetchColumn(0)->shouldBeCalled()->willReturn(1);
929 $statementProphecy->fetch()->willReturn($secondRow);
931 $expected =
'{"type":"record","tableName":"aTableName","uid":2,"fieldName":"tx_templavoila_ds"}';
932 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $initialRow));
944 'ds_pointerField' =>
'tx_templavoila_ds',
945 'ds_pointerField_searchParent' =>
'pid',
946 'ds_pointerField_searchParent_subField' =>
'tx_templavoila_next_ds',
952 'tx_templavoila_ds' =>
null,
953 'tx_templavoila_next_ds' =>
null,
958 'tx_templavoila_ds' =>
'<T3DataStructure>...',
959 'tx_templavoila_next_ds' =>
'anotherDataStructure',
963 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
964 $queryBuilderRevelation = $queryBuilderProphecy->reveal();
965 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
966 $queryRestrictionContainerProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
967 $queryRestrictionContainerRevelation = $queryRestrictionContainerProphecy->reveal();
968 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
969 $statementProphecy = $this->prophesize(Statement::class);
973 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
976 $connectionPoolProphecy->getQueryBuilderForTable(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
977 $queryRestrictionContainerProphecy->removeAll()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
978 $queryRestrictionContainerProphecy->add(Argument::cetera())->shouldBeCalled();
979 $queryBuilderProphecy->getRestrictions()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
980 $queryBuilderProphecy->select(
'uid',
'pid',
'tx_templavoila_ds')->shouldBeCalled();
981 $queryBuilderProphecy->addSelect(
'tx_templavoila_next_ds')->shouldBeCalled();
982 $queryBuilderProphecy->from(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
983 $queryBuilderProphecy->expr()->shouldBeCalled()->willReturn($expressionBuilderProphecy->reveal());
984 $queryBuilderProphecy->createNamedParameter(2, 1)->willReturn(2);
985 $expressionBuilderProphecy->eq(
'uid', 2)->shouldBeCalled()->willReturn(
'uid = 2');
986 $queryBuilderProphecy->where(
'uid = 2')->shouldBeCalled()->willReturn($queryBuilderRevelation);
987 $queryBuilderProphecy->count(
'uid')->shouldBeCalled()->willReturn($queryBuilderRevelation);
988 $queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
989 $statementProphecy->fetchColumn(0)->shouldBeCalled()->willReturn(1);
992 $statementProphecy->fetch()->willReturn($secondRow);
994 $expected =
'{"type":"record","tableName":"aTableName","uid":2,"fieldName":"tx_templavoila_next_ds"}';
995 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $initialRow));
1005 'ds_pointerField' =>
'aPointerField',
1006 'ds_tableField' =>
'foreignTableName:foreignTableField',
1012 'aPointerField' => 42,
1014 $expected =
'{"type":"record","tableName":"foreignTableName","uid":42,"fieldName":"foreignTableField"}';
1015 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $row));
1027 'ds_pointerField' =>
'tx_templavoila_ds',
1028 'ds_pointerField_searchParent' =>
'pid',
1029 'ds_pointerField_searchParent_subField' =>
'tx_templavoila_next_ds',
1030 'ds_tableField' =>
'foreignTableName:foreignTableField',
1036 'tx_templavoila_ds' =>
null,
1037 'tx_templavoila_next_ds' =>
null,
1042 'tx_templavoila_ds' =>
'<T3DataStructure>...',
1043 'tx_templavoila_next_ds' =>
'42',
1047 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
1048 $queryBuilderRevelation = $queryBuilderProphecy->reveal();
1049 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
1050 $queryRestrictionContainerProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
1051 $queryRestrictionContainerRevelation = $queryRestrictionContainerProphecy->reveal();
1052 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
1053 $statementProphecy = $this->prophesize(Statement::class);
1057 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
1060 $connectionPoolProphecy->getQueryBuilderForTable(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
1061 $queryRestrictionContainerProphecy->removeAll()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
1062 $queryRestrictionContainerProphecy->add(Argument::cetera())->shouldBeCalled();
1063 $queryBuilderProphecy->getRestrictions()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
1064 $queryBuilderProphecy->select(
'uid',
'pid',
'tx_templavoila_ds')->shouldBeCalled();
1065 $queryBuilderProphecy->addSelect(
'tx_templavoila_next_ds')->shouldBeCalled();
1066 $queryBuilderProphecy->from(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
1067 $queryBuilderProphecy->expr()->shouldBeCalled()->willReturn($expressionBuilderProphecy->reveal());
1068 $queryBuilderProphecy->createNamedParameter(2, 1)->willReturn(2);
1069 $expressionBuilderProphecy->eq(
'uid', 2)->shouldBeCalled()->willReturn(
'uid = 2');
1070 $queryBuilderProphecy->where(
'uid = 2')->shouldBeCalled()->willReturn($queryBuilderRevelation);
1071 $queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
1072 $queryBuilderProphecy->count(
'uid')->shouldBeCalled()->willReturn($queryBuilderRevelation);
1073 $statementProphecy->fetchColumn(0)->shouldBeCalled()->willReturn(1);
1076 $statementProphecy->fetch()->willReturn($secondRow);
1078 $expected =
'{"type":"record","tableName":"foreignTableName","uid":42,"fieldName":"foreignTableField"}';
1079 $this->assertSame($expected, (
new FlexFormTools())->getDataStructureIdentifier($fieldTca,
'aTableName',
'aFieldName', $initialRow));
1087 $this->expectException(InvalidIdentifierException::class);
1088 $this->expectExceptionCode(1478100828);
1097 $this->expectException(\RuntimeException::class);
1098 $this->expectExceptionCode(1478345642);
1107 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
1108 DataStructureParsePreProcessHookThrowException::class,
1110 $this->expectException(\RuntimeException::class);
1111 $this->expectExceptionCode(1478112411);
1112 (
new FlexFormTools())->parseDataStructureByIdentifier(
'{"some":"input"}');
1120 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
1121 DataStructureParsePreProcessHookReturnObject::class
1123 $this->expectException(\RuntimeException::class);
1124 $this->expectExceptionCode(1478168512);
1125 (
new FlexFormTools())->parseDataStructureByIdentifier(
'{"some":"input"}');
1133 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
1134 DataStructureParsePreProcessHookReturnEmptyString::class
1136 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default'] =
'
1141 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1145 $this->assertSame($expected, (
new FlexFormTools())->parseDataStructureByIdentifier($identifier));
1153 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
1154 DataStructureParsePreProcessHookReturnString::class
1156 $identifier =
'{"type":"myExtension"}';
1160 $this->assertSame($expected, (
new FlexFormTools())->parseDataStructureByIdentifier($identifier));
1168 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
1169 DataStructureParsePreProcessHookReturnEmptyString::class,
1170 DataStructureParsePreProcessHookReturnString::class,
1171 DataStructureParsePreProcessHookThrowException::class
1173 $identifier =
'{"type":"myExtension"}';
1177 $this->assertSame($expected, (
new FlexFormTools())->parseDataStructureByIdentifier($identifier));
1185 $this->expectException(InvalidIdentifierException::class);
1186 $this->expectExceptionCode(1478104554);
1187 (
new FlexFormTools())->parseDataStructureByIdentifier(
'{"type":"bernd"}');
1195 $this->expectException(\RuntimeException::class);
1196 $this->expectExceptionCode(1478113471);
1197 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName"}';
1198 (
new FlexFormTools())->parseDataStructureByIdentifier($identifier);
1206 $this->expectException(InvalidIdentifierException::class);
1207 $this->expectExceptionCode(1478105491);
1208 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1209 (
new FlexFormTools())->parseDataStructureByIdentifier($identifier);
1217 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default'] =
'
1222 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1226 $this->assertSame($expected, (
new FlexFormTools())->parseDataStructureByIdentifier($identifier));
1234 $this->expectException(\RuntimeException::class);
1235 $this->expectExceptionCode(1478113873);
1236 $identifier =
'{"type":"record","tableName":"foreignTableName","uid":42}';
1237 (
new FlexFormTools())->parseDataStructureByIdentifier($identifier);
1246 $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
1247 $queryBuilderRevelation = $queryBuilderProphecy->reveal();
1248 $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
1249 $queryRestrictionContainerProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
1250 $queryRestrictionContainerRevelation = $queryRestrictionContainerProphecy->reveal();
1251 $expressionBuilderProphecy = $this->prophesize(ExpressionBuilder::class);
1252 $statementProphecy = $this->prophesize(Statement::class);
1255 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
1258 $connectionPoolProphecy->getQueryBuilderForTable(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
1259 $queryRestrictionContainerProphecy->removeAll()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
1260 $queryRestrictionContainerProphecy->add(Argument::cetera())->shouldBeCalled();
1261 $queryBuilderProphecy->getRestrictions()->shouldBeCalled()->willReturn($queryRestrictionContainerRevelation);
1262 $queryBuilderProphecy->select(
'dataprot')->shouldBeCalled()->willReturn($queryBuilderRevelation);
1263 $queryBuilderProphecy->from(
'aTableName')->shouldBeCalled()->willReturn($queryBuilderRevelation);
1264 $queryBuilderProphecy->expr()->shouldBeCalled()->willReturn($expressionBuilderProphecy->reveal());
1265 $queryBuilderProphecy->createNamedParameter(42, 1)->willReturn(42);
1266 $expressionBuilderProphecy->eq(
'uid', 42)->shouldBeCalled()->willReturn(
'uid = 42');
1267 $queryBuilderProphecy->where(
'uid = 42')->shouldBeCalled()->willReturn($queryBuilderRevelation);
1268 $queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
1269 $statementProphecy->fetchColumn(0)->willReturn(
'
1274 $identifier =
'{"type":"record","tableName":"aTableName","uid":42,"fieldName":"dataprot"}';
1278 $this->assertSame($expected, (
new FlexFormTools())->parseDataStructureByIdentifier($identifier));
1286 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default']
1287 =
'FILE:EXT:core/Does/Not/Exist.xml';
1288 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1289 $this->expectException(\RuntimeException::class);
1290 $this->expectExceptionCode(1478105826);
1291 (
new FlexFormTools())->parseDataStructureByIdentifier($identifier);
1299 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default']
1300 =
' FILE:EXT:core/Tests/Unit/Configuration/FlexForm/Fixtures/DataStructureWithSheet.xml ';
1301 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1310 'label' =>
'aFlexFieldLabel',
1318 'sheetTitle' =>
'aTitle',
1324 $this->assertEquals($expected, (
new FlexFormTools())->parseDataStructureByIdentifier($identifier));
1332 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default'] =
'
1339 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1340 $this->expectException(InvalidIdentifierException::class);
1341 $this->expectExceptionCode(1478106090);
1342 (
new FlexFormTools())->parseDataStructureByIdentifier($identifier);
1350 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default'] =
'
1356 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1357 $this->expectException(\RuntimeException::class);
1358 $this->expectExceptionCode(1440676540);
1359 (
new FlexFormTools())->parseDataStructureByIdentifier($identifier);
1367 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default'] =
'
1371 <sheetTitle>aTitle</sheetTitle>
1377 <label>aFlexFieldLabel</label>
1387 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1396 'label' =>
'aFlexFieldLabel',
1404 'sheetTitle' =>
'aTitle',
1410 $this->assertEquals($expected, (
new FlexFormTools())->parseDataStructureByIdentifier($identifier));
1418 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default'] =
'
1422 EXT:core/Tests/Unit/Configuration/FlexForm/Fixtures/DataStructureOfSingleSheet.xml
1427 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1436 'label' =>
'aFlexFieldLabel',
1444 'sheetTitle' =>
'aTitle',
1450 $this->assertEquals($expected, (
new FlexFormTools())->parseDataStructureByIdentifier($identifier));
1458 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default'] =
'
1462 FILE:EXT:core/Tests/Unit/Configuration/FlexForm/Fixtures/DataStructureOfSingleSheet.xml
1467 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1476 'label' =>
'aFlexFieldLabel',
1484 'sheetTitle' =>
'aTitle',
1490 $this->assertEquals($expected, (
new FlexFormTools())->parseDataStructureByIdentifier($identifier));
1498 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default'] =
'
1503 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1504 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
1505 DataStructureParsePostProcessHookThrowException::class,
1507 $this->expectException(\RuntimeException::class);
1508 $this->expectExceptionCode(1478351691);
1509 (
new FlexFormTools())->parseDataStructureByIdentifier($identifier);
1517 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default'] =
'
1522 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1523 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
1524 DataStructureParsePostProcessHookReturnString::class,
1526 $this->expectException(\RuntimeException::class);
1527 $this->expectExceptionCode(1478350806);
1528 (
new FlexFormTools())->parseDataStructureByIdentifier($identifier);
1536 $GLOBALS[
'TCA'][
'aTableName'][
'columns'][
'aFieldName'][
'config'][
'ds'][
'default'] =
'
1541 $identifier =
'{"type":"tca","tableName":"aTableName","fieldName":"aFieldName","dataStructureKey":"default"}';
1542 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][FlexFormTools::class][
'flexParsing'] = [
1543 DataStructureParsePostProcessHookReturnArray::class,
1550 $this->assertSame($expected, (
new FlexFormTools())->parseDataStructureByIdentifier($identifier));
1567 'callBackMethod_value' =>
'dummy',
1571 $subject = $this->getMockBuilder(FlexFormTools::class)
1572 ->setMethods([
'executeCallBackMethod'])
1574 $subject->expects($this->never())->method(
'executeCallBackMethod');
1575 $subject->traverseFlexFormXMLData_recurse($dataStruct, $editData, $pA);
1586 'el' =>
'field_not_in_data',
1591 'callBackMethod_value' =>
'dummy',
1600 $subject = $this->createMock(FlexFormTools::class);
1601 $this->assertEquals(
1602 $subject->traverseFlexFormXMLData_recurse($dataStruct, $editData, $pA),
1603 $subject->traverseFlexFormXMLData_recurse($dataStruct, $editData2, $pA)