1010use Magento \Framework \App \Config \ScopeConfigInterface ;
1111use Magento \Framework \App \Response \Http ;
1212use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
13+ use Magento \Framework \View \Result \Layout ;
1314use Magento \Store \Model \ScopeInterface ;
1415use Magento \Theme \Controller \Result \JsFooterPlugin ;
1516use PHPUnit \Framework \MockObject \MockObject ;
@@ -22,21 +23,18 @@ class JsFooterPluginTest extends TestCase
2223{
2324 const STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM = 'dev/js/move_script_to_bottom ' ;
2425
25- /**
26- * @var JsFooterPlugin
27- */
26+ /** @var JsFooterPlugin */
2827 private $ plugin ;
2928
30- /**
31- * @var ScopeConfigInterface|MockObject
32- */
29+ /** @var ScopeConfigInterface|MockObject */
3330 private $ scopeConfigMock ;
3431
35- /**
36- * @var Http|MockObject
37- */
32+ /** @var Http|MockObject */
3833 private $ httpMock ;
3934
35+ /** @var Layout|MockObject */
36+ private $ layoutMock ;
37+
4038 /**
4139 * @inheritdoc
4240 */
@@ -48,6 +46,7 @@ protected function setUp(): void
4846 ->getMockForAbstractClass ();
4947
5048 $ this ->httpMock = $ this ->createMock (Http::class);
49+ $ this ->layoutMock = $ this ->createMock (Layout::class);
5150
5251 $ objectManager = new ObjectManagerHelper ($ this );
5352 $ this ->plugin = $ objectManager ->getObject (
@@ -59,11 +58,11 @@ protected function setUp(): void
5958 }
6059
6160 /**
62- * Data Provider for testBeforeSendResponse ()
61+ * Data Provider for testAfterRenderResult ()
6362 *
6463 * @return array
6564 */
66- public function sendResponseDataProvider (): array
65+ public function renderResultDataProvider (): array
6766 {
6867 return [
6968 'content_with_script_tag ' => [
@@ -74,9 +73,9 @@ public function sendResponseDataProvider(): array
7473 "flag " => true ,
7574 "result " => "<body><h1>Test Title</h1> " .
7675 "<script type= \"text/x-magento-template \">test</script> " .
77- "<p>Test Content</p> " .
78- "<script type= \"text/x-magento-init \">test</script> " .
79- "\n </body> "
76+ "<p>Test Content</p> \n " .
77+ "<script type= \"text/x-magento-init \">test</script> \n " .
78+ "</body> "
8079 ],
8180 'content_with_config_disable ' => [
8281 "content " => "<body><p>Test Content</p></body> " ,
@@ -98,67 +97,61 @@ public function sendResponseDataProvider(): array
9897 * @param bool $isSetFlag
9998 * @param string $result
10099 * @return void
101- * @dataProvider sendResponseDataProvider
100+ * @dataProvider renderResultDataProvider
102101 */
103- public function testBeforeSendResponse ($ content , $ isSetFlag , $ result ): void
102+ public function testAfterRenderResult ($ content , $ isSetFlag , $ result ): void
104103 {
105- $ this -> httpMock -> expects ( $ this -> once () )
106- ->method ('getContent ' )
104+ // Given (context )
105+ $ this -> httpMock ->method ('getContent ' )
107106 ->willReturn ($ content );
108107
109- $ this ->scopeConfigMock ->expects ($ this ->once ())
110- ->method ('isSetFlag ' )
111- ->with (
112- self ::STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM ,
113- ScopeInterface::SCOPE_STORE
114- )
108+ $ this ->scopeConfigMock ->method ('isSetFlag ' )
109+ ->with (self ::STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM , ScopeInterface::SCOPE_STORE )
115110 ->willReturn ($ isSetFlag );
116111
112+ // Expects
117113 $ this ->httpMock ->expects ($ this ->any ())
118114 ->method ('setContent ' )
119115 ->with ($ result );
120116
121- $ this ->plugin ->beforeSendResponse ($ this ->httpMock );
117+ // When
118+ $ this ->plugin ->afterRenderResult ($ this ->layoutMock , $ this ->layoutMock , $ this ->httpMock );
122119 }
123120
124121 /**
125- * Data Provider for testBeforeSendResponseIfGetContentIsNotAString ()
122+ * Data Provider for testAfterRenderResultIfGetContentIsNotAString ()
126123 *
127124 * @return array
128125 */
129126 public function ifGetContentIsNotAStringDataProvider (): array
130127 {
131128 return [
132- 'empty_array ' => [
133- 'content ' => []
134- ],
135129 'null ' => [
136130 'content ' => null
137131 ]
138132 ];
139133 }
140134
141135 /**
142- * Test BeforeSendResponse if content is not a string
136+ * Test AfterRenderResult if content is not a string
143137 *
144138 * @param string $content
145139 * @return void
146140 * @dataProvider ifGetContentIsNotAStringDataProvider
147141 */
148- public function testBeforeSendResponseIfGetContentIsNotAString ($ content ): void
142+ public function testAfterRenderResultIfGetContentIsNotAString ($ content ): void
149143 {
144+ $ this ->scopeConfigMock ->method ('isSetFlag ' )
145+ ->with (self ::STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM , ScopeInterface::SCOPE_STORE )
146+ ->willReturn (true );
147+
150148 $ this ->httpMock ->expects ($ this ->once ())
151149 ->method ('getContent ' )
152150 ->willReturn ($ content );
153151
154- $ this ->scopeConfigMock ->expects ($ this ->never ())
155- ->method ('isSetFlag ' )
156- ->with (
157- self ::STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM ,
158- ScopeInterface::SCOPE_STORE
159- )
160- ->willReturn (false );
152+ $ this ->httpMock ->expects ($ this ->never ())
153+ ->method ('setContent ' );
161154
162- $ this ->plugin ->beforeSendResponse ( $ this ->httpMock );
155+ $ this ->plugin ->afterRenderResult ( $ this -> layoutMock , $ this -> layoutMock , $ this ->httpMock );
163156 }
164157}
0 commit comments