From f97e9504533b1ee594f535236da129f9b3e29f90 Mon Sep 17 00:00:00 2001 From: Tomasz Kryszan Date: Mon, 4 Sep 2023 14:46:56 +0200 Subject: [PATCH] LimitationResolverTest cleanup --- .../lib/Permission/LimitationResolverTest.php | 59 ++++++------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/tests/lib/Permission/LimitationResolverTest.php b/tests/lib/Permission/LimitationResolverTest.php index fad6bc151e..325c205ea1 100644 --- a/tests/lib/Permission/LimitationResolverTest.php +++ b/tests/lib/Permission/LimitationResolverTest.php @@ -32,20 +32,6 @@ */ final class LimitationResolverTest extends TestCase { - /** @var \Ibexa\Contracts\Core\Repository\ContentService&\PHPUnit\Framework\MockObject\MockObject */ - private ContentService $contentService; - - /** @var \Ibexa\Contracts\Core\Repository\ContentTypeService&\PHPUnit\Framework\MockObject\MockObject */ - private ContentTypeService $contentTypeService; - - /** @var \Ibexa\Contracts\Core\Repository\LanguageService&\PHPUnit\Framework\MockObject\MockObject */ - private LanguageService $languageService; - - /** @var \Ibexa\Contracts\Core\Repository\LocationService&\PHPUnit\Framework\MockObject\MockObject */ - private LocationService $locationService; - - private LookupLimitationsTransformer $lookupLimitationsTransformer; - /** @var \Ibexa\Contracts\Core\Repository\PermissionResolver&\PHPUnit\Framework\MockObject\MockObject */ private PermissionResolver $permissionResolver; @@ -53,19 +39,14 @@ final class LimitationResolverTest extends TestCase protected function setUp(): void { - $this->contentService = $this->createMock(ContentService::class); - $this->contentTypeService = $this->createMock(ContentTypeService::class); - $this->languageService = $this->createMock(LanguageService::class); - $this->locationService = $this->createMock(LocationService::class); - $this->lookupLimitationsTransformer = new LookupLimitationsTransformer(); $this->permissionResolver = $this->createMock(PermissionResolver::class); $this->limitationResolver = new LimitationResolver( - $this->contentService, - $this->contentTypeService, - $this->languageService, - $this->locationService, - $this->lookupLimitationsTransformer, + $this->createMock(ContentService::class), + $this->createMock(ContentTypeService::class), + $this->createMock(LanguageService::class), + $this->createMock(LocationService::class), + new LookupLimitationsTransformer(), $this->permissionResolver ); } @@ -86,10 +67,6 @@ public function testGetLanguageLimitations( LookupLimitationResult $lookupLimitationResult ): void { $this->mockPermissionResolverLookupLimitations( - [ - 'eng-GB', - 'ger-DE', - ], $versionInfo->getContentInfo(), $location, $lookupLimitationResult @@ -141,7 +118,7 @@ public function provideDataForTestGetLanguageLimitations(): iterable new LookupLimitationResult(false), ]; - yield 'Has access to all enabled languages' => [ + yield 'Access to all enabled languages' => [ [ $this->getLanguageAccessData(true, $english), $this->getLanguageAccessData(true, $german), @@ -152,7 +129,7 @@ public function provideDataForTestGetLanguageLimitations(): iterable new LookupLimitationResult(true), ]; - yield 'Has limited access to English language by policy limitation' => [ + yield 'Limited access to English language by policy limitation' => [ [ $this->getLanguageAccessData(true, $english), $this->getLanguageAccessData(false, $german), @@ -174,7 +151,7 @@ public function provideDataForTestGetLanguageLimitations(): iterable ), ]; - yield 'Has limited access to German language by role limitation' => [ + yield 'Limited access to German language by role limitation' => [ [ $this->getLanguageAccessData(false, $english), $this->getLanguageAccessData(true, $german), @@ -190,7 +167,7 @@ public function provideDataForTestGetLanguageLimitations(): iterable ), ]; - yield 'Has limited access to English and German languages by role and policy limitations' => [ + yield 'Limited access to English and German languages by role and policy limitations' => [ [ $this->getLanguageAccessData(true, $english), $this->getLanguageAccessData(true, $german), @@ -289,25 +266,27 @@ private function createLanguageLimitation(array $limitationValues): Limitation\L ); } - /** - * @param array $languageCodes - */ private function mockPermissionResolverLookupLimitations( - array $languageCodes, ContentInfo $contentInfo, Location $location, LookupLimitationResult $lookupLimitationResult ): void { + $languageCodes = [ + 'eng-GB', + 'ger-DE', + ]; + $targets = [ + (new VersionBuilder())->translateToAnyLanguageOf($languageCodes)->build(), + $location, + ]; + $this->permissionResolver ->method('lookupLimitations') ->with( 'content', 'edit', $contentInfo, - [ - (new VersionBuilder())->translateToAnyLanguageOf($languageCodes)->build(), - $location, - ], + $targets, [Limitation::LANGUAGE], ) ->willReturn($lookupLimitationResult);