17 use Doctrine\DBAL\DBALException;
18 use Doctrine\DBAL\Driver\Statement;
19 use Prophecy\Argument;
20 use Prophecy\Prophecy\ObjectProphecy;
43 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
56 $languageServiceProphecy = $this->prophesize(LanguageService::class);
57 $languageServiceProphecy->loadSingleTableDescription(Argument::cetera())->willReturn(
null);
58 $languageServiceProphecy->sL(Argument::cetera())->willReturnArgument(0);
59 $GLOBALS[
'LANG'] = $languageServiceProphecy->reveal();
61 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
62 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
64 $cacheManagerProphecy = $this->prophesize(CacheManager::class);
65 $cacheProphecy = $this->prophesize(FrontendInterface::class);
66 $cacheManagerProphecy->getCache(
'cache_runtime')->willReturn($cacheProphecy->reveal());
67 $cacheManagerProphecy->getCache(
'assets')->willReturn($cacheProphecy->reveal());
68 $cacheProphecy->get(Argument::cetera())->willReturn(
false);
69 $cacheProphecy->set(Argument::cetera())->willReturn(
false);
70 GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
78 GeneralUtility::purgeInstances();
91 $connectionProphet = $this->prophesize(Connection::class);
92 $connectionProphet->quote(Argument::cetera())->will(
function ($arguments) {
93 return "'" . $arguments[0] .
"'";
95 $connectionProphet->quoteIdentifier(Argument::cetera())->will(
function ($arguments) {
96 return '`' . $arguments[0] .
'`';
99 $restrictionProphet = $this->prophesize(DefaultRestrictionContainer::class);
100 $restrictionProphet->removeAll()->willReturn($restrictionProphet->reveal());
101 $restrictionProphet->add(Argument::cetera())->willReturn($restrictionProphet->reveal());
103 $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
104 $queryBuilderProphet->expr()->willReturn(
105 GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
107 $queryBuilderProphet->getRestrictions()->willReturn($restrictionProphet->reveal());
108 $queryBuilderProphet->quoteIdentifier(Argument::cetera())->will(
function ($arguments) {
109 return '`' . $arguments[0] .
'`';
112 $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
113 $connectionPoolProphet->getConnectionForTable($tableName)
114 ->willReturn($connectionProphet->reveal());
115 $connectionPoolProphet->getQueryBuilderForTable($tableName)
117 ->willReturn($queryBuilderProphet->reveal());
119 return [$queryBuilderProphet, $connectionPoolProphet, $connectionProphet, $restrictionProphet];
131 $statementProphet = $this->prophesize(Statement::class);
132 $statementProphet->fetch()->shouldBeCalled();
134 $queryBuilderProphet->select(
'foreignTable.uid')
136 ->willReturn($queryBuilderProphet->reveal());
137 $queryBuilderProphet->from(
'foreignTable')
139 ->willReturn($queryBuilderProphet->reveal());
140 $queryBuilderProphet->from(
'pages')
142 ->willReturn($queryBuilderProphet->reveal());
143 $queryBuilderProphet->where(
'')
145 ->willReturn($queryBuilderProphet->reveal());
146 $queryBuilderProphet->andWhere(
' 1=1')
148 ->willReturn($queryBuilderProphet->reveal());
149 $queryBuilderProphet->andWhere(
'`pages.uid` = `foreignTable.pid`')
151 ->willReturn($queryBuilderProphet->reveal());
152 $queryBuilderProphet->execute()
154 ->willReturn($statementProphet->reveal());
157 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
158 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
167 'tableName' =>
'aTable',
206 'tableName' =>
'aTable',
212 'renderType' =>
'selectSingle',
222 $this->expectException(\UnexpectedValueException::class);
223 $this->expectExceptionCode(1439288036);
234 'tableName' =>
'aTable',
236 'aField' =>
'aValue',
243 'renderType' =>
'selectSingle',
258 $languageService = $this->prophesize(LanguageService::class);
259 $GLOBALS[
'LANG'] = $languageService->reveal();
260 $languageService->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue')->willReturn(
'INVALID VALUE "%s"');
262 $languageService->sL(
'aLabel')->shouldBeCalled()->willReturn(
'translated');
265 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][0][0] =
'translated';
266 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][0][2] =
null;
267 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][0][3] =
null;
269 $expected[
'databaseRow'][
'aField'] = [
'aValue'];
280 'tableName' =>
'aTable',
282 'aField' =>
'aValue',
289 'renderType' =>
'selectSingle',
294 2 =>
'an-icon-reference',
306 $expected[
'databaseRow'][
'aField'] = [
'aValue'];
317 'tableName' =>
'aTable',
323 'renderType' =>
'selectSingle',
324 'special' =>
'anUnknownValue',
331 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
332 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
334 $this->expectException(\UnexpectedValueException::class);
335 $this->expectExceptionCode(1439298496);
349 'tableName' =>
'aTable',
355 'renderType' =>
'selectSingle',
356 'special' =>
'tables',
375 $GLOBALS[
'TCA_DESCR'][
'aTable'][
'columns'][
''][
'description'] =
'aDescription';
377 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
378 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
381 $languageService = $this->prophesize(LanguageService::class);
382 $GLOBALS[
'LANG'] = $languageService->reveal();
383 $languageService->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue')->willReturn(
'INVALID VALUE "%s"');
384 $languageService->sL(Argument::containingString(
'INVALID VALUE'))->willReturnArgument(0);
386 $languageService->sL(
'aTitle')->shouldBeCalled()->willReturnArgument(0);
387 $languageService->loadSingleTableDescription(
'aTable')->shouldBeCalled();
390 $expected[
'databaseRow'][
'aField'] = [];
391 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = [
397 'description' =>
'aDescription',
412 'aField' =>
'aValue',
414 'tableName' =>
'aTable',
420 'renderType' =>
'selectSingle',
421 'special' =>
'pagetypes',
446 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
447 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
450 $languageService = $this->prophesize(LanguageService::class);
451 $GLOBALS[
'LANG'] = $languageService->reveal();
452 $languageService->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue')->willReturn(
'INVALID VALUE "%s"');
454 $languageService->sL(
'aLabel')->shouldBeCalled()->willReturnArgument(0);
457 $expected[
'databaseRow'][
'aField'] = [
'aValue'];
458 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = [
476 'Table with exclude and non exclude field returns exclude item' => [
481 'title' =>
'fooTableTitle',
485 'label' =>
'barColumnTitle',
489 'label' =>
'bazColumnTitle',
497 0 =>
'fooTableTitle',
503 0 =>
'barColumnTitle (bar)',
510 'Root level table with ignored root level restriction returns exclude item' => [
515 'title' =>
'fooTableTitle',
518 'ignoreRootLevelRestriction' =>
true,
523 'label' =>
'barColumnTitle',
532 0 =>
'fooTableTitle',
538 0 =>
'barColumnTitle (bar)',
545 'Root level table without ignored root level restriction returns no item' => [
550 'title' =>
'fooTableTitle',
555 'label' =>
'barColumnTitle',
565 'Admin table returns no item' => [
570 'title' =>
'fooTableTitle',
575 'label' =>
'barColumnTitle',
595 'tableName' =>
'aTable',
602 'renderType' =>
'selectSingle',
603 'special' =>
'exclude',
611 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
612 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
616 $this->assertSame($expectedItems, $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
625 'tableName' =>
'aTable',
632 'renderType' =>
'selectSingle',
633 'special' =>
'exclude',
643 'title' =>
'fooTableTitle',
647 'label' =>
'aFlexFieldTitle',
659 <label>flexInputLabel</label>
678 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
679 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
683 0 =>
'fooTableTitle aFlexFieldTitle dummy',
689 0 =>
'flexInputLabel (input1)',
690 1 =>
'fooTable:aFlexField;dummy;sDEF;input1',
698 $this->assertSame($expectedItems, $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
707 'tableName' =>
'aTable',
714 'renderType' =>
'selectSingle',
715 'special' =>
'explicitValues',
725 'title' =>
'fooTableTitle',
729 'label' =>
'aFieldTitle',
732 'renderType' =>
'selectSingle',
733 'authMode' =>
'explicitAllow',
746 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
747 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
750 $languageService = $this->prophesize(LanguageService::class);
751 $GLOBALS[
'LANG'] = $languageService->reveal();
752 $languageService->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.allow')->shouldBeCalled()->willReturn(
'allowMe');
753 $languageService->sL(Argument::cetera())->willReturnArgument(0);
757 0 =>
'fooTableTitle: aFieldTitle',
763 0 =>
'[allowMe] anItemTitle',
764 1 =>
'fooTable:aField:anItemValue:ALLOW',
765 2 =>
'status-status-permission-granted',
772 $this->assertSame($expectedItems, $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
781 'tableName' =>
'aTable',
788 'renderType' =>
'selectSingle',
789 'special' =>
'explicitValues',
799 'title' =>
'fooTableTitle',
803 'label' =>
'aFieldTitle',
806 'renderType' =>
'selectSingle',
807 'authMode' =>
'explicitDeny',
820 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
821 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
824 $languageService = $this->prophesize(LanguageService::class);
825 $GLOBALS[
'LANG'] = $languageService->reveal();
826 $languageService->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.deny')->shouldBeCalled()->willReturn(
'denyMe');
827 $languageService->sL(Argument::cetera())->willReturnArgument(0);
831 0 =>
'fooTableTitle: aFieldTitle',
837 0 =>
'[denyMe] anItemTitle',
838 1 =>
'fooTable:aField:anItemValue:DENY',
839 2 =>
'status-status-permission-denied',
846 $this->assertSame($expectedItems, $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
855 'tableName' =>
'aTable',
862 'renderType' =>
'selectSingle',
863 'special' =>
'explicitValues',
873 'title' =>
'fooTableTitle',
877 'label' =>
'aFieldTitle',
880 'renderType' =>
'selectSingle',
881 'authMode' =>
'individual',
909 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
910 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
913 $languageService = $this->prophesize(LanguageService::class);
914 $GLOBALS[
'LANG'] = $languageService->reveal();
915 $languageService->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.allow')->shouldBeCalled()->willReturn(
'allowMe');
916 $languageService->sL(Argument::cetera())->willReturnArgument(0);
920 0 =>
'fooTableTitle: aFieldTitle',
926 0 =>
'[allowMe] aItemTitle',
927 1 =>
'fooTable:aField:aItemValue:ALLOW',
928 2 =>
'status-status-permission-granted',
932 0 =>
'[allowMe] cItemTitle',
933 1 =>
'fooTable:aField:cItemValue:ALLOW',
934 2 =>
'status-status-permission-granted',
941 $this->assertSame($expectedItems, $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
950 'tableName' =>
'aTable',
957 'renderType' =>
'selectSingle',
958 'special' =>
'explicitValues',
968 'title' =>
'fooTableTitle',
972 'label' =>
'aFieldTitle',
975 'renderType' =>
'selectSingle',
976 'authMode' =>
'individual',
1004 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
1005 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
1008 $languageService = $this->prophesize(LanguageService::class);
1009 $GLOBALS[
'LANG'] = $languageService->reveal();
1010 $languageService->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.deny')->shouldBeCalled()->willReturn(
'denyMe');
1011 $languageService->sL(Argument::cetera())->willReturnArgument(0);
1015 0 =>
'fooTableTitle: aFieldTitle',
1021 0 =>
'[denyMe] aItemTitle',
1022 1 =>
'fooTable:aField:aItemValue:DENY',
1023 2 =>
'status-status-permission-denied',
1027 0 =>
'[denyMe] cItemTitle',
1028 1 =>
'fooTable:aField:cItemValue:DENY',
1029 2 =>
'status-status-permission-denied',
1036 $this->assertSame($expectedItems, $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
1045 'tableName' =>
'aTable',
1046 'databaseRow' => [],
1052 'renderType' =>
'selectSingle',
1053 'special' =>
'languages',
1058 'systemLanguageRows' => [
1060 'title' =>
'aLangTitle',
1062 'flagIconIdentifier' =>
'aFlag.gif',
1067 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
1068 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
1081 $this->assertSame($expectedItems, $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
1090 'tableName' =>
'aTable',
1091 'databaseRow' => [],
1097 'renderType' =>
'selectSingle',
1098 'special' =>
'custom',
1105 $GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'customPermOptions'] = [
1107 'header' =>
'aHeader',
1113 0 =>
'anotherTitle',
1114 1 =>
'status-status-permission-denied',
1115 2 =>
'aDescription',
1121 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
1122 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
1133 1 =>
'aKey:anItemKey',
1138 0 =>
'anotherTitle',
1139 1 =>
'aKey:anotherKey',
1141 3 => [
'description' =>
'aDescription' ],
1147 $this->assertSame($expectedItems, $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
1156 'tableName' =>
'aTable',
1157 'databaseRow' => [],
1163 'renderType' =>
'selectSingle',
1164 'special' =>
'modListGroup',
1173 $iconFactoryProphecy = $this->prophesize(IconRegistry::class);
1174 GeneralUtility::setSingletonInstance(IconRegistry::class, $iconFactoryProphecy->reveal());
1177 $moduleLoaderProphecy = $this->prophesize(ModuleLoader::class);
1178 GeneralUtility::addInstance(ModuleLoader::class, $moduleLoaderProphecy->reveal());
1179 $moduleLoaderProphecy->load([])->shouldBeCalled();
1180 $moduleLoaderProphecy->modListGroup = [
1183 $moduleLoaderProphecy->modules = [
1185 'iconIdentifier' =>
'empty-empty'
1188 $moduleLoaderProphecy->getLabelsForModule(
'aModule')->shouldBeCalled()->willReturn([
1189 'shortdescription' =>
'aModuleTabLabel',
1190 'description' =>
'aModuleTabDescription',
1191 'title' =>
'aModuleLabel'
1196 0 =>
'aModuleLabel',
1200 'title' =>
'aModuleTabLabel',
1201 'description' =>
'aModuleTabDescription',
1208 $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][0][2] = str_replace([CR, LF,
"\t"],
'', $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][0][2]);
1209 $this->assertSame($expectedItems, $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
1217 $directory = $this->getUniqueId(
'typo3temp/var/tests/test-') .
'/';
1219 'tableName' =>
'aTable',
1220 'databaseRow' => [],
1226 'renderType' =>
'selectSingle',
1227 'fileFolder' => $directory,
1228 'fileFolder_extList' =>
'gif',
1229 'fileFolder_recursions' => 1,
1251 0 =>
'subdir/anotherImage.gif',
1252 1 =>
'subdir/anotherImage.gif',
1260 $this->assertSame($expectedItems, $result[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
1269 'tableName' =>
'aTable',
1270 'databaseRow' => [],
1276 'renderType' =>
'selectSingle',
1277 'fileFolder' =>
'EXT:non_existing/Resources/Public/',
1284 $this->expectException(\RuntimeException::class);
1285 $this->expectExceptionCode(1479399227);
1298 'tableName' =>
'aTable',
1304 'renderType' =>
'selectSingle',
1313 'maxitems' => 99999,
1332 $expected[
'databaseRow'][
'aField'] = [];
1333 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][1] = [
1340 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
1352 'tableName' =>
'aTable',
1358 'renderType' =>
'selectSingle',
1367 'maxitems' => 99999,
1386 $expected[
'databaseRow'][
'aField'] = [];
1387 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][1] = [
1394 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
1403 'replace REC_FIELD' => [
1404 'AND fTable.title=\'###REC_FIELD_rowField###\'',
1406 [
'fTable.title=\'rowFieldValue\''],
1408 [
'`pages.uid` = `fTable.pid`']
1412 'replace REC_FIELD within FlexForm' => [
1413 'AND fTable.title=###REC_FIELD_rowFieldFlexForm###',
1415 [
'fTable.title=\'rowFieldFlexFormValue\''],
1417 [
'`pages.uid` = `fTable.pid`']
1421 'rowFieldThree' => [
1422 0 =>
'rowFieldThreeValue'
1425 'flexParentDatabaseRow' => [
1426 'rowFieldFlexForm' => [
1427 0 =>
'rowFieldFlexFormValue'
1432 'replace REC_FIELD fullQuote' => [
1433 'AND fTable.title=###REC_FIELD_rowField###',
1435 [
'fTable.title=\'rowFieldValue\''],
1437 [
'`pages.uid` = `fTable.pid`']
1441 'replace REC_FIELD fullQuoteWithArray' => [
1442 'AND fTable.title=###REC_FIELD_rowFieldThree###',
1444 [
'fTable.title=\'rowFieldThreeValue\''],
1446 [
'`pages.uid` = `fTable.pid`']
1450 'rowFieldThree' => [
1451 0 =>
'rowFieldThreeValue'
1456 'replace REC_FIELD multiple markers' => [
1457 'AND fTable.title=\'###REC_FIELD_rowField###\' AND fTable.pid=###REC_FIELD_rowFieldTwo###',
1459 [
'fTable.title=\'rowFieldValue\' AND fTable.pid=\'rowFieldTwoValue\''],
1461 [
'`pages.uid` = `fTable.pid`']
1465 'replace CURRENT_PID' => [
1466 'AND fTable.uid=###CURRENT_PID###',
1470 [
'`pages.uid` = `fTable.pid`']
1474 'replace CURRENT_PID within FlexForm' => [
1475 'AND fTable.uid=###CURRENT_PID###',
1479 [
'`pages.uid` = `fTable.pid`']
1482 'flexParentDatabaseRow' => [
1487 'replace CURRENT_PID integer cast' => [
1488 'AND fTable.uid=###CURRENT_PID###',
1492 [
'`pages.uid` = `fTable.pid`']
1495 'effectivePid' =>
'431string',
1498 'replace THIS_UID' => [
1499 'AND fTable.uid=###THIS_UID###',
1503 [
'`pages.uid` = `fTable.pid`']
1507 'replace THIS_UID integer cast' => [
1508 'AND fTable.uid=###THIS_UID###',
1512 [
'`pages.uid` = `fTable.pid`']
1516 'uid' =>
'421string',
1520 'replace SITEROOT' => [
1521 'AND fTable.uid=###SITEROOT###',
1525 [
'`pages.uid` = `fTable.pid`']
1529 'replace SITEROOT integer cast' => [
1530 'AND fTable.uid=###SITEROOT###',
1534 [
'`pages.uid` = `fTable.pid`']
1539 'uid' =>
'441string',
1544 'replace PAGE_TSCONFIG_ID' => [
1545 'AND fTable.uid=###PAGE_TSCONFIG_ID###',
1549 [
'`pages.uid` = `fTable.pid`']
1556 'PAGE_TSCONFIG_ID' =>
'45',
1563 'replace PAGE_TSCONFIG_ID integer cast' => [
1564 'AND fTable.uid=###PAGE_TSCONFIG_ID###',
1568 [
'`pages.uid` = `fTable.pid`']
1575 'PAGE_TSCONFIG_ID' =>
'451string'
1582 'replace PAGE_TSCONFIG_STR' => [
1583 'AND fTable.uid=\'###PAGE_TSCONFIG_STR###\'',
1585 [
'fTable.uid=\'46\''],
1587 [
'`pages.uid` = `fTable.pid`']
1594 'PAGE_TSCONFIG_STR' =>
'46',
1601 'replace PAGE_TSCONFIG_IDLIST' => [
1602 'AND fTable.uid IN (###PAGE_TSCONFIG_IDLIST###)',
1604 [
'fTable.uid IN (47,48)'],
1606 [
'`pages.uid` = `fTable.pid`']
1613 'PAGE_TSCONFIG_IDLIST' =>
'47,48',
1620 'replace PAGE_TSCONFIG_IDLIST cleans list' => [
1621 'AND fTable.uid IN (###PAGE_TSCONFIG_IDLIST###)',
1623 [
'fTable.uid IN (471,481)'],
1625 [
'`pages.uid` = `fTable.pid`']
1632 'PAGE_TSCONFIG_IDLIST' =>
'a, 471, b, 481, c',
1649 'tableName' =>
'aTable',
1650 'effectivePid' => 43,
1653 'rowField' =>
'rowFieldValue',
1654 'rowFieldTwo' =>
'rowFieldTwoValue',
1661 'renderType' =>
'selectSingle',
1662 'foreign_table' =>
'fTable',
1663 'foreign_table_where' => $foreignTableWhere,
1679 'is_siteroot' =>
null,
1682 'pageTsConfig' => [],
1688 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
1689 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
1691 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
1692 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
1693 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
1698 $statementProphet = $this->prophesize(Statement::class);
1700 $queryBuilderProphet->select(
'fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1701 $queryBuilderProphet->from(
'fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1702 $queryBuilderProphet->from(
'pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1703 $queryBuilderProphet->where(...array_shift($expectedWhere))->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1704 $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
1706 while ($constraint = array_shift($expectedWhere)) {
1707 $queryBuilderProphet->andWhere(...$constraint)
1709 ->willReturn($queryBuilderProphet->reveal());
1713 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
1714 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
1717 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
1718 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
1719 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
1730 'tableName' =>
'aTable',
1736 'renderType' =>
'selectSingle',
1737 'foreign_table' =>
'fTable',
1744 $this->expectException(\UnexpectedValueException::class);
1745 $this->expectExceptionCode(1439569743);
1756 'tableName' =>
'aTable',
1757 'effectivePid' => 42,
1766 'renderType' =>
'selectSingle',
1767 'foreign_table' =>
'fTable',
1768 'foreign_table_where' =>
'
1770 GROUP BY groupField1, groupField2
1782 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
1783 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
1785 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
1786 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
1787 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
1790 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
1791 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
1792 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
1797 $statementProphet = $this->prophesize(Statement::class);
1799 $queryBuilderProphet->select(
'fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1800 $queryBuilderProphet->from(
'fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1801 $queryBuilderProphet->from(
'pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1802 $queryBuilderProphet->groupBy(
'groupField1',
'groupField2')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1803 $queryBuilderProphet->addOrderBy(
'orderField',
null)->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1804 $queryBuilderProphet->setFirstResult(1)->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1805 $queryBuilderProphet->setMaxResults(2)->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1806 $queryBuilderProphet->where(
'ftable.uid=1')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1807 $queryBuilderProphet->andWhere(
' 1=1')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1808 $queryBuilderProphet->andWhere(
'`pages.uid` = `fTable.pid`')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1809 $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
1812 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
1813 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
1828 'tableName' =>
'aTable',
1829 'effectivePid' => 42,
1835 'renderType' =>
'selectSingle',
1836 'foreign_table' =>
'fTable',
1845 'maxitems' => 99999,
1856 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
1857 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
1858 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
1863 $statementProphet = $this->prophesize(Statement::class);
1865 $queryBuilderProphet->select(
'fTable.uid')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1866 $queryBuilderProphet->from(
'fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1867 $queryBuilderProphet->from(
'pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1868 $queryBuilderProphet->where(
'')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1869 $queryBuilderProphet->andWhere(
' 1=1')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1870 $queryBuilderProphet->andWhere(
'`pages.uid` = `fTable.pid`')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1872 $prevException =
new DBALException(
'Invalid table name', 1476045274);
1873 $exception =
new DBALException(
'Driver error', 1476045971, $prevException);
1875 $queryBuilderProphet->execute()->shouldBeCalled()->willThrow($exception);
1878 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
1879 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
1882 $flashMessage = $this->prophesize(FlashMessage::class);
1883 GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal());
1885 $flashMessageService = $this->prophesize(FlashMessageService::class);
1886 GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal());
1888 $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
1889 $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
1891 $flashMessageQueue->enqueue($flashMessage)->shouldBeCalled();
1894 $expected[
'databaseRow'][
'aField'] = [];
1896 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
1907 $statementProphet = $this->prophesize(Statement::class);
1909 $queryBuilderProphet->select(
'fTable.uid',
'fTable.labelField')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1910 $queryBuilderProphet->from(
'fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1911 $queryBuilderProphet->from(
'pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1912 $queryBuilderProphet->where(
'')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1913 $queryBuilderProphet->andWhere(
' 1=1')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1914 $queryBuilderProphet->andWhere(
'`pages.uid` = `fTable.pid`')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
1915 $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
1917 return [$connectionPoolProphet, $statementProphet];
1930 'tableName' =>
'aTable',
1931 'effectivePid' => 42,
1937 'renderType' =>
'selectSingle',
1938 'foreign_table' =>
'fTable',
1939 'foreign_table_prefix' =>
'aPrefix',
1941 'maxitems' => 99999,
1951 'label' =>
'labelField',
1956 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
1957 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
1959 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
1960 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
1961 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
1964 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
1965 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
1966 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
1971 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
1972 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
1975 $statementProphet->fetch()->shouldBeCalled()->will(
function (
$args) use (&$counter) {
1977 if ($counter >= 3) {
1983 'labelField' =>
'aLabel',
1989 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = [
1991 0 =>
'aPrefix[LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title]',
1997 0 =>
'aPrefix[LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title]',
2004 $expected[
'databaseRow'][
'aField'] = [];
2006 self::assertEquals($expected, (
new TcaSelectItems)->addData($input));
2019 'tableName' =>
'aTable',
2020 'effectivePid' => 42,
2026 'renderType' =>
'selectSingle',
2027 'foreign_table' =>
'sys_file_storage',
2028 'foreign_table_prefix' =>
'prefix for item labels',
2030 'maxitems' => 99999,
2038 $GLOBALS[
'TCA'][
'sys_file_storage'] = [
2040 'label' =>
'labelField',
2045 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
2046 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
2047 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
2049 $resourceStorageProphecy = $this->prophesize(ResourceStorage::class);
2050 $resourceStorageProphecy->getUid()->willReturn(1);
2053 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
2054 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
2055 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
2056 $backendUserProphecy->getFileStorages()->shouldBeCalled()->willReturn(
2057 [$resourceStorageProphecy->reveal()]
2063 $statementProphet = $this->prophesize(Statement::class);
2065 $queryBuilderProphet->select(
'sys_file_storage.uid',
'sys_file_storage.labelField')
2066 ->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2067 $queryBuilderProphet->from(
'sys_file_storage')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2068 $queryBuilderProphet->from(
'pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2069 $queryBuilderProphet->where(
'')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2070 $queryBuilderProphet->andWhere(
' 1=1')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2071 $queryBuilderProphet->andWhere(
'`pages.uid` = `sys_file_storage.pid`')
2072 ->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2073 $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
2076 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
2077 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
2080 $statementProphet->fetch()->shouldBeCalled()->will(
function (
$args) use (&$counter) {
2082 if ($counter >= 3) {
2088 'labelField' =>
'storageFolderLabel'
2093 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = [
2095 0 =>
'prefix for item labels[LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title]',
2097 2 =>
'default-not-found',
2102 $expected[
'databaseRow'][
'aField'] = [];
2104 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2117 'tableName' =>
'aTable',
2118 'effectivePid' => 42,
2124 'renderType' =>
'selectSingle',
2125 'foreign_table' =>
'fTable',
2126 'maxitems' => 99999,
2138 'selicon_field' =>
'icon',
2139 'selicon_field_path' =>
'uploads/media',
2146 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
2147 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
2149 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
2150 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
2151 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
2154 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
2155 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
2156 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
2161 $statementProphet = $this->prophesize(Statement::class);
2163 $queryBuilderProphet->select(
'fTable.uid',
'fTable.icon')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2164 $queryBuilderProphet->from(
'fTable')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2165 $queryBuilderProphet->from(
'pages')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2166 $queryBuilderProphet->where(
'')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2167 $queryBuilderProphet->andWhere(
' 1=1')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2168 $queryBuilderProphet->andWhere(
'`pages.uid` = `fTable.pid`')->shouldBeCalled()->willReturn($queryBuilderProphet->reveal());
2169 $queryBuilderProphet->execute()->shouldBeCalled()->willReturn($statementProphet->reveal());
2172 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
2173 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
2176 $foreignTableRowResultOne = [
2179 'icon' =>
'foo.jpg',
2181 $statementProphet->fetch()->shouldBeCalled()->willReturn($foreignTableRowResultOne,
false);
2184 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = [
2188 2 =>
'uploads/media/foo.jpg',
2192 $expected[
'databaseRow'][
'aField'] = [];
2194 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2206 'tableName' =>
'aTable',
2212 'renderType' =>
'selectSingle',
2229 'maxitems' => 99999,
2238 'keepItems' =>
'keep',
2246 $expected[
'databaseRow'][
'aField'] = [];
2248 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][1],
2249 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][2]
2252 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2264 'tableName' =>
'aTable',
2270 'renderType' =>
'selectSingle',
2283 'maxitems' => 99999,
2300 $expected[
'databaseRow'][
'aField'] = [];
2301 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = [];
2303 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2315 'tableName' =>
'aTable',
2321 'renderType' =>
'selectSingle',
2334 'maxitems' => 99999,
2345 '1' =>
'addItem #1',
2346 '12' =>
'addItem #12',
2355 $expected[
'databaseRow'][
'aField'] = [];
2356 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = [
2377 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2389 'tableName' =>
'aTable',
2395 'renderType' =>
'selectSingle',
2414 'maxitems' => 99999,
2423 'removeItems' =>
'remove',
2431 $expected[
'databaseRow'][
'aField'] = [];
2432 unset($expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][1]);
2433 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = array_values($expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items']);
2434 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2446 'tableName' =>
'aTable',
2452 'renderType' =>
'selectSingle',
2471 'maxitems' => 99999,
2480 'removeItems' =>
'0',
2488 $expected[
'databaseRow'][
'aField'] = [];
2489 unset($expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][2]);
2490 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2502 'tableName' =>
'aTable',
2508 'renderType' =>
'selectSingle',
2521 'maxitems' => 99999,
2530 'removeItems' =>
'remove,add',
2541 $expected[
'databaseRow'][
'aField'] = [];
2542 unset($expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][1]);
2544 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2554 'aField' =>
'aValue,remove'
2556 'tableName' =>
'aTable',
2559 'languageField' =>
'aField',
2565 'renderType' =>
'selectSingle',
2578 'maxitems' => 99999,
2586 $languageService = $this->prophesize(LanguageService::class);
2587 $GLOBALS[
'LANG'] = $languageService->reveal();
2588 $languageService->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue')->willReturn(
'INVALID VALUE "%s"');
2589 $languageService->sL(Argument::cetera())->willReturnArgument(0);
2592 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
2593 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
2594 $backendUserProphecy->checkLanguageAccess(
'keep')->shouldBeCalled()->willReturn(
true);
2595 $backendUserProphecy->checkLanguageAccess(
'remove')->shouldBeCalled()->willReturn(
false);
2598 $expected[
'databaseRow'][
'aField'] = [];
2599 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = [
2600 [
'[ INVALID VALUE "aValue" ]',
'aValue',
null, null ],
2601 [
'keepMe',
'keep',
null, null ],
2604 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2614 'aField' =>
'keep,remove'
2616 'tableName' =>
'aTable',
2622 'renderType' =>
'selectSingle',
2623 'authMode' =>
'explicitAllow',
2636 'maxitems' => 99999,
2644 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
2645 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
2646 $backendUserProphecy->checkAuthMode(
'aTable',
'aField',
'keep',
'explicitAllow')->shouldBeCalled()->willReturn(
true);
2647 $backendUserProphecy->checkAuthMode(
'aTable',
'aField',
'remove',
'explicitAllow')->shouldBeCalled()->willReturn(
false);
2650 $expected[
'databaseRow'][
'aField'] = [
'keep'];
2651 unset($expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][1]);
2653 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2665 'tableName' =>
'pages',
2671 'renderType' =>
'selectSingle',
2680 'maxitems' => 99999,
2688 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
2689 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
2690 $backendUserProphecy->isAdmin()->shouldBeCalled()->willReturn(
true);
2693 $expected[
'databaseRow'][
'doktype'] = [
'keep'];
2695 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2705 'doktype' =>
'keep',
2707 'tableName' =>
'pages',
2713 'renderType' =>
'selectSingle',
2726 'maxitems' => 99999,
2734 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
2735 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
2736 $backendUserProphecy->isAdmin()->shouldBeCalled()->willReturn(
false);
2737 $backendUserProphecy->groupData = [
2738 'pagetypes_select' =>
'foo,keep,anotherAllowedDoktype',
2742 $expected[
'databaseRow'][
'doktype'] = [
'keep'];
2743 unset($expected[
'processedTca'][
'columns'][
'doktype'][
'config'][
'items'][1]);
2745 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
2754 'tableName' =>
'aTable',
2756 'aField' =>
'aValue'
2763 'renderType' =>
'selectSingle',
2765 'itemsProcFunc' =>
function (array $parameters, $pObj) {
2766 $parameters[
'items'] = [
2782 $expected[
'databaseRow'][
'aField'] = [
'aValue'];
2783 $expected[
'processedTca'][
'columns'][
'aField'][
'config'] = [
2785 'renderType' =>
'selectSingle',
2794 'maxitems' => 99999,
2810 'tableName' =>
'aTable',
2811 'effectivePid' => 42,
2817 'renderType' =>
'selectSingle',
2818 'foreign_table' =>
'fTable',
2819 'maxitems' => 99999,
2829 'label' =>
'labelField',
2836 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
2837 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
2838 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
2841 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
2842 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
2843 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
2848 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
2849 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
2852 $statementProphet->fetch()->shouldBeCalled()->will(
function (
$args) use (&$counter) {
2854 if ($counter >= 3) {
2860 'labelField' =>
'aLabel_' . $counter,
2862 'dbfield' =>
'some data'
2867 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = [
2871 2 =>
'default-not-found',
2877 2 =>
'default-not-found',
2882 $expected[
'databaseRow'][
'aField'] = [
2886 self::assertEquals($expected, (
new TcaSelectItems)->addData($input));
2904 'tableName' =>
'aTable',
2905 'effectivePid' => 42,
2911 'renderType' =>
'selectSingle',
2912 'foreign_table' =>
'fTable',
2913 'itemsProcFunc' =>
function (array $parameters, $pObj) {
2914 $filteredItems = [];
2916 foreach ($parameters[
'items'] as $item) {
2917 if ($item[1] === 2) {
2918 $filteredItems[] = [
2926 $parameters[
'items'] = $filteredItems;
2928 'maxitems' => 99999,
2938 'label' =>
'labelField',
2944 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
2945 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
2946 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
2949 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
2950 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
2951 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
2956 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
2957 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
2962 $statementProphet->fetch()->shouldBeCalled()->will(
function (
$args) use (&$counter) {
2964 if ($counter >= 3) {
2970 'labelField' =>
'aLabel will be replaced since the label column is not configured',
2971 'aValue' =>
'bar, irrelevant',
2972 'dbfield' =>
'some random data, irrelevant'
2977 $expected[
'processedTca'][
'columns'][
'aField'][
'config'] = [
2979 'renderType' =>
'selectSingle',
2980 'foreign_table' =>
'fTable',
2983 0 =>
'[LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title]',
2992 $expected[
'databaseRow'][
'aField'] = [];
2994 self::assertEquals($expected, (
new TcaSelectItems)->addData($input));
3013 'tableName' =>
'aTable',
3014 'effectivePid' => 42,
3020 'renderType' =>
'selectSingle',
3021 'foreign_table' =>
'fTable',
3022 'itemsProcFunc' =>
function (array $parameters, $pObj) {
3023 $filteredItems = [];
3025 foreach ($parameters[
'items'] as $item) {
3027 $filteredItems[] = [
3035 $parameters[
'items'] = $filteredItems;
3037 'maxitems' => 99999,
3046 'removeItems' =>
'2'
3056 'label' =>
'labelField',
3062 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
3063 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
3064 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
3067 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
3068 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
3069 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
3074 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
3075 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
3080 $statementProphet->fetch()->shouldBeCalled()->will(
function (
$args) use (&$counter) {
3082 if ($counter >= 3) {
3088 'labelField' =>
'aLabel will be replaced since the label column is not configured',
3089 'randomDbField' =>
'bar, irrelevant'
3094 $expected[
'processedTca'][
'columns'][
'aField'][
'config'] = [
3096 'renderType' =>
'selectSingle',
3097 'foreign_table' =>
'fTable',
3100 0 =>
'[LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title]',
3109 $expected[
'databaseRow'][
'aField'] = [];
3111 self::assertEquals($expected, (
new TcaSelectItems)->addData($input));
3130 'tableName' =>
'aTable',
3131 'effectivePid' => 42,
3137 'renderType' =>
'selectSingle',
3138 'foreign_table' =>
'fTable',
3139 'itemsProcFunc' =>
function (array $parameters, $pObj) {
3140 $filteredItems = [];
3142 foreach ($parameters[
'items'] as $item) {
3143 if ($item[1] === 2) {
3144 $filteredItems[] = [
3152 $parameters[
'items'] = $filteredItems;
3154 'maxitems' => 99999,
3164 '12' =>
'Label of the added item'
3175 'label' =>
'labelField',
3181 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
3182 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
3183 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
3186 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
3187 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
3188 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
3193 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
3194 GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
3199 $statementProphet->fetch()->shouldBeCalled()->will(
function (
$args) use (&$counter) {
3201 if ($counter >= 3) {
3207 'labelField' =>
'aLabel will be replaced since the label column is not configured',
3208 'randomDbField' =>
'bar, irrelevant'
3213 $expected[
'processedTca'][
'columns'][
'aField'][
'config'] = [
3215 'renderType' =>
'selectSingle',
3216 'foreign_table' =>
'fTable',
3219 0 =>
'[LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.no_title]',
3225 0 =>
'Label of the added item',
3234 $expected[
'databaseRow'][
'aField'] = [];
3236 self::assertEquals($expected, (
new TcaSelectItems)->addData($input));
3245 'tableName' =>
'aTable',
3247 'aField' =>
'aValue',
3253 'itemsProcFunc.' => [
3254 'itemParamKey' =>
'itemParamValue',
3265 'renderType' =>
'selectSingle',
3273 'itemsProcFunc' =>
function (array $parameters, $pObj) {
3274 if ($parameters[
'items'] !== [ 0 => [
'aLabel',
'aValue'] ]
3275 || $parameters[
'config'][
'aKey'] !==
'aValue'
3276 || $parameters[
'TSconfig'] !== [
'itemParamKey' =>
'itemParamValue' ]
3277 || $parameters[
'table'] !==
'aTable'
3278 || $parameters[
'row'] !== [
'aField' =>
'aValue' ]
3279 || $parameters[
'field'] !==
'aField'
3281 throw new \UnexpectedValueException(
'broken', 1476109436);
3290 $languageService = $this->prophesize(LanguageService::class);
3291 $GLOBALS[
'LANG'] = $languageService->reveal();
3292 $languageService->sL(Argument::cetera())->willReturnArgument(0);
3294 $flashMessage = $this->prophesize(FlashMessage::class);
3295 GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal());
3297 $flashMessageService = $this->prophesize(FlashMessageService::class);
3298 GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal());
3300 $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
3301 $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
3304 $flashMessageQueue->enqueue($flashMessage)->shouldNotBeCalled();
3315 'tableName' =>
'aTable',
3317 'aField' =>
'aValue',
3323 'itemsProcFunc.' => [
3324 'itemParamKey' =>
'itemParamValue',
3335 'renderType' =>
'selectSingle',
3343 'itemsProcFunc' =>
function (array $parameters, $pObj) {
3344 throw new \UnexpectedValueException(
'anException', 1476109437);
3352 $languageService = $this->prophesize(LanguageService::class);
3353 $GLOBALS[
'LANG'] = $languageService->reveal();
3355 $flashMessage = $this->prophesize(FlashMessage::class);
3356 GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal());
3358 $flashMessageService = $this->prophesize(FlashMessageService::class);
3359 GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal());
3361 $flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
3362 $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal());
3364 $flashMessageQueue->enqueue($flashMessage)->shouldBeCalled();
3376 'aField' =>
'aValue',
3378 'tableName' =>
'aTable',
3384 'renderType' =>
'selectSingle',
3393 'maxitems' => 99999,
3403 'aValue' =>
'labelOverride',
3412 $languageService = $this->prophesize(LanguageService::class);
3413 $GLOBALS[
'LANG'] = $languageService->reveal();
3414 $languageService->sL(
'aLabel')->willReturnArgument(0);
3415 $languageService->sL(
'labelOverride')->shouldBeCalled()->willReturnArgument(0);
3416 $languageService->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue')->willReturn(
'INVALID VALUE "%s"');
3419 $expected[
'databaseRow'][
'aField'] = [
'aValue'];
3420 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'][0][0] =
'labelOverride';
3432 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
3433 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
3435 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
3436 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
3437 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
3440 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
3441 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
3442 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
3447 'command' =>
'edit',
3448 'tableName' =>
'aTable',
3449 'effectivePid' => 23,
3460 'renderType' =>
'selectSingle',
3462 'foreign_table' =>
'foreignTable',
3463 'MM' =>
'aTable_foreignTable_mm',
3470 $fieldConfig = $input[
'processedTca'][
'columns'][
'aField'][
'config'];
3472 $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
3473 GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
3475 $relationHandlerUids = [
3480 $relationHandlerProphecy->start(
'',
'foreignTable',
'aTable_foreignTable_mm', 42,
'aTable', $fieldConfig)->shouldBeCalled();
3481 $relationHandlerProphecy->getValueArray()->shouldBeCalled()->willReturn($relationHandlerUids);
3484 $expected[
'databaseRow'][
'aField'] = $relationHandlerUids;
3486 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
3496 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
3497 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
3499 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
3500 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
3501 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
3504 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
3505 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
3506 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
3511 'tableName' =>
'aTable',
3512 'effectivePid' => 23,
3516 'aField' =>
'22,23,24,25',
3523 'renderType' =>
'selectSingle',
3525 'foreign_table' =>
'foreignTable',
3532 $fieldConfig = $input[
'processedTca'][
'columns'][
'aField'][
'config'];
3534 $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
3535 GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
3537 $relationHandlerUids = [
3542 $relationHandlerProphecy->start(
'22,23,24,25',
'foreignTable',
'', 42,
'aTable', $fieldConfig)->shouldBeCalled();
3543 $relationHandlerProphecy->getValueArray()->shouldBeCalled()->willReturn($relationHandlerUids);
3546 $expected[
'databaseRow'][
'aField'] = $relationHandlerUids;
3548 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
3558 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
3559 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
3561 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
3562 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
3563 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
3566 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
3567 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
3568 $backendUserProphecy->getPagePermsClause(1)->shouldBeCalled()->willReturn(
' 1=1');
3572 $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
3573 GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
3574 $relationHandlerProphecy->start(Argument::cetera())->shouldBeCalled();
3575 $relationHandlerProphecy->getValueArray(Argument::cetera())->shouldBeCalled()->willReturn([1]);
3578 'tableName' =>
'aTable',
3579 'effectivePid' => 23,
3582 'aField' =>
'1,2,bar,foo',
3589 'renderType' =>
'selectSingleBox',
3590 'foreign_table' =>
'foreignTable',
3593 [
'foo',
'foo',
null,
null],
3602 $expected[
'databaseRow'][
'aField'] = [1,
'foo'];
3604 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
3613 'tableName' =>
'aTable',
3615 'aField' =>
'foo,bar',
3622 'renderType' =>
'selectSingle',
3625 [
'foo',
'foo',
null,
null],
3626 [
'bar',
'bar',
null,
null],
3635 $expected[
'databaseRow'][
'aField'] = [
3640 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
3649 'tableName' =>
'aTable',
3658 'renderType' =>
'selectSingle',
3659 'maxitems' => 99999,
3668 $expected[
'databaseRow'][
'aField'] = [];
3670 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
3679 'tableName' =>
'aTable',
3688 'renderType' =>
'selectSingle',
3691 [
'a',
'',
null,
null],
3692 [
'b',
'b',
null,
null],
3693 [
'c',
'c',
null,
null],
3702 $expected[
'databaseRow'][
'aField'] = [
3707 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
3715 $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
3716 GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
3717 $relationHandlerProphecy->start(Argument::cetera())->shouldNotBeCalled();
3718 $relationHandlerProphecy->getValueArray(Argument::cetera())->shouldNotBeCalled();
3721 'tableName' =>
'aTable',
3730 'renderType' =>
'selectSingle',
3733 [
'foo',
'foo',
null,
null],
3742 $expected[
'databaseRow'][
'aField'] = [
'foo'];
3744 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
3752 $languageService = $this->prophesize(LanguageService::class);
3753 $GLOBALS[
'LANG'] = $languageService->reveal();
3754 $languageService->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.noMatchingValue')->willReturn(
'INVALID VALUE "%s"');
3755 $languageService->sL(Argument::cetera())->willReturnArgument(0);
3757 $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
3758 GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
3759 $relationHandlerProphecy->start(Argument::cetera())->shouldNotBeCalled();
3760 $relationHandlerProphecy->getValueArray(Argument::cetera())->shouldNotBeCalled();
3763 'tableName' =>
'aTable',
3765 'aField' =>
'1,2,bar,foo',
3772 'renderType' =>
'selectSingle',
3773 'maxitems' => 99999,
3775 [
'foo',
'foo',
null,
null],
3784 $expected[
'databaseRow'][
'aField'] = [
'foo'];
3785 $expected[
'processedTca'][
'columns'][
'aField'][
'config'][
'items'] = [
3786 [
'[ INVALID VALUE "bar" ]',
'bar',
null,
null],
3787 [
'[ INVALID VALUE "2" ]',
'2',
null,
null],
3788 [
'[ INVALID VALUE "1" ]',
'1',
null,
null],
3789 [
'foo',
'foo',
null,
null],
3791 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
3800 'tableName' =>
'aTable',
3802 'aField' =>
'1,foo,foo,2,bar',
3809 'renderType' =>
'selectSingle',
3813 [
'1',
'1',
null,
null],
3814 [
'foo',
'foo',
null,
null],
3815 [
'bar',
'bar',
null,
null],
3816 [
'2',
'2',
null,
null],
3825 $expected[
'databaseRow'][
'aField'] = [
3833 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
3842 'tableName' =>
'aTable',
3844 'aField' =>
'1,foo,foo,2,bar',
3851 'renderType' =>
'selectSingle',
3852 'multiple' =>
false,
3855 [
'1',
'1',
null,
null],
3856 [
'foo',
'foo',
null,
null],
3857 [
'bar',
'bar',
null,
null],
3858 [
'2',
'2',
null,
null],
3867 $expected[
'databaseRow'][
'aField'] = [
3874 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));
3885 'Relation with MM table and new status with default values' => [
3887 'tableName' =>
'aTable',
3889 'effectivePid' => 42,
3892 'aField' =>
'24,35',
3899 'renderType' =>
'selectSingle',
3901 'MM' =>
'mm_aTable_foreignTable',
3902 'foreign_table' =>
'foreignTable',
3916 'Relation with MM table and item array in list but no new status' => [
3918 'tableName' =>
'aTable',
3919 'command' =>
'edit',
3920 'effectivePid' => 42,
3930 'renderType' =>
'selectSingle',
3932 'MM' =>
'mm_aTable_foreignTable',
3933 'foreign_table' =>
'foreignTable',
3941 'relationHandlerStartItemList' =>
'',
3945 'Relation with MM table and maxitems = 1 processes field value (item count)' => [
3947 'tableName' =>
'aTable',
3948 'command' =>
'edit',
3949 'effectivePid' => 42,
3960 'renderType' =>
'selectSingle',
3962 'MM' =>
'mm_aTable_foreignTable',
3963 'foreign_table' =>
'foreignTable',
3971 'relationHandlerStartItemList' =>
'',
3977 'Relation with MM table and maxitems = 1 results in empty array if no items are set' => [
3979 'tableName' =>
'aTable',
3980 'command' =>
'edit',
3981 'effectivePid' => 42,
3992 'renderType' =>
'selectSingle',
3994 'MM' =>
'mm_aTable_foreignTable',
3995 'foreign_table' =>
'foreignTable',
4003 'relationHandlerStartItemList' =>
'',
4020 $field = $overrideRelationHandlerSettings[
'relationHandlerStartItemList'] ?? $input[
'databaseRow'][
'aField'];
4021 $foreignTable = $overrideRelationHandlerSettings[
'foreign_table'] ?? $input[
'processedTca'][
'columns'][
'aField'][
'config'][
'foreign_table'];
4022 $mmTable = $overrideRelationHandlerSettings[
'MM'] ?? $input[
'processedTca'][
'columns'][
'aField'][
'config'][
'MM'];
4023 $uid = $input[
'databaseRow'][
'uid'];
4024 $tableName = $input[
'tableName'];
4025 $fieldConfig = $input[
'processedTca'][
'columns'][
'aField'][
'config'];
4029 $iconFactoryProphecy = $this->prophesize(IconFactory::class);
4030 GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal());
4032 $fileRepositoryProphecy = $this->prophesize(FileRepository::class);
4033 $fileRepositoryProphecy->findByRelation(Argument::cetera())->shouldNotBeCalled();
4034 GeneralUtility::setSingletonInstance(FileRepository::class, $fileRepositoryProphecy->reveal());
4037 $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class);
4038 $GLOBALS[
'BE_USER'] = $backendUserProphecy->reveal();
4039 $backendUserProphecy->getPagePermsClause(Argument::cetera())->willReturn(
' 1=1');
4044 $relationHandlerProphecy = $this->prophesize(RelationHandler::class);
4045 GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal());
4047 $relationHandlerProphecy->start($field, $foreignTable, $mmTable, $uid, $tableName, $fieldConfig)->shouldBeCalled();
4048 $relationHandlerProphecy->getValueArray()->shouldBeCalled()->willReturn($relationHandlerUids);
4051 $expected[
'databaseRow'][
'aField'] = $relationHandlerUids;
4053 $this->assertEquals($expected, (
new TcaSelectItems)->addData($input));