[TASK] Change $fixture to $subject in unit-tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / Page / CacheHashCalculatorTest.php
index 6e05af2..a297168 100644 (file)
@@ -1,28 +1,18 @@
 <?php
 namespace TYPO3\CMS\Frontend\Tests\Unit\Page;
 
-/***************************************************************
- *  Copyright notice
+/*
+ * This file is part of the TYPO3 CMS project.
  *
- *  (c) 2012-2013 Tolleiv Nietsch <typo3@tolleiv.de>
- *  All rights reserved
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
  *
- *  This script is part of the TYPO3 project. The TYPO3 project is
- *  free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
  *
- *  The GNU General Public License can be found at
- *  http://www.gnu.org/copyleft/gpl.html.
- *
- *  This script is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
+ * The TYPO3 project - inspiring people to share!
+ */
 
 /**
  * Testcase
@@ -34,20 +24,20 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        /**
         * @var \TYPO3\CMS\Frontend\Page\CacheHashCalculator
         */
-       protected $fixture;
+       protected $subject;
 
        /**
         * @var array
         */
        protected $confCache = array();
 
-       public function setUp() {
+       protected function setUp() {
                $this->confCache = array(
                        'encryptionKey' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']
                );
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = 't3lib_cacheHashTest';
-               $this->fixture = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator', array('foo'));
-               $this->fixture->setConfiguration(array(
+               $this->subject = $this->getMock(\TYPO3\CMS\Frontend\Page\CacheHashCalculator::class, array('foo'));
+               $this->subject->setConfiguration(array(
                        'excludedParameters' => array('exclude1', 'exclude2'),
                        'cachedParametersWhiteList' => array(),
                        'requireCacheHashPresenceParameters' => array('req1', 'req2'),
@@ -56,16 +46,12 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                ));
        }
 
-       public function tearDown() {
-               $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] = $this->confCache['encryptionKey'];
-       }
-
        /**
         * @dataProvider cacheHashCalculationDataprovider
         * @test
         */
        public function cacheHashCalculationWorks($params, $expected) {
-               $this->assertEquals($expected, $this->fixture->calculateCacheHash($params));
+               $this->assertEquals($expected, $this->subject->calculateCacheHash($params));
        }
 
        /**
@@ -100,7 +86,7 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function getRelevantParametersWorks($params, $expected) {
-               $actual = $this->fixture->getRelevantParameters($params);
+               $actual = $this->subject->getRelevantParameters($params);
                $this->assertEquals($expected, array_keys($actual));
        }
 
@@ -118,11 +104,11 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                'key1=v&key2=v',
                                array('encryptionKey', 'key1', 'key2')
                        ),
-                       'System and exclude paramters should be omitted' => array(
+                       'System and exclude parameters should be omitted' => array(
                                'id=1&type=3&exclude1=x&no_cache=1',
                                array()
                        ),
-                       'System and exclude paramters should be omitted' => array(
+                       'System and exclude parameters should be omitted, others should stay' => array(
                                'id=1&type=3&key=x&no_cache=1',
                                array('encryptionKey', 'key')
                        )
@@ -134,7 +120,7 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function canGenerateForParameters($params, $expected) {
-               $this->assertEquals($expected, $this->fixture->generateForParameters($params));
+               $this->assertEquals($expected, $this->subject->generateForParameters($params));
        }
 
        /**
@@ -148,7 +134,7 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'Querystring has only system parameters so we should not have a cacheHash' => array('id=1&type=val', ''),
                        'Trivial key value combination should generate hash' => array('&key=value', $knowHash),
                        'Only the relevant parts should be taken into account' => array('&key=value&exclude1=val', $knowHash),
-                       'Only the relevant parts should be taken into account' => array('&exclude2=val&key=value', $knowHash),
+                       'Only the relevant parts should be taken into account(exclude2 before key)' => array('&exclude2=val&key=value', $knowHash),
                        'System parameters should not be taken into account' => array('&id=1&key=value', $knowHash),
                        'Admin panel parameters should not be taken into account' => array('&TSFE_ADMIN_PANEL[display]=7&key=value', $knowHash),
                        'Trivial hash for sorted parameters should be right' => array('a=v&b=v', '0f40b089cdad149aea99e9bf4badaa93'),
@@ -161,7 +147,7 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function parametersRequireCacheHashWorks($params, $expected) {
-               $this->assertEquals($expected, $this->fixture->doParametersRequireCacheHash($params));
+               $this->assertEquals($expected, $this->subject->doParametersRequireCacheHash($params));
        }
 
        /**
@@ -172,8 +158,8 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        'Empty parameter strings should not require anything.' => array('', FALSE),
                        'Normal parameters aren\'t required.' => array('key=value', FALSE),
                        'Configured "req1" to be required.' => array('req1=value', TRUE),
-                       'Configured "req1" to be requiredm, should also work in combined context' => array('&key=value&req1=value', TRUE),
-                       'Configured "req1" to be requiredm, should also work in combined context' => array('req1=value&key=value', TRUE)
+                       'Configured "req1" to be required, should also work in combined context' => array('&key=value&req1=value', TRUE),
+                       'Configured "req1" to be required, should also work in combined context (key at the end)' => array('req1=value&key=value', TRUE)
                );
        }
 
@@ -185,10 +171,10 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function canWhitelistParameters($params, $expected) {
-               $method = new \ReflectionMethod('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator', 'setCachedParametersWhiteList');
+               $method = new \ReflectionMethod(\TYPO3\CMS\Frontend\Page\CacheHashCalculator::class, 'setCachedParametersWhiteList');
                $method->setAccessible(TRUE);
-               $method->invoke($this->fixture, array('whitep1', 'whitep2'));
-               $this->assertEquals($expected, $this->fixture->generateForParameters($params));
+               $method->invoke($this->subject, array('whitep1', 'whitep2'));
+               $this->assertEquals($expected, $this->subject->generateForParameters($params));
        }
 
        /**
@@ -211,8 +197,8 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function canSkipParametersWithEmptyValues($params, $settings, $expected) {
-               $this->fixture->setConfiguration($settings);
-               $actual = $this->fixture->getRelevantParameters($params);
+               $this->subject->setConfiguration($settings);
+               $actual = $this->subject->getRelevantParameters($params);
                $this->assertEquals($expected, array_keys($actual));
        }
 
@@ -226,12 +212,12 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                                array('excludedParametersIfEmpty' => array(), 'excludeAllEmptyParameters' => FALSE),
                                array('encryptionKey', 'key1', 'key2', 'key3')
                        ),
-                       'Due to the empty value, "key2" should be skipped' => array(
+                       'Due to the empty value, "key2" should be skipped(with equals sign' => array(
                                'key1=v&key2=&key3=',
                                array('excludedParametersIfEmpty' => array('key2'), 'excludeAllEmptyParameters' => FALSE),
                                array('encryptionKey', 'key1', 'key3')
                        ),
-                       'Due to the empty value, "key2" should be skipped' => array(
+                       'Due to the empty value, "key2" should be skipped(without equals sign)' => array(
                                'key1=v&key2&key3',
                                array('excludedParametersIfEmpty' => array('key2'), 'excludeAllEmptyParameters' => FALSE),
                                array('encryptionKey', 'key1', 'key3')
@@ -245,5 +231,3 @@ class CacheHashCalculatorTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        }
 
 }
-
-?>
\ No newline at end of file