[BUGFIX] Fix typo in CacheManager 34/51234/16
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 10 Jan 2017 10:09:03 +0000 (11:09 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Tue, 17 Jan 2017 10:37:42 +0000 (11:37 +0100)
By fixing a typo in the CacheManager empty tag arrays
are detected and intercepted.

Resolves: #79236
Releases: master
Change-Id: I67fccda3755274f3334f0916d26beabbb28b8eb4
Reviewed-on: https://review.typo3.org/51234
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Cache/CacheManager.php
typo3/sysext/core/Tests/Unit/Cache/CacheManagerTest.php

index bb6321e..d71b84b 100644 (file)
@@ -204,14 +204,14 @@ class CacheManager implements SingletonInterface
      * caches of a specific group.
      *
      * @param string $groupIdentifier
-     * @param string[] $tag Tags to search for
+     * @param string[] $tags Tags to search for
      * @return void
      * @throws NoSuchCacheGroupException
      * @api
      */
     public function flushCachesInGroupByTags($groupIdentifier, array $tags)
     {
-        if (empty($tag)) {
+        if (empty($tags)) {
             return;
         }
         $this->createAllCaches();
index d90ec7e..635c4d1 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Cache;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Prophecy\Argument;
 use TYPO3\CMS\Core\Cache\CacheManager;
 use TYPO3\CMS\Core\Cache\Exception\InvalidBackendException;
 use TYPO3\CMS\Core\Cache\Exception\InvalidCacheException;
@@ -419,4 +420,77 @@ class CacheManagerTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
         $this->expectExceptionCode(1464557160);
         $manager->getCache($cacheIdentifier);
     }
+
+    /**
+     * @test
+     */
+    public function flushCachesInGroupByTagsWithEmptyTagsArrayDoesNotFlushCaches()
+    {
+        /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Components\TestingFramework\Core\AccessibleObjectInterface|CacheManager $manager */
+        $manager = $this->getAccessibleMock(CacheManager::class, ['dummy'], [], '', false);
+        $cacheIdentifier = 'aTest';
+
+        $cacheGroups = [
+            'group1' => [$cacheIdentifier],
+            'group2' => [$cacheIdentifier],
+        ];
+        $manager->_set('cacheGroups', $cacheGroups);
+
+        $frontend = $this->prophesize(FrontendFixture::class);
+
+        $caches = [
+            $cacheIdentifier => $frontend->reveal()
+        ];
+        $manager->_set('caches', $caches);
+
+        $frontend->flushByTags(Argument::any())->shouldNotBeCalled();
+
+        $configuration = [
+            $cacheIdentifier => [
+                'frontend' => $frontend,
+                'backend' => BackendFixture::class,
+                'options' => [],
+                'groups' => ['group1', 'group2']
+            ],
+        ];
+        $manager->setCacheConfigurations($configuration);
+        $manager->flushCachesInGroupByTags('group2', []);
+    }
+
+    /**
+     * @test
+     */
+    public function flushCachesInGroupByTagsDeletesByTag()
+    {
+        /** @var \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Components\TestingFramework\Core\AccessibleObjectInterface|CacheManager $manager */
+        $manager = $this->getAccessibleMock(CacheManager::class, ['dummy'], [], '', false);
+        $cacheIdentifier = 'aTest';
+
+        $cacheGroups = [
+            'group1' => [$cacheIdentifier],
+            'group2' => [$cacheIdentifier],
+        ];
+        $manager->_set('cacheGroups', $cacheGroups);
+
+        $frontend = $this->prophesize(FrontendFixture::class);
+
+        $caches = [
+            $cacheIdentifier => $frontend->reveal()
+        ];
+        $manager->_set('caches', $caches);
+
+        $tags = ['tag1', 'tag2'];
+        $frontend->flushByTags($tags)->shouldBeCalled();
+
+        $configuration = [
+            $cacheIdentifier => [
+                'frontend' => $frontend,
+                'backend' => BackendFixture::class,
+                'options' => [],
+                'groups' => ['group1', 'group2']
+            ],
+        ];
+        $manager->setCacheConfigurations($configuration);
+        $manager->flushCachesInGroupByTags('group2', $tags);
+    }
 }