1010namespace OxidEsales \Twig \Tests \Integration \Extensions ;
1111
1212use OxidEsales \EshopCommunity \Application \Model \Content ;
13+ use OxidEsales \EshopCommunity \Core \Di \ContainerFacade ;
14+ use OxidEsales \EshopCommunity \Internal \Framework \Html \HtmlSanitizerInterface ;
1315use OxidEsales \EshopCommunity \Internal \Transition \Adapter \TemplateLogic \ContentFactory ;
16+ use OxidEsales \EshopCommunity \Tests \ContainerTrait ;
1417use OxidEsales \Twig \Extensions \IncludeContentExtension ;
1518use PHPUnit \Framework \Attributes \DataProvider ;
1619use PHPUnit \Framework \MockObject \MockBuilder ;
2326
2427final class IncludeContentExtensionTest extends AbstractExtensionTestCase
2528{
26- private MockBuilder $ contentMockBuilder ;
29+ use ContainerTrait ;
2730
28- protected function setUp (): void
31+ private MockBuilder $ contentMockBuilder ;
32+
33+ protected function setUp (): void
2934 {
3035 parent ::setUp ();
3136
@@ -54,6 +59,10 @@ protected function setUp(): void
5459 'oxactive ' => false ,
5560 'oxcontent ' => 'Not active content '
5661 ]);
62+ $ SpamContentMock = $ this ->prepareContentMock (0 , [
63+ 'oxactive ' => true ,
64+ 'oxcontent ' => 'not spam<script>alert("spam")</script> '
65+ ]);
5766
5867 /** @var MockObject|ContentFactory $contentFactoryMock */
5968 $ contentFactoryMock = $ this
@@ -68,10 +77,17 @@ protected function setUp(): void
6877 ['ident ' , 'english ' , $ enContentMock ],
6978 ['ident ' , 'twig_code ' , $ twigContentMock ],
7079 ['ident ' , 'dynamic_content ' , $ dynamicContentMock ],
71- ['ident ' , 'not_active ' , $ notActiveContentMock ]
80+ ['ident ' , 'not_active ' , $ notActiveContentMock ],
81+ ['ident ' , 'spam ' , $ SpamContentMock ]
7282 ]);
7383
74- $ this ->extension = new IncludeContentExtension ($ contentFactoryMock );
84+ $ this ->setParameter ('oxid_esales.html_sanitizer_enabled ' , true );
85+ $ this ->attachContainerToContainerFactory ();
86+
87+ $ this ->extension = new IncludeContentExtension (
88+ $ contentFactoryMock ,
89+ ContainerFacade::get (HtmlSanitizerInterface::class)
90+ );
7591 }
7692
7793 #[DataProvider('contentProvider ' )]
@@ -99,6 +115,10 @@ public static function contentProvider(): array
99115 "{% set content_name = 'dynamic_content' %}{% include_content content_name %} " ,
100116 "Dynamic content "
101117 ],
118+ [
119+ "{% set content_name = 'spam' %}{% include_content content_name %} " ,
120+ "not spam "
121+ ],
102122 ];
103123 }
104124
0 commit comments