Skip to content

Commit

Permalink
IBX-2275: Refactor UDW configuration subscribers (#2039)
Browse files Browse the repository at this point in the history
* IBX-2275: Made `single_container` UDW config read-only

* IBX-2275: Refactored UDW configuration subscribers

* IBX-2275: Adapter unit tests
  • Loading branch information
barw4 authored Apr 20, 2022
1 parent a7d5834 commit 93ffb2c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function setUp(): void
public function testUdwConfigResolveWithCreateTab(array $config): void
{
$event = new ConfigResolveEvent();
$event->setConfigName('some_config');
$event->setConfigName('create');
$event->setConfig($config);

$subscriber = $this->getSubscriberWithRestrictions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ protected function setUp(): void

public function testUdwConfigResolveOnUnsupportedConfigName(): void
{
$this->permissionResolver->expects($this->never())->method('hasAccess');
$this->permissionResolver->method('hasAccess')->with('content', 'read')->willReturn(true);
$this->permissionChecker->expects($this->never())->method('getRestrictions');
$this->contentTypeService->expects($this->never())->method('loadContentTypeList');

$event = $this->createConfigResolveEvent('unsupported_config_name');

$this->subscriber->onUdwConfigResolve($event);

$this->assertEquals([], $event->getConfig());
$expectedConfig = [
'allowed_content_types' => null,
];

$this->assertEquals($expectedConfig, $event->getConfig());
}

public function testUdwConfigResolveWhenThereIsNoContentReadLimitations(): void
Expand Down
14 changes: 0 additions & 14 deletions src/lib/UniversalDiscovery/Event/ConfigResolveEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ class ConfigResolveEvent extends Event
{
public const NAME = 'udw.resolve.config';

private const READ_SPECIFIC_CONFIGURATIONS = [
'richtext_embed',
'richtext_embed_image',
'browse',
'subtree_search',
'single',
'multiple',
];

/** @var string */
protected $configName;

Expand Down Expand Up @@ -79,9 +70,4 @@ public function setContext(array $context): void
{
$this->context = $context;
}

public function isReadOnlyEvent(): bool
{
return in_array($this->getConfigName(), self::READ_SPECIFIC_CONFIGURATIONS, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function getSubscribedEvents(): array
*/
public function onUdwConfigResolve(ConfigResolveEvent $event): void
{
if ($event->isReadOnlyEvent()) {
if ($event->getConfigName() !== 'create') {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ public function onUdwConfigResolve(ConfigResolveEvent $event): void
{
$config = $event->getConfig();

if (!$event->isReadOnlyEvent()) {
return;
}

$this->allowedContentTypesIdentifiers = $this->getAllowedContentTypesIdentifiers(
$config['allowed_content_types'] ?? []
);
Expand Down

0 comments on commit 93ffb2c

Please sign in to comment.