Skip to content

Commit

Permalink
Fix test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hoogi91 committed Jul 26, 2020
1 parent 23dcfd9 commit 2f5a1ea
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
11 changes: 8 additions & 3 deletions Classes/Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Information\Typo3Version;

/**
* Class CacheService
* @package Hoogi91\AccessRestriction\Service
*/
class CacheService
{
const CACHE_NAME = 'cache_accessrestriction';
const CACHE_NAME = 'accessrestriction';

/**
* @TYPO3\CMS\Extbase\Annotation\Inject
Expand All @@ -35,7 +36,7 @@ public function get($identifier)

/**
* @param string $identifier
* @param mixed $data
* @param mixed $data
*/
public function set($identifier, $data)
{
Expand Down Expand Up @@ -64,6 +65,10 @@ public function flush()
*/
protected function getCache()
{
return $this->cacheManager->getCache(static::CACHE_NAME);
$cacheName = self::CACHE_NAME;
if (class_exists(Typo3Version::class) === false || (new Typo3Version())->getMajorVersion() < 10) {
$cacheName = 'cache_' . $cacheName;
}
return $this->cacheManager->getCache($cacheName);
}
}
4 changes: 2 additions & 2 deletions Classes/Service/UserGroupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class UserGroupService
{

/**
* @TYPO3\CMS\Extbase\Annotation\Inject
* @var \Hoogi91\AccessRestriction\Service\RestrictionService
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $restrictionService;

/**
* @TYPO3\CMS\Extbase\Annotation\Inject
* @var \Hoogi91\AccessRestriction\Service\IpValidationService
* @TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $ipValidationService;

Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Service/AbstractUserGroupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ abstract public function getRemoteAddress(): string;
*/
abstract public function testEvaluatingRestrictionGroups();

}
}
11 changes: 8 additions & 3 deletions Tests/Unit/Service/CacheServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use TYPO3\CMS\Core\Cache\Backend\TransientMemoryBackend;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
use TYPO3\CMS\Core\Information\Typo3Version;

/**
* Class CacheServiceTest
Expand All @@ -33,16 +34,20 @@ protected function setUp()
'getCache',
])->getMock();

$cacheName = class_exists(Typo3Version::class) && (new Typo3Version())->getMajorVersion() >= 10
? CacheService::CACHE_NAME
: 'cache_'. CacheService::CACHE_NAME;

// only instantiate cache manager for this test class
// cause otherwise singleton interface will set this for all requests/tests
$cacheManager = new CacheManager();
$cacheManager->setCacheConfigurations([
'cache_accessrestriction' => [
$cacheName => [
'backend' => TransientMemoryBackend::class,
'frontend' => VariableFrontend::class,
],
]);
$this->cacheService->method('getCache')->willReturn($cacheManager->getCache(CacheService::CACHE_NAME));
$this->cacheService->method('getCache')->willReturn($cacheManager->getCache($cacheName));

$this->invalidCacheService = $this->getMockBuilder(CacheService::class)->setMethods([
'getCache',
Expand Down Expand Up @@ -89,4 +94,4 @@ public function testInvalidCacheName()
// flush should also do nothing and simply return void
$this->invalidCacheService->flush();
}
}
}

0 comments on commit 2f5a1ea

Please sign in to comment.