Skip to content

Commit

Permalink
EZP-32173: Changed return data when $access is bool
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Dec 14, 2020
1 parent 8798016 commit 54ceb42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ public function testUdwConfigResolveOnUnsupportedConfigName(): void
$this->assertEquals([], $event->getConfig());
}

/**
* @dataProvider dataProviderForUdwConfigResolveWhenThereIsNoContentReadLimitations
*/
public function testUdwConfigResolveWhenThereIsNoContentReadLimitations(bool $hasAccess): void
public function testUdwConfigResolveWhenThereIsNoContentReadLimitations(): void
{
$this->permissionResolver->method('hasAccess')->with('content', 'read')->willReturn($hasAccess);
$this->permissionResolver->method('hasAccess')->with('content', 'read')->willReturn(true);
$this->permissionChecker->expects($this->never())->method('getRestrictions');
$this->contentTypeService->expects($this->never())->method('loadContentTypeList');

Expand All @@ -78,12 +75,15 @@ public function testUdwConfigResolveWhenThereIsNoContentReadLimitations(bool $ha
]);
}

public function dataProviderForUdwConfigResolveWhenThereIsNoContentReadLimitations(): iterable
public function testUdwConfigResolveWhenThereIsNoContentReadLimitationsAndNoAccess(): void
{
return [
['hasAccess' => false],
['hasAccess' => true],
];
$this->permissionResolver->method('hasAccess')->with('content', 'read')->willReturn(false);
$this->permissionChecker->expects($this->never())->method('getRestrictions');
$this->contentTypeService->expects($this->never())->method('loadContentTypeList');

$this->assertConfigurationResolvingResult([
'allowed_content_types' => [null],
]);
}

public function testUdwConfigResolveWhenThereAreContentReadLimitations(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function __construct(
private function getAllowedContentTypesIdentifiers(array $contentTypesAllowedViaConfig): ?array
{
$access = $this->permissionResolver->hasAccess('content', 'read');
if (!\is_array($access) && $access) {
return $contentTypesAllowedViaConfig ?: null;
if (!\is_array($access)) {
return $access ? ($contentTypesAllowedViaConfig ?: null) : [null];
}

$restrictedContentTypesIds = $this->permissionChecker->getRestrictions($access, ContentTypeLimitation::class);
Expand Down Expand Up @@ -87,7 +87,7 @@ public function onUdwConfigResolve(ConfigResolveEvent $event): void
$this->allowedContentTypesIdentifiers = $this->getAllowedContentTypesIdentifiers($config['allowed_content_types'] ?? []);
}

$config['allowed_content_types'] = $this->allowedContentTypesIdentifiers ?: null;
$config['allowed_content_types'] = $this->allowedContentTypesIdentifiers;

$event->setConfig($config);
}
Expand Down

0 comments on commit 54ceb42

Please sign in to comment.