Skip to content

Commit

Permalink
LimitationResolverTest cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Sep 6, 2023
1 parent bef583b commit f97e950
Showing 1 changed file with 19 additions and 40 deletions.
59 changes: 19 additions & 40 deletions tests/lib/Permission/LimitationResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,21 @@
*/
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;

private LimitationResolverInterface $limitationResolver;

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
);
}
Expand All @@ -86,10 +67,6 @@ public function testGetLanguageLimitations(
LookupLimitationResult $lookupLimitationResult
): void {
$this->mockPermissionResolverLookupLimitations(
[
'eng-GB',
'ger-DE',
],
$versionInfo->getContentInfo(),
$location,
$lookupLimitationResult
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -289,25 +266,27 @@ private function createLanguageLimitation(array $limitationValues): Limitation\L
);
}

/**
* @param array<string> $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);
Expand Down

0 comments on commit f97e950

Please sign in to comment.