Skip to content

Commit

Permalink
[BUGFIX] Notice free TcaSelectItems testing
Browse files Browse the repository at this point in the history
Making FormEngine data providers notice free is a mixture of
fixing notices in the test subject, and improving test setup:
* It is assumed that stuff like BE_USER and LANG object exists,
  $subject access to these globals which throw notices is not
  fixed, instead the test setup is changed to mock these where
  needed.
* Data provider which have dependencies to other data prodivers
  assume their data is properly set, too. In those cases the
  test setup porperly sets this dependent data.
* Various other "real" notice fixes in test subject and code
  called by the test subject is actually fixed.

Change-Id: I7ae6444dc646ec114c15b2738ef4e30f67f88595
Resolves: #83975
Releases: master
Reviewed-on: https://review.typo3.org/55823
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
lolli42 committed Feb 20, 2018
1 parent 3a7ffec commit 2845b6a
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 261 deletions.
Expand Up @@ -234,7 +234,7 @@ protected function addItemsFromSpecial(array $result, $fieldName, array $items)
// Add help text
$helpText = [];
$languageService->loadSingleTableDescription($excludeArray['table']);
$helpTextArray = $GLOBALS['TCA_DESCR'][$excludeArray['table']]['columns'][$excludeArray['table']];
$helpTextArray = $GLOBALS['TCA_DESCR'][$excludeArray['table']]['columns'][$excludeArray['table']] ?? [];
if (!empty($helpTextArray['description'])) {
$helpText['description'] = $helpTextArray['description'];
}
Expand All @@ -255,7 +255,7 @@ protected function addItemsFromSpecial(array $result, $fieldName, array $items)
];
// Traverse types:
foreach ($theTypes as $tableFieldKey => $theTypeArrays) {
if (is_array($theTypeArrays['items'])) {
if (!empty($theTypeArrays['items'])) {
// Add header:
$items[] = [
$theTypeArrays['tableFieldLabel'],
Expand Down Expand Up @@ -326,7 +326,9 @@ protected function addItemsFromSpecial(array $result, $fieldName, array $items)
if (is_array($modList)) {
foreach ($modList as $theMod) {
$moduleLabels = $loadModules->getLabelsForModule($theMod);
list($mainModule, $subModule) = explode('_', $theMod, 2);
$moduleArray = GeneralUtility::trimExplode('_', $theMod, true);
$mainModule = $moduleArray[0] ?? '';
$subModule = $moduleArray[1] ?? '';
// Icon:
if (!empty($subModule)) {
$icon = $loadModules->modules[$mainModule]['sub'][$subModule]['iconIdentifier'];
Expand Down Expand Up @@ -443,7 +445,7 @@ protected function addItemsFromForeignTable(array $result, $fieldName, array $it

$foreignTable = $result['processedTca']['columns'][$fieldName]['config']['foreign_table'];

if (!is_array($GLOBALS['TCA'][$foreignTable])) {
if (!isset($GLOBALS['TCA'][$foreignTable]) || !is_array($GLOBALS['TCA'][$foreignTable])) {
throw new \UnexpectedValueException(
'Field ' . $fieldName . ' of table ' . $result['tableName'] . ' reference to foreign table '
. $foreignTable . ', but this table is not defined in TCA',
Expand Down Expand Up @@ -491,8 +493,10 @@ protected function addItemsFromForeignTable(array $result, $fieldName, array $it
$isReferenceField = false;
if (!empty($GLOBALS['TCA'][$foreignTable]['ctrl']['selicon_field'])) {
$iconFieldName = $GLOBALS['TCA'][$foreignTable]['ctrl']['selicon_field'];
if ($GLOBALS['TCA'][$foreignTable]['columns'][$iconFieldName]['config']['type'] === 'inline'
&& $GLOBALS['TCA'][$foreignTable]['columns'][$iconFieldName]['config']['foreign_table'] === 'sys_file_reference') {
if (isset($GLOBALS['TCA'][$foreignTable]['columns'][$iconFieldName]['config']['type'])
&& $GLOBALS['TCA'][$foreignTable]['columns'][$iconFieldName]['config']['type'] === 'inline'
&& $GLOBALS['TCA'][$foreignTable]['columns'][$iconFieldName]['config']['foreign_table'] === 'sys_file_reference'
) {
$isReferenceField = true;
}
}
Expand Down Expand Up @@ -749,7 +753,7 @@ protected function getExcludeFields()
&& (empty($GLOBALS['TCA'][$table]['ctrl']['rootLevel']) || !empty($GLOBALS['TCA'][$table]['ctrl']['security']['ignoreRootLevelRestriction']))
) {
foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $_) {
if ($GLOBALS['TCA'][$table]['columns'][$field]['exclude']) {
if (isset($GLOBALS['TCA'][$table]['columns'][$field]['exclude']) && (bool)$GLOBALS['TCA'][$table]['columns'][$field]['exclude']) {
// Get human readable names of fields
$translatedField = $languageService->sL($GLOBALS['TCA'][$table]['columns'][$field]['label']);
// Add entry, key 'labels' needed for sorting
Expand Down Expand Up @@ -918,9 +922,9 @@ protected function getExplicitAuthFieldValues()
$iMode = 'DENY';
break;
case 'individual':
if ($iVal[4] === 'EXPL_ALLOW') {
if (isset($iVal[4]) && $iVal[4] === 'EXPL_ALLOW') {
$iMode = 'ALLOW';
} elseif ($iVal[4] === 'EXPL_DENY') {
} elseif (isset($iVal[4]) && $iVal[4] === 'EXPL_DENY') {
$iMode = 'DENY';
}
break;
Expand Down Expand Up @@ -1101,12 +1105,16 @@ protected function processForeignTableClause(array $result, $foreignTableName, $
}

$pageTsConfigId = 0;
if ($result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_ID']) {
if (isset($result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_ID'])
&& $result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_ID']
) {
$pageTsConfigId = (int)$result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_ID'];
}

$pageTsConfigIdList = 0;
if ($result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_IDLIST']) {
if (isset($result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_IDLIST'])
&& $result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_IDLIST']
) {
$pageTsConfigIdList = $result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_IDLIST'];
}
$pageTsConfigIdListArray = GeneralUtility::trimExplode(',', $pageTsConfigIdList, true);
Expand All @@ -1119,7 +1127,9 @@ protected function processForeignTableClause(array $result, $foreignTableName, $
$pageTsConfigIdList = implode(',', $pageTsConfigIdList);

$pageTsConfigString = '';
if ($result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_STR']) {
if (isset($result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_STR'])
&& $result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_STR']
) {
$pageTsConfigString = $result['pageTsConfig']['TCEFORM.'][$localTable . '.'][$localFieldName . '.']['PAGE_TSCONFIG_STR'];
$pageTsConfigString = $connection->quote($pageTsConfigString);
}
Expand Down Expand Up @@ -1253,7 +1263,7 @@ protected function processSelectFieldValue(array $result, $fieldName, array $sta
$newDatabaseValueArray = array_merge($newDatabaseValueArray, $relationHandler->getValueArray());
}

if ($fieldConfig['config']['multiple']) {
if ($fieldConfig['config']['multiple'] ?? false) {
return $newDatabaseValueArray;
}
return array_unique($newDatabaseValueArray);
Expand Down Expand Up @@ -1286,8 +1296,8 @@ public function translateLabels(array $result, array $itemArray, $table, $fieldN
$label = $languageService->sL(trim($item[0]));
}
$value = strlen((string)$item[1]) > 0 ? $item[1] : '';
$icon = $item[2] ?: null;
$helpText = $item[3] ?: null;
$icon = !empty($item[2]) ? $item[2] : null;
$helpText = !empty($item[3]) ? $item[3] : null;
$itemArray[$key] = [
$label,
$value,
Expand Down
Expand Up @@ -43,7 +43,7 @@ public function addData(array $result)
continue;
}

$fieldConfig['config']['items'] = $this->sanitizeItemArray($fieldConfig['config']['items'], $table, $fieldName);
$fieldConfig['config']['items'] = $this->sanitizeItemArray($fieldConfig['config']['items'] ?? [], $table, $fieldName);

// Resolve "itemsProcFunc"
if (!empty($fieldConfig['config']['itemsProcFunc'])) {
Expand All @@ -52,7 +52,7 @@ public function addData(array $result)
unset($fieldConfig['config']['itemsProcFunc']);
}

$fieldConfig['config']['maxitems'] = MathUtility::forceIntegerInRange($fieldConfig['config']['maxitems'], 0, 99999);
$fieldConfig['config']['maxitems'] = MathUtility::forceIntegerInRange($fieldConfig['config']['maxitems'] ?? 0, 0, 99999);
if ($fieldConfig['config']['maxitems'] === 0) {
$fieldConfig['config']['maxitems'] = 99999;
}
Expand Down Expand Up @@ -124,8 +124,8 @@ public function addInvalidItemsFromDatabase(array $result, $table, $fieldName, a
// Early return if there are no items or invalid values should not be displayed
if (empty($fieldConf['config']['items'])
|| $fieldConf['config']['renderType'] !== 'selectSingle'
|| $result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['disableNoMatchingValueElement']
|| $fieldConf['config']['disableNoMatchingValueElement']
|| ($result['pageTsConfig']['TCEFORM.'][$table . '.'][$fieldName . '.']['disableNoMatchingValueElement'] ?? false)
|| ($fieldConf['config']['disableNoMatchingValueElement'] ?? false)
) {
return $fieldConf['config']['items'];
}
Expand Down
38 changes: 18 additions & 20 deletions typo3/sysext/backend/Classes/Utility/BackendUtility.php
Expand Up @@ -1869,11 +1869,11 @@ public static function getProcessedValue(
return $value;
}
// Check if table and field is configured
if (!is_array($GLOBALS['TCA'][$table]) || !is_array($GLOBALS['TCA'][$table]['columns'][$col])) {
if (!isset($GLOBALS['TCA'][$table]['columns'][$col]) || !is_array($GLOBALS['TCA'][$table]['columns'][$col])) {
return null;
}
// Depending on the fields configuration, make a meaningful output value.
$theColConf = $GLOBALS['TCA'][$table]['columns'][$col]['config'];
$theColConf = $GLOBALS['TCA'][$table]['columns'][$col]['config'] ?? [];
/*****************
*HOOK: pre-processing the human readable output from a record
****************/
Expand All @@ -1884,7 +1884,7 @@ public static function getProcessedValue(

$l = '';
$lang = static::getLanguageService();
switch ((string)$theColConf['type']) {
switch ((string)($theColConf['type'] ?? '')) {
case 'radio':
$l = self::getLabelFromItemlist($table, $col, $value);
$l = $lang->sL($l);
Expand Down Expand Up @@ -2225,7 +2225,7 @@ public static function getProcessedValue(
default:
if ($defaultPassthrough) {
$l = $value;
} elseif ($theColConf['MM']) {
} elseif (isset($theColConf['MM'])) {
$l = 'N/A';
} elseif ($value) {
$l = GeneralUtility::fixed_lgd_cs(strip_tags($value), 200);
Expand Down Expand Up @@ -2310,7 +2310,7 @@ public static function getCommonSelectFields($table, $prefix = '', $fields = [])
if (isset($GLOBALS['TCA'][$table]['ctrl']['label']) && $GLOBALS['TCA'][$table]['ctrl']['label'] != '') {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['label'];
}
if ($GLOBALS['TCA'][$table]['ctrl']['label_alt']) {
if (!empty($GLOBALS['TCA'][$table]['ctrl']['label_alt'])) {
$secondFields = GeneralUtility::trimExplode(',', $GLOBALS['TCA'][$table]['ctrl']['label_alt'], true);
foreach ($secondFields as $fieldN) {
$fields[] = $prefix . $fieldN;
Expand All @@ -2322,25 +2322,23 @@ public static function getCommonSelectFields($table, $prefix = '', $fields = [])
$fields[] = $prefix . 't3ver_wsid';
$fields[] = $prefix . 't3ver_count';
}
if ($GLOBALS['TCA'][$table]['ctrl']['selicon_field']) {
if (!empty($GLOBALS['TCA'][$table]['ctrl']['selicon_field'])) {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['selicon_field'];
}
if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
if (!empty($GLOBALS['TCA'][$table]['ctrl']['typeicon_column'])) {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
}
if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']) {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
}
if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime']) {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'];
}
if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime']) {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'];
}
if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group']) {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'];
}
if (!empty($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'])) {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'];
}
if (!empty($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'])) {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['starttime'];
}
if (!empty($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'])) {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['endtime'];
}
if (!empty($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'])) {
$fields[] = $prefix . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['fe_group'];
}
return implode(',', array_unique($fields));
}
Expand Down

0 comments on commit 2845b6a

Please sign in to comment.