[TASK] Make frontend/Tests/Unit/Controller notice free 02/57902/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 14 Aug 2018 18:59:59 +0000 (20:59 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Tue, 14 Aug 2018 19:15:52 +0000 (21:15 +0200)
Resolves: #85851
Releases: master
Change-Id: I8e9ac42b8176a0b37237ecd65a67efe8f8db8c82
Reviewed-on: https://review.typo3.org/57902
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Context/LanguageAspectFactory.php
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/Controller/TypoScriptFrontendController.php
typo3/sysext/frontend/Tests/Unit/Controller/TypoScriptFrontendControllerTest.php

index a53918b..acb0441 100644 (file)
@@ -36,11 +36,19 @@ class LanguageAspectFactory
     public static function createFromTypoScript(array $config): LanguageAspect
     {
         // Get values from TypoScript, if not set before
-        $languageId = (int)$config['sys_language_uid'];
-        list($fallbackMode, $fallbackOrder) = GeneralUtility::trimExplode(';', $config['sys_language_mode']);
+        $languageId = (int)($config['sys_language_uid'] ?? 0);
+        $fallbacks = GeneralUtility::trimExplode(';', $config['sys_language_mode'] ?? '');
+        $fallbackMode = null;
+        if (isset($fallbacks[0])) {
+            $fallbackMode = $fallbacks[0];
+        }
+        $fallbackOrder = null;
+        if (isset($fallbacks[1])) {
+            $fallbackOrder = $fallbacks[1];
+        }
 
         // Page resolving
-        switch ($fallbackMode ?? '') {
+        switch ($fallbackMode) {
             case 'strict':
                 $fallBackOrder = [];
                 break;
@@ -68,7 +76,7 @@ class LanguageAspectFactory
         }
 
         // Content fetching
-        switch ((string)$config['sys_language_overlay'] ?? '') {
+        switch ((string)($config['sys_language_overlay'] ?? '')) {
             case '1':
                 $overlayType = LanguageAspect::OVERLAYS_MIXED;
                 break;
index e19c884..fa4d39c 100644 (file)
@@ -550,7 +550,9 @@ class ContentObjectRenderer implements LoggerAwareInterface
     {
         $this->data = $data;
         $this->table = $table;
-        $this->currentRecord = $table !== '' ? $table . ':' . $this->data['uid'] : '';
+        $this->currentRecord = $table !== ''
+            ? $table . ':' . ($this->data['uid'] ?? '')
+            : '';
         $this->parameters = [];
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['cObjTypeAndClass'] ?? [] as $classArr) {
             $this->cObjHookObjectsRegistry[$classArr[0]] = $classArr[1];
index 893b79a..9a242c9 100644 (file)
@@ -2718,7 +2718,9 @@ class TypoScriptFrontendController implements LoggerAwareInterface
         // Setting sys_language_uid inside sys-page by creating a new page repository
         $this->sys_page = GeneralUtility::makeInstance(PageRepository::class, $this->context);
         // If default translation is not available:
-        if ((!$languageAspect->getContentId() || !$languageAspect->getId()) && GeneralUtility::hideIfDefaultLanguage($this->page['l18n_cfg'])) {
+        if ((!$languageAspect->getContentId() || !$languageAspect->getId())
+            && GeneralUtility::hideIfDefaultLanguage($this->page['l18n_cfg'] ?? 0)
+        ) {
             $message = 'Page is not available in default language.';
             $this->logger->error($message);
             $response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
@@ -3402,7 +3404,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
     public function preparePageContentGeneration()
     {
         $this->getTimeTracker()->push('Prepare page content generation');
-        if ($this->page['content_from_pid'] > 0) {
+        if (isset($this->page['content_from_pid']) && $this->page['content_from_pid'] > 0) {
             // make REAL copy of TSFE object - not reference!
             $temp_copy_TSFE = clone $this;
             // Set ->id to the content_from_pid value - we are going to evaluate this pid as was it a given id for a page-display!
@@ -3412,7 +3414,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
             $this->contentPid = (int)$temp_copy_TSFE->id;
             unset($temp_copy_TSFE);
         }
-        if ($this->config['config']['MP_defaults']) {
+        if ($this->config['config']['MP_defaults'] ?? false) {
             $temp_parts = GeneralUtility::trimExplode('|', $this->config['config']['MP_defaults'], true);
             foreach ($temp_parts as $temp_p) {
                 list($temp_idP, $temp_MPp) = explode(':', $temp_p, 2);
@@ -3423,20 +3425,19 @@ class TypoScriptFrontendController implements LoggerAwareInterface
             }
         }
         // Global vars...
-        $this->indexedDocTitle = $this->page['title'];
+        $this->indexedDocTitle = $this->page['title'] ?? null;
         $this->debug = !empty($this->config['config']['debug']);
         // Base url:
         if (isset($this->config['config']['baseURL'])) {
             $this->baseUrl = $this->config['config']['baseURL'];
         }
         // Internal and External target defaults
-        $this->intTarget = '' . $this->config['config']['intTarget'];
-        $this->extTarget = '' . $this->config['config']['extTarget'];
-        $this->fileTarget = '' . $this->config['config']['fileTarget'];
-        if ($this->config['config']['spamProtectEmailAddresses'] === 'ascii') {
-            $this->spamProtectEmailAddresses = 'ascii';
-        } else {
-            $this->spamProtectEmailAddresses = MathUtility::forceIntegerInRange($this->config['config']['spamProtectEmailAddresses'], -10, 10, 0);
+        $this->intTarget = (string)($this->config['config']['intTarget'] ?? '');
+        $this->extTarget = (string)($this->config['config']['extTarget'] ?? '');
+        $this->fileTarget = (string)($this->config['config']['fileTarget'] ?? '');
+        $this->spamProtectEmailAddresses = $this->config['config']['spamProtectEmailAddresses'] ?? 0;
+        if ($this->spamProtectEmailAddresses !== 'ascii') {
+            $this->spamProtectEmailAddresses = MathUtility::forceIntegerInRange($this->spamProtectEmailAddresses, -10, 10, 0);
         }
         // calculate the absolute path prefix
         if (!empty($this->config['config']['absRefPrefix'])) {
@@ -3449,13 +3450,13 @@ class TypoScriptFrontendController implements LoggerAwareInterface
         } else {
             $this->absRefPrefix = '';
         }
-        $this->ATagParams = trim($this->config['config']['ATagParams']) ? ' ' . trim($this->config['config']['ATagParams']) : '';
+        $this->ATagParams = trim($this->config['config']['ATagParams'] ?? '') ? ' ' . trim($this->config['config']['ATagParams']) : '';
         $this->initializeSearchWordDataInTsfe();
         // linkVars
         $this->calculateLinkVars();
         // Setting XHTML-doctype from doctype
-        if (!$this->config['config']['xhtmlDoctype']) {
-            $this->config['config']['xhtmlDoctype'] = $this->config['config']['doctype'];
+        if (!isset($this->config['config']['xhtmlDoctype']) || !$this->config['config']['xhtmlDoctype']) {
+            $this->config['config']['xhtmlDoctype'] = $this->config['config']['doctype'] ?? '';
         }
         if ($this->config['config']['xhtmlDoctype']) {
             $this->xhtmlDoctype = $this->config['config']['xhtmlDoctype'];
@@ -3581,11 +3582,11 @@ class TypoScriptFrontendController implements LoggerAwareInterface
 
         $titleTagContent = $this->printTitle(
             $pageTitle,
-            (bool)$this->config['config']['noPageTitle'],
-            (bool)$this->config['config']['pageTitleFirst'],
+            (bool)($this->config['config']['noPageTitle'] ?? false),
+            (bool)($this->config['config']['pageTitleFirst'] ?? false),
             $pageTitleSeparator
         );
-        if ($this->config['config']['titleTagFunction']) {
+        if ($this->config['config']['titleTagFunction'] ?? false) {
             $titleTagContent = $this->cObj->callUserFunction(
                 $this->config['config']['titleTagFunction'],
                 [],
@@ -3598,7 +3599,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface
         }
 
         // config.noPageTitle = 2 - means do not render the page title
-        if ((int)$this->config['config']['noPageTitle'] === 2) {
+        if (isset($this->config['config']['noPageTitle']) && (int)$this->config['config']['noPageTitle'] === 2) {
             $titleTagContent = '';
         }
         if ($titleTagContent !== '') {
@@ -3643,10 +3644,14 @@ class TypoScriptFrontendController implements LoggerAwareInterface
     {
         // Deprecated stuff:
         // @deprecated: annotation added TYPO3 4.6
-        $this->additionalHeaderData = is_array($this->config['INTincScript_ext']['additionalHeaderData']) ? $this->config['INTincScript_ext']['additionalHeaderData'] : [];
-        $this->additionalFooterData = is_array($this->config['INTincScript_ext']['additionalFooterData']) ? $this->config['INTincScript_ext']['additionalFooterData'] : [];
-        $this->additionalJavaScript = $this->config['INTincScript_ext']['additionalJavaScript'];
-        $this->additionalCSS = $this->config['INTincScript_ext']['additionalCSS'];
+        $this->additionalHeaderData = (isset($this->config['INTincScript_ext']['additionalHeaderData']) && is_array($this->config['INTincScript_ext']['additionalHeaderData']))
+            ? $this->config['INTincScript_ext']['additionalHeaderData']
+            : [];
+        $this->additionalFooterData = (isset($this->config['INTincScript_ext']['additionalFooterData']) && is_array($this->config['INTincScript_ext']['additionalFooterData']))
+            ? $this->config['INTincScript_ext']['additionalFooterData']
+            : [];
+        $this->additionalJavaScript = $this->config['INTincScript_ext']['additionalJavaScript'] ?? null;
+        $this->additionalCSS = $this->config['INTincScript_ext']['additionalCSS'] ?? null;
         $this->divSection = '';
         if (empty($this->config['INTincScript_ext']['pageRenderer'])) {
             $this->initPageRenderer();
@@ -3692,7 +3697,8 @@ class TypoScriptFrontendController implements LoggerAwareInterface
             $INTiS_config = $this->config['INTincScript'];
             $this->INTincScript_process($INTiS_config);
             // Check if there were new items added to INTincScript during the previous execution:
-            $INTiS_config = array_diff_assoc($this->config['INTincScript'], $INTiS_config);
+            // array_diff_assoc throws notices if values are arrays but not strings. We suppress this here.
+            $INTiS_config = @array_diff_assoc($this->config['INTincScript'], $INTiS_config);
             $reprocess = count($INTiS_config) > 0;
         } while ($reprocess);
     }
@@ -4920,7 +4926,8 @@ class TypoScriptFrontendController implements LoggerAwareInterface
      */
     protected function getCurrentSiteLanguage(): ?SiteLanguage
     {
-        if ($GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface
+        if (isset($GLOBALS['TYPO3_REQUEST'])
+            && $GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface
             && $GLOBALS['TYPO3_REQUEST']->getAttribute('language') instanceof SiteLanguage) {
             return $GLOBALS['TYPO3_REQUEST']->getAttribute('language');
         }
index 65e1f6f..ef34c1c 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types = 1);
 namespace TYPO3\CMS\Frontend\Tests\Unit\Controller;
 
 /*
@@ -32,11 +33,6 @@ class TypoScriptFrontendControllerTest extends UnitTestCase
     protected $resetSingletonInstances = true;
 
     /**
-     * Subject is not notice free, disable E_NOTICES
-     */
-    protected static $suppressNotices = true;
-
-    /**
      * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|TypoScriptFrontendController
      */
     protected $subject;