[TASK] Add a function for clearing the rootline caches 52/30052/8
authorOliver Klee <typo3-coding@oliverklee.de>
Tue, 13 May 2014 12:44:05 +0000 (14:44 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Sat, 28 Jun 2014 17:12:23 +0000 (19:12 +0200)
The RootlineUtility uses two local caches and one additional cache from
the caching framework. If a unit test uses the RootlineUtility, it needs
a way of purging these caches so it does not change the environment.

Resolves: #58763
Releases: 6.3, 6.2, 6.1
Change-Id: Ia9878b808acfa03f018086829f90b84d4c5e8512
Reviewed-on: https://review.typo3.org/30052
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/Utility/RootlineUtility.php
typo3/sysext/core/Tests/Unit/Utility/RootlineUtilityTest.php

index 626e438..f9dc672 100644 (file)
@@ -162,6 +162,18 @@ class RootlineUtility {
        }
 
        /**
+        * Purges all rootline caches.
+        *
+        * Note: This function is intended to be used in unit tests only.
+        *
+        * @return void
+        */
+       static public function purgeCaches() {
+               self::$localCache = array();
+               self::$pageRecordCache = array();
+       }
+
+       /**
         * Constructs the cache Identifier
         *
         * @param integer $otherUid
index e2f11f1..b65ce00 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\RootlineUtility;
+
 /**
  * Testcase for class \TYPO3\CMS\Core\Utility\RootlineUtility
  *
@@ -22,7 +24,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Utility;
 class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
-        * @var \TYPO3\CMS\Core\Utility\RootlineUtility|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject
+        * @var RootlineUtility|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject
         */
        protected $fixture;
 
@@ -31,11 +33,15 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        protected $pageContextMock;
 
-       public function setUp() {
+       protected function setUp() {
                $this->pageContextMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
-               $this->fixture = $this->getAccessibleMock('\TYPO3\CMS\Core\Utility\RootlineUtility', array('enrichWithRelationFields'), array(1, '', $this->pageContextMock));
+               $this->fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Utility\\RootlineUtility', array('enrichWithRelationFields'), array(1, '', $this->pageContextMock));
        }
 
+       protected function tearDown() {
+               parent::tearDown();
+               RootlineUtility::purgeCaches();
+       }
 
        /***
         *