Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
HtmlSanitizerExtension example
->
method
(
'sanitize'
)
->
with
(
'foobar'
)
->
willReturn
(
'foo'
)
;
$barSanitizer
=
$this
->
createMock
(
HtmlSanitizerInterface::
class
)
;
$barSanitizer
->
expects
(
$this
->
once
(
)
)
->
method
(
'sanitize'
)
->
with
(
'foobar'
)
->
willReturn
(
'bar'
)
;
return
array_merge
(
parent::
getExtensions
(
)
,
[
new
HtmlSanitizerExtension
(
new
ServiceLocator
(
[
'foo' =>
fn
(
)
=>
$fooSanitizer
,
'bar' =>
fn
(
)
=>
$barSanitizer
,
]
)
, 'foo'
)
,
]
)
;
}
public
function
testSanitizer
(
)
{
$form
=
$this
->factory->
createBuilder
(
FormType::
class
,
[
'data' => null
]
)
->
add
(
'data', TextType::
class
,
[
'sanitize_html' => true
]
)
->
getForm
(
)
;
$fooSanitizer
->
expects
(
$this
->
once
(
)
)
->
method
(
'sanitize'
)
->
with
(
'foobar'
)
->
willReturn
(
'foo'
)
;
$barSanitizer
=
$this
->
createMock
(
HtmlSanitizerInterface::
class
)
;
$barSanitizer
->
expects
(
$this
->
once
(
)
)
->
method
(
'sanitize'
)
->
with
(
'foobar'
)
->
willReturn
(
'bar'
)
;
$twig
->
addExtension
(
new
HtmlSanitizerExtension
(
new
ServiceLocator
(
[
'foo' =>
fn
(
)
=>
$fooSanitizer
,
'bar' =>
fn
(
)
=>
$barSanitizer
,
]
)
, 'foo'
)
)
;
$this
->
assertSame
(
'foo',
$twig
->
render
(
'foo'
)
)
;
$this
->
assertSame
(
'bar',
$twig
->
render
(
'bar'
)
)
;
}
}