[TASK] Create a Getter for CacheManager inside Datahandler 88/31288/2
authorStefano Kowalke <blueduck@gmx.net>
Wed, 2 Jul 2014 11:26:16 +0000 (13:26 +0200)
committerThomas Maroschik <tmaroschik@dfau.de>
Wed, 2 Jul 2014 12:00:49 +0000 (14:00 +0200)
At the moment the CacheManager is created by
GeneralUtility::makeInstance(
  'TYPO3\\CMS\\Core\\Cache\\CacheManager'
); within the code. This makes the particular method untestable.

Solution: Create a Getter which creates and returns the instance.
This getter can be mocked.

Resolves: #60059
Releases: 6.2, 6.3
Change-Id: I9f83ec017da94778e542410cc9d03faacddc245c
Reviewed-on: https://review.typo3.org/31288
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Alexander Opitz
Tested-by: Alexander Opitz
Reviewed-by: Thomas Maroschik
Tested-by: Thomas Maroschik
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index d1c3472..33663fb 100644 (file)
@@ -7084,7 +7084,7 @@ class DataHandler {
                }
 
                /** @var \TYPO3\CMS\Core\Cache\CacheManager $cacheManager */
-               $cacheManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+               $cacheManager = $this->getCacheManager();
                foreach ($tagsToClear as $tag) {
                        $cacheManager->flushCachesInGroupByTag('pages', $tag);
                }
@@ -7147,13 +7147,13 @@ class DataHandler {
                switch (strtolower($cacheCmd)) {
                        case 'pages':
                                if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.pages')) {
-                                       GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('pages');
+                                       $this->getCacheManager()->flushCachesInGroup('pages');
                                }
                                break;
                        case 'all':
                                if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.all')) {
                                        // Clear cache group "all" of caching framework caches
-                                       GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('all');
+                                       $this->getCacheManager()->flushCachesInGroup('all');
                                        $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('cache_treelist');
                                        // Clearing additional cache tables:
                                        if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearAllCache_additionalTables'])) {
@@ -7173,7 +7173,7 @@ class DataHandler {
                        case 'system':
                                if ($this->admin || $this->BE_USER->getTSConfigVal('options.clearCache.system')
                                        || ((bool) $GLOBALS['TYPO3_CONF_VARS']['SYS']['clearCacheSystem'] === TRUE && $this->admin)) {
-                                       GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('system');
+                                       $this->getCacheManager()->flushCachesInGroup('system');
                                }
                                break;
                }
@@ -7205,7 +7205,7 @@ class DataHandler {
                // process caching framwork operations
                if (count($tagsToFlush) > 0) {
                        foreach (array_unique($tagsToFlush) as $tag) {
-                               GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroupByTag('pages', $tag);
+                               $this->getCacheManager()->flushCachesInGroupByTag('pages', $tag);
                        }
                }
 
@@ -7327,7 +7327,7 @@ class DataHandler {
         */
        public function internal_clearPageCache() {
                GeneralUtility::logDeprecatedFunction();
-               GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->flushCachesInGroup('pages');
+               $this->getCacheManager()->flushCachesInGroup('pages');
        }
 
        /**
@@ -7437,9 +7437,10 @@ class DataHandler {
         * @return \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend
         */
        protected function getMemoryCache() {
-               return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager')->getCache('cache_runtime');
+               return $this->getCacheManager()->getCache('cache_runtime');
        }
 
+
        /**
         * Determines nested element calls.
         *
@@ -7600,4 +7601,12 @@ class DataHandler {
                return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\RelationHandler');
        }
 
+       /**
+        * Create and returns an instance of the CacheManager
+        *
+        * @return \TYPO3\CMS\Core\Cache\CacheManager
+        */
+       protected function getCacheManager() {
+               return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager');
+       }
 }