Skip to content

Commit

Permalink
fixed preview style-link (#3930)
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes authored and danrot committed Apr 26, 2018
1 parent a603c38 commit a508a47
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,9 @@
CHANGELOG for Sulu
==================

* dev-master
* ENHANCEMENT #3930 [PreviewBundle] Fixed preview style-link

* 1.6.17 (2018-04-23)
* FEATURE #3906 [MediaBundle] Add file version delete to media overlay
* HOTFIX #3912 [ContentBundle] Fixed content-query when a child is broken
Expand Down
2 changes: 1 addition & 1 deletion src/Sulu/Bundle/PreviewBundle/Preview/Preview.php
Expand Up @@ -169,7 +169,7 @@ public function render($token, $webspaceKey, $locale, $targetGroupId = null)
*/
protected function replaceLinks($html)
{
return preg_replace('/(href|action)="[^"]*"/', '$1="#"', $html);
return preg_replace('/((?:a|form)(?:[^>]*)(?:href|action))="[^"]*"/', '$1="#"', $html);
}

/**
Expand Down
55 changes: 55 additions & 0 deletions src/Sulu/Bundle/PreviewBundle/Tests/Unit/Preview/PreviewTest.php
Expand Up @@ -473,6 +473,61 @@ public function testRenderWithLink()
$this->assertEquals('<a property="title" href="#">test</a>', $response);
}

public function testRenderWithStyle()
{
$object = $this->prophesize(\stdClass::class);

$token = '123-123-123';
$this->dataCache->contains($token)->willReturn(true);
$this->dataCache->fetch($token)->willReturn(get_class($object->reveal()) . "\n{\"title\": \"test\"}");

$provider = $this->prophesize(PreviewObjectProviderInterface::class);
$provider->deserialize('{"title": "test"}', get_class($object->reveal()))->willReturn($object->reveal());
$provider->getId($object->reveal())->willReturn(1);

$this->renderer->render($object->reveal(), 1, 'sulu_io', 'de', false, null)
->willReturn('<link rel="stylesheet" type="text/css" href="theme.css">');

$preview = $this->getPreview([get_class($object->reveal()) => $provider]);
$response = $preview->render($token, 'sulu_io', 'de');

$this->assertEquals('<link rel="stylesheet" type="text/css" href="theme.css">', $response);
}

public function testRenderWithMultipleTags()
{
$object = $this->prophesize(\stdClass::class);

$token = '123-123-123';
$this->dataCache->contains($token)->willReturn(true);
$this->dataCache->fetch($token)->willReturn(get_class($object->reveal()) . "\n{\"title\": \"test\"}");

$provider = $this->prophesize(PreviewObjectProviderInterface::class);
$provider->deserialize('{"title": "test"}', get_class($object->reveal()))->willReturn($object->reveal());
$provider->getId($object->reveal())->willReturn(1);

$this->renderer->render($object->reveal(), 1, 'sulu_io', 'de', false, null)
->willReturn(
'<link rel="stylesheet" type="text/css" href="theme.css">' .
'<a property="title" href="/test">test</a>' .
'<a href="/test">test</a>' .
'<form action="/test"></form>' .
'<form class="form" action="/test"></form>'
);

$preview = $this->getPreview([get_class($object->reveal()) => $provider]);
$response = $preview->render($token, 'sulu_io', 'de');

$this->assertEquals(
'<link rel="stylesheet" type="text/css" href="theme.css">' .
'<a property="title" href="#">test</a>' .
'<a href="#">test</a>' .
'<form action="#"></form>' .
'<form class="form" action="#"></form>',
$response
);
}

public function testRenderWithTargetGroup()
{
$object = $this->prophesize(\stdClass::class);
Expand Down

0 comments on commit a508a47

Please sign in to comment.