Skip to content

Commit

Permalink
Fix preview webspace without theme (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
plozmun authored and alexander-schranz committed Mar 4, 2021
1 parent 9818b4d commit 14381cc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion EventListener/SetThemeEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ public function setActiveThemeOnRequest(RequestEvent $event): void
*/
public function setActiveThemeOnPreviewPreRender(PreRenderEvent $event): void
{
$theme = $this->themeRepository->findOneByName($event->getAttribute('webspace')->getTheme());
$themeName = $event->getAttribute('webspace')->getTheme();
if (null === $themeName) {
return;
}
$theme = $this->themeRepository->findOneByName($themeName);
if (null !== $theme) {
$this->themeContext->setTheme($theme);
}
Expand Down
20 changes: 20 additions & 0 deletions Tests/Unit/EventListener/SetThemeEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,24 @@ public function testEventListenerOnPreview(): void

$this->assertSame($theme->reveal(), $this->themeContext->getTheme());
}

public function testEventListenerOnPreviewNoTheme(): void
{
/** @var Webspace|ObjectProphecy webspace */
$webspace = $this->prophesize(Webspace::class);
$webspace->getTheme()->willReturn(null);

/** @var RequestAttributes|ObjectProphecy $attributes */
$attributes = $this->prophesize(RequestAttributes::class);
$attributes->getAttribute('webspace', null)->willReturn($webspace->reveal());

$this->themeRepository->findOneByName('theme/name')
->shouldNotBeCalled();

$this->listener->setActiveThemeOnPreviewPreRender(
new PreRenderEvent($attributes->reveal())
);

$this->assertNull($this->themeContext->getTheme());
}
}

0 comments on commit 14381cc

Please sign in to comment.