Skip to content

Commit

Permalink
Merge 1c24ae5 into 7d14504
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminBeck committed Feb 1, 2023
2 parents 7d14504 + 1c24ae5 commit 97536d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
17 changes: 14 additions & 3 deletions Classes/ViewHelpers/Security/AbstractSecurityViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/

use FluidTYPO3\Vhs\Utility\ContextUtility;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
Expand Down Expand Up @@ -316,11 +318,20 @@ public function assertBackendUserGroupLoggedIn($groups = null): bool
*/
public function assertAdminLoggedIn(): bool
{
if (!$this->assertBackendUserLoggedIn()) {
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '11.5', '<')) {
if (!$this->assertBackendUserLoggedIn()) {
return false;
}
$currentBackendUser = $this->getCurrentBackendUser();
return is_array($currentBackendUser) && (boolean) ($currentBackendUser['admin'] ?? false);
}
/** @var Context $context */
$context = GeneralUtility::makeInstance(Context::class);
try {
return (bool) $context->getPropertyFromAspect('backend.user', 'isAdmin');
} catch (AspectNotFoundException $e) {
return false;
}
$currentBackendUser = $this->getCurrentBackendUser();
return is_array($currentBackendUser) && (boolean) ($currentBackendUser['admin'] ?? false);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTestCase;
use FluidTYPO3\Vhs\ViewHelpers\Security\AbstractSecurityViewHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Domain\Model\BackendUser;
use TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
Expand Down Expand Up @@ -368,9 +369,12 @@ public function testAssertAdminLoggedIn(?array $currentUser, bool $expected): vo
->setMethods(['getCurrentBackendUser'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$instance->expects($this->atLeastOnce())->method('getCurrentBackendUser')->willReturn($currentUser);
$result = $instance->assertAdminLoggedIn();
$this->assertEquals($expected, $result);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '11.5', '<')) {
$instance->expects($this->atLeastOnce())->method('getCurrentBackendUser')->willReturn($currentUser);
$result = $instance->assertAdminLoggedIn();
$this->assertEquals($expected, $result);
}
// no test for TYPO3 11.5 and above, as the aspects implementation is tested by the core
}

public function getAssertAdminLoggedInTestValues(): array
Expand Down

0 comments on commit 97536d9

Please sign in to comment.