1616use OxidEsales \EshopCommunity \Tests \ContainerTrait ;
1717use OxidEsales \Twig \Extensions \IncludeContentExtension ;
1818use PHPUnit \Framework \Attributes \DataProvider ;
19- use PHPUnit \Framework \MockObject \MockBuilder ;
20- use PHPUnit \Framework \MockObject \MockObject ;
2119use Twig \Environment ;
2220use Twig \Error \LoaderError ;
2321use Twig \Extension \StringLoaderExtension ;
@@ -28,25 +26,15 @@ final class IncludeContentExtensionTest extends AbstractExtensionTestCase
2826{
2927 use ContainerTrait;
3028
31- private MockBuilder $ contentMockBuilder ;
32- private MockObject &ContentFactory $ contentFactoryMock ;
29+ private ContentFactory $ contentFactoryStub ;
3330 private string $ spamContent = 'not spam<script>alert("spam")</script> ' ;
3431
3532 public function setUp (): void
3633 {
3734 parent ::setUp ();
3835
39- $ this ->contentMockBuilder = $ this
40- ->getMockBuilder (Content::class)
41- ->disableOriginalConstructor ()
42- ->onlyMethods (['getLanguage ' ]);
43-
44- $ this ->contentFactoryMock = $ this
45- ->getMockBuilder (ContentFactory::class)
46- ->onlyMethods (['getContent ' ])
47- ->getMock ();
48-
49- $ this ->contentFactoryMock
36+ $ this ->contentFactoryStub = $ this ->createStub (ContentFactory::class);
37+ $ this ->contentFactoryStub
5038 ->method ('getContent ' )
5139 ->willReturnMap ($ this ->getContentMap ());
5240 }
@@ -112,49 +100,49 @@ private function initializeExtension(bool $sanitizerEnabled): void
112100 $ this ->setParameter ('oxid_esales.html_sanitizer_enabled ' , $ sanitizerEnabled );
113101
114102 $ this ->extension = new IncludeContentExtension (
115- $ this ->contentFactoryMock ,
103+ $ this ->contentFactoryStub ,
116104 ContainerFacade::get (HtmlSanitizerInterface::class)
117105 );
118106 }
119107
120- private function prepareContentMock (int $ language , array $ fields ): MockObject
108+ private function prepareContent (int $ language , array $ fields ): Content
121109 {
122- $ mock = $ this -> contentMockBuilder -> getMock ();
123- $ mock -> method ( ' getLanguage ' )-> willReturn ($ language );
110+ $ content = new Content ();
111+ $ content -> setLanguage ($ language );
124112
125113 foreach ($ fields as $ field => $ value ) {
126114 $ property = 'oxcontents__ ' . $ field ;
127- $ mock ->$ property = (object )['value ' => $ value ];
115+ $ content ->$ property = (object )['value ' => $ value ];
128116 }
129117
130- return $ mock ;
118+ return $ content ;
131119 }
132120
133121 /** Build the content return map for the mock factory */
134122 private function getContentMap (): array
135123 {
136124 return [
137- ['ident ' , 'german ' , $ this ->prepareContentMock (0 , [
125+ ['ident ' , 'german ' , $ this ->prepareContent (0 , [
138126 'oxactive ' => true ,
139127 'oxcontent ' => 'Template code (DE) ' ,
140128 ])],
141- ['ident ' , 'english ' , $ this ->prepareContentMock (1 , [
129+ ['ident ' , 'english ' , $ this ->prepareContent (1 , [
142130 'oxactive ' => true ,
143131 'oxcontent ' => 'Template code (EN) ' ,
144132 ])],
145- ['ident ' , 'twig_code ' , $ this ->prepareContentMock (0 , [
133+ ['ident ' , 'twig_code ' , $ this ->prepareContent (0 , [
146134 'oxactive ' => true ,
147135 'oxcontent ' => 'In my_var I have {{ my_var }} value ' ,
148136 ])],
149- ['ident ' , 'dynamic_content ' , $ this ->prepareContentMock (0 , [
137+ ['ident ' , 'dynamic_content ' , $ this ->prepareContent (0 , [
150138 'oxactive ' => true ,
151139 'oxcontent ' => 'Dynamic content ' ,
152140 ])],
153- ['ident ' , 'not_active ' , $ this ->prepareContentMock (0 , [
141+ ['ident ' , 'not_active ' , $ this ->prepareContent (0 , [
154142 'oxactive ' => false ,
155143 'oxcontent ' => 'Not active content ' ,
156144 ])],
157- ['ident ' , 'spam ' , $ this ->prepareContentMock (0 , [
145+ ['ident ' , 'spam ' , $ this ->prepareContent (0 , [
158146 'oxactive ' => true ,
159147 'oxcontent ' => $ this ->spamContent ,
160148 ])],
0 commit comments