[TASK] Make DataHandler tests notice free 13/57913/7
authorWouter Wolters <typo3@wouterwolters.nl>
Wed, 15 Aug 2018 13:12:12 +0000 (15:12 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 16 Aug 2018 10:37:30 +0000 (12:37 +0200)
Resolves: #85862
Releases: master
Change-Id: I19ef49799b2a5a0704072b1758ceba7a28aaee5f
Reviewed-on: https://review.typo3.org/57913
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Classes/Utility/GeneralUtility.php
typo3/sysext/core/Tests/Unit/DataHandling/DataHandlerTest.php

index 4789e28..f0bdead 100644 (file)
@@ -1102,11 +1102,11 @@ class DataHandler implements LoggerAwareInterface
                         $this->newlog('recordEditAccessInternals() check failed. [' . $this->BE_USER->errorMsg . ']', 1);
                     } else {
                         // Here we fetch the PID of the record that we point to...
-                        $tempdata = $this->recordInfo($table, $id, 'pid' . ($GLOBALS['TCA'][$table]['ctrl']['versioningWS'] ? ',t3ver_wsid,t3ver_stage' : ''));
+                        $tempdata = $this->recordInfo($table, $id, 'pid' . (!empty($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) ? ',t3ver_wsid,t3ver_stage' : ''));
                         $theRealPid = $tempdata['pid'];
                         // Use the new id of the versionized record we're trying to write to:
                         // (This record is a child record of a parent and has already been versionized.)
-                        if ($this->autoVersionIdMap[$table][$id]) {
+                        if (!empty($this->autoVersionIdMap[$table][$id])) {
                             // For the reason that creating a new version of this record, automatically
                             // created related child records (e.g. "IRRE"), update the accordant field:
                             $this->getVersionizedIncomingFieldArray($table, $id, $incomingFieldArray, $registerDBList);
@@ -1140,7 +1140,7 @@ class DataHandler implements LoggerAwareInterface
                                 $tce->process_cmdmap();
                                 $this->errorLog = array_merge($this->errorLog, $tce->errorLog);
                                 // If copying was successful, share the new uids (also of related children):
-                                if ($tce->copyMappingArray[$table][$id]) {
+                                if (!empty($tce->copyMappingArray[$table][$id])) {
                                     foreach ($tce->copyMappingArray as $origTable => $origIdArray) {
                                         foreach ($origIdArray as $origId => $newId) {
                                             $this->uploadedFileArray[$origTable][$newId] = $this->uploadedFileArray[$origTable][$origId];
@@ -1861,7 +1861,7 @@ class DataHandler implements LoggerAwareInterface
             }
         }
         // Secures the string-length to be less than max.
-        if ((int)$tcaFieldConf['max'] > 0) {
+        if (isset($tcaFieldConf['max']) && (int)$tcaFieldConf['max'] > 0) {
             $value = mb_substr((string)$value, 0, (int)$tcaFieldConf['max'], 'utf-8');
         }
 
@@ -1876,7 +1876,7 @@ class DataHandler implements LoggerAwareInterface
                 $this->runtimeCache->set($cacheId, $evalCodesArray);
             }
 
-            $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in'], $table);
+            $res = $this->checkValue_input_Eval($value, $evalCodesArray, $tcaFieldConf['is_in'] ?? '', $table);
             if (isset($tcaFieldConf['dbType']) && isset($res['value']) && !$res['value']) {
                 // set the value to null if we have an empty value for a native field
                 $res['value'] = null;
@@ -1896,7 +1896,11 @@ class DataHandler implements LoggerAwareInterface
 
         // Checking range of value:
         // @todo: The "checkbox" option was removed for type=input, this check could be probably relaxed?
-        if ($tcaFieldConf['range'] && $res['value'] != $tcaFieldConf['checkbox'] && (int)$res['value'] !== (int)$tcaFieldConf['default']) {
+        if (
+            isset($tcaFieldConf['range']) && $tcaFieldConf['range']
+            && (!isset($tcaFieldConf['checkbox']) || $res['value'] != $tcaFieldConf['checkbox'])
+            && (!isset($tcaFieldConf['default']) || (int)$res['value'] !== (int)$tcaFieldConf['default'])
+        ) {
             if (isset($tcaFieldConf['range']['upper']) && (int)$res['value'] > (int)$tcaFieldConf['range']['upper']) {
                 $res['value'] = (int)$tcaFieldConf['range']['upper'];
             }
@@ -1928,7 +1932,7 @@ class DataHandler implements LoggerAwareInterface
     protected function checkValueForCheck($res, $value, $tcaFieldConf, $table, $id, $realPid, $field)
     {
         $items = $tcaFieldConf['items'];
-        if ($tcaFieldConf['itemsProcFunc']) {
+        if (!empty($tcaFieldConf['itemsProcFunc'])) {
             /** @var ItemProcessingService $processingService */
             $processingService = GeneralUtility::makeInstance(ItemProcessingService::class);
             $items = $processingService->getProcessingItems(
@@ -2485,7 +2489,7 @@ class DataHandler implements LoggerAwareInterface
             }
             // Remove all old meta for languages...
             // Evaluation of input values:
-            $value['data'] = $this->checkValue_flex_procInData($value['data'], $currentValueArray['data'], $uploadedFiles['data'], $dataStructureArray, [$table, $id, $curValue, $status, $realPid, $recFID, $tscPID]);
+            $value['data'] = $this->checkValue_flex_procInData($value['data'] ?? [], $currentValueArray['data'] ?? [], $uploadedFiles['data'] ?? [], $dataStructureArray, [$table, $id, $curValue, $status, $realPid, $recFID, $tscPID]);
             // Create XML from input value:
             $xmlValue = $this->checkValue_flexArray2Xml($value, true);
 
@@ -6468,7 +6472,7 @@ class DataHandler implements LoggerAwareInterface
      */
     public function checkModifyAccessList($table)
     {
-        $res = $this->admin || !$this->tableAdminOnly($table) && GeneralUtility::inList($this->BE_USER->groupData['tables_modify'], $table);
+        $res = $this->admin || (!$this->tableAdminOnly($table) && isset($this->BE_USER->groupData['tables_modify']) && GeneralUtility::inList($this->BE_USER->groupData['tables_modify'], $table));
         // Hook 'checkModifyAccessList': Post-processing of the state of access
         foreach ($this->getCheckModifyAccessListHookObjects() as $hookObject) {
             /** @var $hookObject DataHandlerCheckModifyAccessListHookInterface */
@@ -6762,7 +6766,7 @@ class DataHandler implements LoggerAwareInterface
     public function tableAdminOnly($table)
     {
         // Returns TRUE if table is admin-only
-        return (bool)$GLOBALS['TCA'][$table]['ctrl']['adminOnly'];
+        return !empty($GLOBALS['TCA'][$table]['ctrl']['adminOnly']);
     }
 
     /**
@@ -6812,16 +6816,19 @@ class DataHandler implements LoggerAwareInterface
     public function getExcludeListArray()
     {
         $list = [];
-        $nonExcludeFieldsArray = array_flip(GeneralUtility::trimExplode(',', $this->BE_USER->groupData['non_exclude_fields']));
-        foreach ($GLOBALS['TCA'] as $table => $tableConfiguration) {
-            if (isset($tableConfiguration['columns'])) {
-                foreach ($tableConfiguration['columns'] as $field => $config) {
-                    if ($config['exclude'] && !isset($nonExcludeFieldsArray[$table . ':' . $field])) {
-                        $list[] = $table . '-' . $field;
+        if (isset($this->BE_USER->groupData['non_exclude_fields'])) {
+            $nonExcludeFieldsArray = array_flip(GeneralUtility::trimExplode(',', $this->BE_USER->groupData['non_exclude_fields']));
+            foreach ($GLOBALS['TCA'] as $table => $tableConfiguration) {
+                if (isset($tableConfiguration['columns'])) {
+                    foreach ($tableConfiguration['columns'] as $field => $config) {
+                        if ($config['exclude'] && !isset($nonExcludeFieldsArray[$table . ':' . $field])) {
+                            $list[] = $table . '-' . $field;
+                        }
                     }
                 }
             }
         }
+
         return $list;
     }
 
index 82fe085..127fb13 100644 (file)
@@ -1557,7 +1557,7 @@ class GeneralUtility
                     $content = htmlspecialchars($v);
                     $dType = gettype($v);
                     if ($dType === 'string') {
-                        if ($options['useCDATA'] && $content != $v) {
+                        if (isset($options['useCDATA']) && $options['useCDATA'] && $content != $v) {
                             $content = '<![CDATA[' . $v . ']]>';
                         }
                     } elseif (!$options['disableTypeAttrib']) {
index ed4e018..bf5872c 100644 (file)
@@ -32,10 +32,6 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
  */
 class DataHandlerTest extends UnitTestCase
 {
-    /**
-     * Subject is not notice free, disable E_NOTICES
-     */
-    protected static $suppressNotices = true;
 
     /**
      * @var bool Reset singletons created by subject
@@ -955,12 +951,10 @@ class DataHandlerTest extends UnitTestCase
      */
     public function checkValueForInputConvertsNullToEmptyString()
     {
-        $previousLanguageService = $GLOBALS['LANG'];
         $GLOBALS['LANG'] = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\LanguageService::class);
         $GLOBALS['LANG']->init('default');
         $expectedResult = ['value' => ''];
         $this->assertSame($expectedResult, $this->subject->_call('checkValueForInput', null, ['type' => 'string', 'max' => 40], 'tt_content', 'NEW55c0e67f8f4d32.04974534', 89, 'table_caption'));
-        $GLOBALS['LANG'] = $previousLanguageService;
     }
 
     /**