Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Renderer/ContentElementRendererStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function render(ContentElementsAwareInterface $item): string

foreach ($this->renderers as $renderer) {
if ($renderer->supports($contentElement)) {
$content .= html_entity_decode($renderer->render($contentElement), \ENT_QUOTES);
$content .= $renderer->render($contentElement);

break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="{{ content_element_base_class }}__multiple-media mb-3">
{% for element in media %}
{{ element.renderedContent }}
{{ element.renderedContent|raw }}
{% endfor %}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
{% endif %}
{% if page.teaserContent %}
<p class="card-text small text-secondary line-clamp mb-0" style="--line-clamp-number: 3;">
{{ page.teaserContent }}
{{ page.teaserContent|raw }}
</p>
<a href="{{ path('sylius_cms_shop_page_show', {'slug': page.slug}) }}" class="btn btn-light btn-sm mt-4">
{{ 'sylius_cms.ui.read_more'|trans }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="{{ content_element_base_class }}__single-media mb-3">
{{ media.renderedContent }}
{{ media.renderedContent|raw }}
</div>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="{{ content_element_base_class }}__textarea mb-3">
{{ content }}
{{ content|raw }}
</div>
26 changes: 24 additions & 2 deletions tests/Unit/Renderer/ContentElementRendererStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,34 @@ public function testRendersAPageContentElementCorrectly(): void
$contentElementMock->expects(self::once())->method('getLocale')->willReturn('en_US');

$this->rendererMock->expects(self::once())->method('supports')->with($contentElementMock)->willReturn(true);
$this->rendererMock->expects(self::once())->method('render')->with($contentElementMock)->willReturn('&lt;p&gt;Hello World&lt;/p&gt;');
$this->rendererMock->expects(self::once())->method('render')->with($contentElementMock)->willReturn('<p>Hello World</p>');
$this->contentParserMock->expects(self::once())->method('parse')->with('<p>Hello World</p>')->willReturn('<p>Hello World</p>');

self::assertSame('<p>Hello World</p>', $this->contentElementRendererStrategy->render($pageMock));
}

public function testEmitsRenderedMarkupUntouched(): void
{
/** @var PageInterface&MockObject $pageMock */
$pageMock = $this->createMock(PageInterface::class);
/** @var ContentConfigurationInterface&MockObject $contentElementMock */
$contentElementMock = $this->createMock(ContentConfigurationInterface::class);

$pageMock->expects(self::once())->method('getContentElements')->willReturn(new ArrayCollection([$contentElementMock]));
$this->localeContextMock->expects(self::once())->method('getLocaleCode')->willReturn('en_US');
$contentElementMock->expects(self::once())->method('getLocale')->willReturn('en_US');

// Escaped text must stay escaped and attributes carrying entities must survive:
// decoding would unescape user input and cut the attribute at the first quote.
$markup = '<h2>Summer &lt;em&gt;offer&lt;/em&gt;</h2><div data-live-props-value="{&quot;product&quot;:1}"></div>';

$this->rendererMock->expects(self::once())->method('supports')->with($contentElementMock)->willReturn(true);
$this->rendererMock->expects(self::once())->method('render')->with($contentElementMock)->willReturn($markup);
$this->contentParserMock->expects(self::once())->method('parse')->with($markup)->willReturn($markup);

self::assertSame($markup, $this->contentElementRendererStrategy->render($pageMock));
}

public function testSkipsContentElementWithNonMatchingLocale(): void
{
/** @var BlockInterface&MockObject $blockMock */
Expand Down Expand Up @@ -99,7 +121,7 @@ public function testRendersOnlySupportedContentElements(): void
$supportedElementMock->expects(self::once())->method('getLocale')->willReturn('en_US');
$unsupportedElementMock->expects(self::once())->method('getLocale')->willReturn('en_US');

$this->rendererMock->expects(self::once())->method('render')->with($supportedElementMock)->willReturn('&lt;p&gt;Supported&lt;/p&gt;');
$this->rendererMock->expects(self::once())->method('render')->with($supportedElementMock)->willReturn('<p>Supported</p>');
$this->rendererMock->expects(self::exactly(2))->method('supports')->willReturnOnConsecutiveCalls(true, false);
$this->contentParserMock->expects(self::once())->method('parse')->with('<p>Supported</p>')->willReturn('<p>Supported</p>');

Expand Down
Loading