[TASK] Make Tests/Unit/TypoScript/ notice free 63/57063/7
authorJan Helke <typo3@helke.de>
Mon, 28 May 2018 11:50:57 +0000 (13:50 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 9 Jun 2018 21:36:42 +0000 (23:36 +0200)
Releases: master
Resolves: #85092
Change-Id: I29bb5a3d0546d790d9c8d05c52f448ecefbc8564
Reviewed-on: https://review.typo3.org/57063
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: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/TypoScript/TemplateService.php
typo3/sysext/core/Classes/TypoScript/TypoScriptService.php
typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php
typo3/sysext/core/Tests/Unit/TypoScript/TypoScriptServiceTest.php

index 3ecb690..f6cf18b 100644 (file)
@@ -720,11 +720,11 @@ class TemplateService
     public function processTemplate($row, $idList, $pid, $templateID = '', $templateParent = '', $includePath = '')
     {
         // Adding basic template record information to rowSum array
-        $this->rowSum[] = [$row['uid'], $row['title'], $row['tstamp']];
+        $this->rowSum[] = [$row['uid'] ?? null, $row['title'] ?? null, $row['tstamp'] ?? null];
         // Processing "Clear"-flags
         $clConst = 0;
         $clConf = 0;
-        if ($row['clear']) {
+        if (!empty($row['clear'])) {
             $clConst = $row['clear'] & 1;
             $clConf = $row['clear'] & 2;
             if ($clConst) {
@@ -747,12 +747,14 @@ class TemplateService
         }
         // Include files (from extensions) (#1/2)
         // NORMAL inclusion, The EXACT same code is found below the basedOn inclusion!!!
-        if (!$row['includeStaticAfterBasedOn']) {
+        if (!isset($row['!$row[\'includeStaticAfterBasedOn\']']) ||
+            isset($row['includeStaticAfterBasedOn']) && !$row['includeStaticAfterBasedOn']
+        ) {
             $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row);
         }
         // Include "Based On" sys_templates:
         // 'basedOn' is a list of templates to include
-        if (trim($row['basedOn'])) {
+        if (trim($row['basedOn'] ?? '')) {
             // Normal Operation, which is to include the "based-on" sys_templates,
             // if they are not already included, and maintaining the sorting of the templates
             $basedOnIds = GeneralUtility::intExplode(',', $row['basedOn'], true);
@@ -790,20 +792,20 @@ class TemplateService
             }
         }
         // Include files (from extensions) (#2/2)
-        if ($row['includeStaticAfterBasedOn']) {
+        if (!empty($row['includeStaticAfterBasedOn'])) {
             $this->includeStaticTypoScriptSources($idList, $templateID, $pid, $row);
         }
         // Creating hierarchy information; Used by backend analysis tools
         $this->hierarchyInfo[] = ($this->hierarchyInfoToRoot[] = [
-            'root' => trim($row['root']),
-            'next' => $row['nextLevel'],
+            'root' => trim($row['root'] ?? ''),
+            'next' => $row['nextLevel'] ?? null,
             'clConst' => $clConst,
             'clConf' => $clConf,
             'templateID' => $templateID,
             'templateParent' => $templateParent,
             'title' => $row['title'],
             'uid' => $row['uid'],
-            'pid' => $row['pid'],
+            'pid' => $row['pid'] ?? null,
             'configLines' => substr_count($row['config'], LF) + 1
         ]);
         // Adding the content of the fields constants (Constants) and config (Setup)
@@ -813,16 +815,16 @@ class TemplateService
         // For backend analysis (Template Analyser) provide the order of added constants/config template IDs
         $this->clearList_const[] = $templateID;
         $this->clearList_setup[] = $templateID;
-        if (trim($row['sitetitle'])) {
+        if (trim($row['sitetitle'] ?? null)) {
             $this->sitetitle = $row['sitetitle'];
         }
         // If the template record is a Rootlevel record, set the flag and clear the template rootLine (so it starts over from this point)
-        if (trim($row['root'])) {
+        if (trim($row['root'] ?? null)) {
             $this->rootId = $pid;
             $this->rootLine = [];
         }
         // If a template is set to be active on the next level set this internal value to point to this UID. (See runThroughTemplates())
-        if ($row['nextLevel']) {
+        if ($row['nextLevel'] ?? null) {
             $this->nextLevel = $row['nextLevel'];
         } else {
             $this->nextLevel = 0;
@@ -883,11 +885,12 @@ class TemplateService
             GeneralUtility::callUserFunction($_funcRef, $_params, $this);
         }
         // If "Include before all static templates if root-flag is set" is set:
-        if ($row['static_file_mode'] == 3 && strpos($templateID, 'sys_') === 0 && $row['root']) {
+        $staticFileMode = $row['static_file_mode'] ?? null;
+        if ($staticFileMode == 3 && strpos($templateID, 'sys_') === 0 && $row['root']) {
             $this->addExtensionStatics($idList, $templateID, $pid, $row);
         }
         // Static Template Files (Text files from extensions): include_static_file is a list of static files to include (from extensions)
-        if (trim($row['include_static_file'])) {
+        if (trim($row['include_static_file'] ?? '')) {
             $include_static_fileArr = GeneralUtility::trimExplode(',', $row['include_static_file'], true);
             // Traversing list
             foreach ($include_static_fileArr as $ISF_file) {
@@ -915,7 +918,7 @@ class TemplateService
         }
         // If "Default (include before if root flag is set)" is set OR
         // "Always include before this template record" AND root-flag are set
-        if ($row['static_file_mode'] == 1 || $row['static_file_mode'] == 0 && substr($templateID, 0, 4) === 'sys_' && $row['root']) {
+        if ($staticFileMode == 1 || $staticFileMode == 0 && substr($templateID, 0, 4) === 'sys_' && $row['root']) {
             $this->addExtensionStatics($idList, $templateID, $pid, $row);
         }
         // Include Static Template Records after all other TypoScript has been included.
@@ -1020,8 +1023,8 @@ class TemplateService
     {
         // the identifier can be "43" if coming from "static template" extension or a path like "cssstyledcontent/static/"
         $identifier = $subrow['uid'];
-        $subrow['config'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$identifier];
-        $subrow['constants'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$identifier];
+        $subrow['config'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.'][$identifier] ?? null;
+        $subrow['constants'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants.'][$identifier] ?? null;
         // if this is a template of type "default content rendering", also see if other extensions have added their TypoScript that should be included after the content definitions
         if (in_array($identifier, $GLOBALS['TYPO3_CONF_VARS']['FE']['contentRenderingTemplates'], true)) {
             $subrow['config'] .= $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup.']['defaultContentRendering'];
@@ -1700,7 +1703,7 @@ class TemplateService
             array_unshift($this->config, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
             array_unshift($this->templateIncludePaths, '');
             // prepare a proper entry to hierachyInfo (used by TemplateAnalyzer in BE)
-            $rootTemplateId = $this->hierarchyInfo[count($this->hierarchyInfo) - 1]['templateID'];
+            $rootTemplateId = $this->hierarchyInfo[count($this->hierarchyInfo) - 1]['templateID'] ?? null;
             $defaultTemplateInfo = [
                 'root' => '',
                 'next' => '',
index 7f29127..31239d0 100644 (file)
@@ -124,13 +124,13 @@ class TypoScriptService
                         $firstC = count($first);
                     }
                     $middle = [];
-                    if ($main[1]) {
+                    if (!empty($main[1])) {
                         $middle = explode('||', $main[1]);
                         $middleC = count($middle);
                     }
                     $last = [];
                     $value = '';
-                    if ($main[2]) {
+                    if (!empty($main[2])) {
                         $last = explode('||', $main[2]);
                         $lastC = count($last);
                         $value = $last[0];
index c7dd0aa..e81bf52 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Core\Tests\Unit\TypoScript;
 
 /*
@@ -17,44 +19,48 @@ namespace TYPO3\CMS\Core\Tests\Unit\TypoScript;
 use Prophecy\Argument;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
+use TYPO3\CMS\Core\Package\Package;
+use TYPO3\CMS\Core\Package\PackageManager;
 use TYPO3\CMS\Core\Tests\Unit\Utility\AccessibleProxies\ExtensionManagementUtilityAccessibleProxy;
+use TYPO3\CMS\Core\TypoScript\TemplateService;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Frontend\Page\PageRepository;
+use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 
 /**
  * Testcase for \TYPO3\CMS\Core\TypoScript\TemplateService
  */
-class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
+class TemplateServiceTest extends UnitTestCase
 {
     /**
-     * Subject is not notice free, disable E_NOTICES
-     */
-    protected static $suppressNotices = true;
-
-    /**
-     * @var \TYPO3\CMS\Core\TypoScript\TemplateService
+     * @var TemplateService
      */
     protected $templateService;
 
     /**
-     * @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|\TYPO3\CMS\Core\TypoScript\TemplateService
+     * @var \PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface|TemplateService
      */
     protected $templateServiceMock;
 
     /**
-     * @var \TYPO3\CMS\Core\Package\PackageManager
+     * @var PackageManager
      */
     protected $backupPackageManager;
 
     /**
      * Set up
      */
-    protected function setUp()
+    protected function setUp(): void
     {
         $GLOBALS['TYPO3_LOADED_EXT'] = [];
-        $this->templateService = new \TYPO3\CMS\Core\TypoScript\TemplateService();
+        $this->templateService = new TemplateService();
         $this->templateService->tt_track = false;
-        $this->templateServiceMock = $this->getAccessibleMock(\TYPO3\CMS\Core\TypoScript\TemplateService::class, ['dummy']);
+        $this->templateServiceMock = $this->getAccessibleMock(
+            TemplateService::class,
+            ['dummy']
+        );
         $this->templateServiceMock->tt_track = false;
         $this->backupPackageManager = ExtensionManagementUtilityAccessibleProxy::getPackageManager();
     }
@@ -62,7 +68,7 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * Tear down
      */
-    public function tearDown()
+    public function tearDown(): void
     {
         ExtensionManagementUtilityAccessibleProxy::setPackageManager($this->backupPackageManager);
         parent::tearDown();
@@ -71,11 +77,11 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
-    public function versionOlCallsVersionOlOfPageSelectClassWithGivenRow()
+    public function versionOlCallsVersionOlOfPageSelectClassWithGivenRow(): void
     {
         $row = ['foo'];
         $GLOBALS['TSFE'] = new \stdClass();
-        $sysPageMock = $this->createMock(\TYPO3\CMS\Frontend\Page\PageRepository::class);
+        $sysPageMock = $this->createMock(PageRepository::class);
         $sysPageMock->expects($this->once())->method('versionOL')->with('sys_template', $row);
         $GLOBALS['TSFE']->sys_page = $sysPageMock;
         $this->templateService->versionOL($row);
@@ -84,7 +90,7 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
-    public function extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested()
+    public function extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested(): void
     {
         $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
         $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
@@ -103,14 +109,14 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
 
         $this->templateService->runThroughTemplates([], 0);
         $this->assertFalse(
-            in_array('test.Core.TypoScript = 1', $this->templateService->config)
+            in_array('test.Core.TypoScript = 1', $this->templateService->config, true)
         );
     }
 
     /**
      * @test
      */
-    public function extensionStaticsAreProcessedIfExplicitlyRequested()
+    public function extensionStaticsAreProcessedIfExplicitlyRequested(): void
     {
         $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
         $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
@@ -121,20 +127,20 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $GLOBALS['TYPO3_LOADED_EXT'] = [
             $identifier => [
                 'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
-                        'core',
+                    'core',
                     'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
-                    ),
+                ),
                 'ext_typoscript_constants.txt' => ''
             ],
         ];
 
-        $mockPackage = $this->getMockBuilder(\TYPO3\CMS\Core\Package\Package::class)
+        $mockPackage = $this->getMockBuilder(Package::class)
             ->setMethods(['getPackagePath'])
             ->disableOriginalConstructor()
             ->getMock();
         $mockPackage->expects($this->any())->method('getPackagePath')->will($this->returnValue(''));
 
-        $mockPackageManager = $this->getMockBuilder(\TYPO3\CMS\Core\Package\PackageManager::class)
+        $mockPackageManager = $this->getMockBuilder(PackageManager::class)
             ->setMethods(['isPackageActive', 'getPackage'])
             ->disableOriginalConstructor()
             ->getMock();
@@ -146,14 +152,14 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $this->templateService->runThroughTemplates([], 0);
 
         $this->assertTrue(
-            in_array('test.Core.TypoScript = 1', $this->templateService->config)
+            in_array('test.Core.TypoScript = 1', $this->templateService->config, true)
         );
     }
 
     /**
      * @test
      */
-    public function updateRootlineDataOverwritesOwnArrayData()
+    public function updateRootlineDataOverwritesOwnArrayData(): void
     {
         $originalRootline = [
             0 => ['uid' => 2, 'title' => 'originalTitle'],
@@ -179,7 +185,7 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
-    public function updateRootlineDataWithInvalidNewRootlineThrowsException()
+    public function updateRootlineDataWithInvalidNewRootlineThrowsException(): void
     {
         $originalRootline = [
             0 => ['uid' => 2, 'title' => 'originalTitle'],
@@ -201,7 +207,7 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
-    public function getFileNameReturnsUrlCorrectly()
+    public function getFileNameReturnsUrlCorrectly(): void
     {
         $this->assertSame('http://example.com', $this->templateService->getFileName('http://example.com'));
         $this->assertSame('https://example.com', $this->templateService->getFileName('https://example.com'));
@@ -210,7 +216,7 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
-    public function getFileNameReturnsFileCorrectly()
+    public function getFileNameReturnsFileCorrectly(): void
     {
         $this->assertSame('typo3/index.php', $this->templateService->getFileName('typo3/index.php'));
     }
@@ -218,7 +224,7 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
-    public function getFileNameReturnsNullIfDirectory()
+    public function getFileNameReturnsNullIfDirectory(): void
     {
         $this->assertNull($this->templateService->getFileName(__DIR__));
     }
@@ -226,7 +232,7 @@ class TemplateServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     /**
      * @test
      */
-    public function getFileNameReturnsNullWithInvalidFileName()
+    public function getFileNameReturnsNullWithInvalidFileName(): void
     {
         $this->assertNull($this->templateService->getFileName('  '));
         $this->assertNull($this->templateService->getFileName('something/../else'));
index 7859282..c8445a5 100644 (file)
@@ -1,4 +1,6 @@
 <?php
+declare(strict_types = 1);
+
 namespace TYPO3\CMS\Core\Tests\Unit\TypoScript;
 
 /*
@@ -23,15 +25,10 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
 class TypoScriptServiceTest extends UnitTestCase
 {
     /**
-     * Subject is not notice free, disable E_NOTICES
-     */
-    protected static $suppressNotices = true;
-
-    /**
      * data provider for convertTypoScriptArrayToPlainArray
      * @return array
      */
-    public function convertTypoScriptArrayToPlainArrayTestdata()
+    public function convertTypoScriptArrayToPlainArrayTestdata(): array
     {
         return [
             'simple typoscript array' => [
@@ -157,8 +154,10 @@ class TypoScriptServiceTest extends UnitTestCase
      * @param mixed $typoScriptSettings
      * @param mixed $expectedSettings
      */
-    public function convertTypoScriptArrayToPlainArrayRemovesTrailingDotsWithChangedOrderInTheTypoScriptArray($typoScriptSettings, $expectedSettings)
-    {
+    public function convertTypoScriptArrayToPlainArrayRemovesTrailingDotsWithChangedOrderInTheTypoScriptArray(
+        $typoScriptSettings,
+        $expectedSettings
+    ): void {
         $typoScriptService = new TypoScriptService();
         $processedSettings = $typoScriptService->convertTypoScriptArrayToPlainArray($typoScriptSettings);
         $this->assertEquals($expectedSettings, $processedSettings);
@@ -169,7 +168,7 @@ class TypoScriptServiceTest extends UnitTestCase
      *
      * @return array
      */
-    public function convertPlainArrayToTypoScriptArrayTestdata()
+    public function convertPlainArrayToTypoScriptArrayTestdata(): array
     {
         return [
             'simple typoscript' => [
@@ -291,7 +290,7 @@ class TypoScriptServiceTest extends UnitTestCase
      * @param mixed $extbaseTS
      * @param mixed $classic
      */
-    public function convertPlainArrayToTypoScriptArray($extbaseTS, $classic)
+    public function convertPlainArrayToTypoScriptArray($extbaseTS, $classic): void
     {
         $typoScriptService = new TypoScriptService();
         $converted = $typoScriptService->convertPlainArrayToTypoScriptArray($extbaseTS);
@@ -301,7 +300,7 @@ class TypoScriptServiceTest extends UnitTestCase
     /**
      * @return array
      */
-    public function explodeConfigurationForOptionSplitProvider()
+    public function explodeConfigurationForOptionSplitProvider(): array
     {
         return [
             [
@@ -414,7 +413,7 @@ class TypoScriptServiceTest extends UnitTestCase
      * @dataProvider explodeConfigurationForOptionSplitProvider
      * @see https://docs.typo3.org/typo3cms/TyposcriptReference/ObjectsAndProperties/Index.html#objects-optionsplit
      */
-    public function explodeConfigurationForOptionSplitTest($configuration, $splitCount, $expected)
+    public function explodeConfigurationForOptionSplitTest($configuration, $splitCount, $expected): void
     {
         $serviceObject = new TypoScriptService();
         $actual = $serviceObject->explodeConfigurationForOptionSplit($configuration, $splitCount);