[TASK] Make CacheHashCalculatorTest notice free 44/56344/5
authorSascha Löffler <lsascha@gmail.com>
Sun, 18 Mar 2018 09:17:54 +0000 (10:17 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 18 Mar 2018 11:29:33 +0000 (12:29 +0100)
Resolves: #84461
Releases: master
Change-Id: I914baeb2ee4b884d0c0656762973d71e2b8e69a3
Reviewed-on: https://review.typo3.org/56344
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/frontend/Classes/Page/CacheHashCalculator.php
typo3/sysext/frontend/Tests/Unit/Page/CacheHashCalculatorTest.php

index 499014d..7646d4c 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Frontend\Page;
  */
 
 use TYPO3\CMS\Core\SingletonInterface;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Logic for cHash calculation
@@ -151,7 +152,10 @@ class CacheHashCalculator implements SingletonInterface
         $parameters = array_filter(explode('&', ltrim($queryString, '?')));
         $parameterArray = [];
         foreach ($parameters as $parameter) {
-            list($parameterName, $parameterValue) = explode('=', $parameter);
+            // should not remove empty values with trimExplode, otherwise cases like &=value, value is used as parameterName.
+            $parts = GeneralUtility::trimExplode('=', $parameter, false);
+            $parameterName = $parts[0];
+            $parameterValue = $parts[1] ?? '';
             if (trim($parameterName) === '') {
                 // This parameter cannot appear in $_GET in PHP even if its value is not empty, so it should be ignored!
                 continue;
index efdba66..1a578b5 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+declare(strict_types = 1);
 namespace TYPO3\CMS\Frontend\Tests\Unit\Page;
 
 /*
@@ -14,17 +15,15 @@ namespace TYPO3\CMS\Frontend\Tests\Unit\Page;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Frontend\Page\CacheHashCalculator;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
 /**
  * Testcase
  */
-class CacheHashCalculatorTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
+class CacheHashCalculatorTest extends UnitTestCase
 {
     /**
-     * Subject is not notice free, disable E_NOTICES
-     */
-    protected static $suppressNotices = true;
-
-    /**
      * @var \TYPO3\CMS\Frontend\Page\CacheHashCalculator
      */
     protected $subject;
@@ -32,7 +31,7 @@ class CacheHashCalculatorTest extends \TYPO3\TestingFramework\Core\Unit\UnitTest
     protected function setUp()
     {
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 't3lib_cacheHashTest';
-        $this->subject = $this->getMockBuilder(\TYPO3\CMS\Frontend\Page\CacheHashCalculator::class)
+        $this->subject = $this->getMockBuilder(CacheHashCalculator::class)
             ->setMethods(['foo'])
             ->getMock();
         $this->subject->setConfiguration([
@@ -115,7 +114,7 @@ class CacheHashCalculatorTest extends \TYPO3\TestingFramework\Core\Unit\UnitTest
                 ['encryptionKey', 'id', 'key']
             ],
             'System and exclude parameters should be omitted and id is not required to be specified' => [
-                '&type=3&no_cache=1',
+                'type=3&no_cache=1',
                 []
             ]
         ];
@@ -193,7 +192,7 @@ class CacheHashCalculatorTest extends \TYPO3\TestingFramework\Core\Unit\UnitTest
      */
     public function canWhitelistParameters($params, $expected)
     {
-        $method = new \ReflectionMethod(\TYPO3\CMS\Frontend\Page\CacheHashCalculator::class, 'setCachedParametersWhiteList');
+        $method = new \ReflectionMethod(CacheHashCalculator::class, 'setCachedParametersWhiteList');
         $method->setAccessible(true);
         $method->invoke($this->subject, ['whitep1', 'whitep2']);
         $this->assertEquals($expected, $this->subject->generateForParameters($params));