10
10
use Magento \Framework \App \Config \ScopeConfigInterface ;
11
11
use Magento \Framework \App \Response \Http ;
12
12
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
13
+ use Magento \Framework \View \Result \Layout ;
13
14
use Magento \Store \Model \ScopeInterface ;
14
15
use Magento \Theme \Controller \Result \JsFooterPlugin ;
15
16
use PHPUnit \Framework \MockObject \MockObject ;
@@ -22,21 +23,18 @@ class JsFooterPluginTest extends TestCase
22
23
{
23
24
const STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM = 'dev/js/move_script_to_bottom ' ;
24
25
25
- /**
26
- * @var JsFooterPlugin
27
- */
26
+ /** @var JsFooterPlugin */
28
27
private $ plugin ;
29
28
30
- /**
31
- * @var ScopeConfigInterface|MockObject
32
- */
29
+ /** @var ScopeConfigInterface|MockObject */
33
30
private $ scopeConfigMock ;
34
31
35
- /**
36
- * @var Http|MockObject
37
- */
32
+ /** @var Http|MockObject */
38
33
private $ httpMock ;
39
34
35
+ /** @var Layout|MockObject */
36
+ private $ layoutMock ;
37
+
40
38
/**
41
39
* @inheritdoc
42
40
*/
@@ -48,6 +46,7 @@ protected function setUp(): void
48
46
->getMockForAbstractClass ();
49
47
50
48
$ this ->httpMock = $ this ->createMock (Http::class);
49
+ $ this ->layoutMock = $ this ->createMock (Layout::class);
51
50
52
51
$ objectManager = new ObjectManagerHelper ($ this );
53
52
$ this ->plugin = $ objectManager ->getObject (
@@ -59,11 +58,11 @@ protected function setUp(): void
59
58
}
60
59
61
60
/**
62
- * Data Provider for testBeforeSendResponse ()
61
+ * Data Provider for testAfterRenderResult ()
63
62
*
64
63
* @return array
65
64
*/
66
- public function sendResponseDataProvider (): array
65
+ public function renderResultDataProvider (): array
67
66
{
68
67
return [
69
68
'content_with_script_tag ' => [
@@ -74,9 +73,9 @@ public function sendResponseDataProvider(): array
74
73
"flag " => true ,
75
74
"result " => "<body><h1>Test Title</h1> " .
76
75
"<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> "
80
79
],
81
80
'content_with_config_disable ' => [
82
81
"content " => "<body><p>Test Content</p></body> " ,
@@ -98,67 +97,61 @@ public function sendResponseDataProvider(): array
98
97
* @param bool $isSetFlag
99
98
* @param string $result
100
99
* @return void
101
- * @dataProvider sendResponseDataProvider
100
+ * @dataProvider renderResultDataProvider
102
101
*/
103
- public function testBeforeSendResponse ($ content , $ isSetFlag , $ result ): void
102
+ public function testAfterRenderResult ($ content , $ isSetFlag , $ result ): void
104
103
{
105
- $ this -> httpMock -> expects ( $ this -> once () )
106
- ->method ('getContent ' )
104
+ // Given (context )
105
+ $ this -> httpMock ->method ('getContent ' )
107
106
->willReturn ($ content );
108
107
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 )
115
110
->willReturn ($ isSetFlag );
116
111
112
+ // Expects
117
113
$ this ->httpMock ->expects ($ this ->any ())
118
114
->method ('setContent ' )
119
115
->with ($ result );
120
116
121
- $ this ->plugin ->beforeSendResponse ($ this ->httpMock );
117
+ // When
118
+ $ this ->plugin ->afterRenderResult ($ this ->layoutMock , $ this ->layoutMock , $ this ->httpMock );
122
119
}
123
120
124
121
/**
125
- * Data Provider for testBeforeSendResponseIfGetContentIsNotAString ()
122
+ * Data Provider for testAfterRenderResultIfGetContentIsNotAString ()
126
123
*
127
124
* @return array
128
125
*/
129
126
public function ifGetContentIsNotAStringDataProvider (): array
130
127
{
131
128
return [
132
- 'empty_array ' => [
133
- 'content ' => []
134
- ],
135
129
'null ' => [
136
130
'content ' => null
137
131
]
138
132
];
139
133
}
140
134
141
135
/**
142
- * Test BeforeSendResponse if content is not a string
136
+ * Test AfterRenderResult if content is not a string
143
137
*
144
138
* @param string $content
145
139
* @return void
146
140
* @dataProvider ifGetContentIsNotAStringDataProvider
147
141
*/
148
- public function testBeforeSendResponseIfGetContentIsNotAString ($ content ): void
142
+ public function testAfterRenderResultIfGetContentIsNotAString ($ content ): void
149
143
{
144
+ $ this ->scopeConfigMock ->method ('isSetFlag ' )
145
+ ->with (self ::STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM , ScopeInterface::SCOPE_STORE )
146
+ ->willReturn (true );
147
+
150
148
$ this ->httpMock ->expects ($ this ->once ())
151
149
->method ('getContent ' )
152
150
->willReturn ($ content );
153
151
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 ' );
161
154
162
- $ this ->plugin ->beforeSendResponse ( $ this ->httpMock );
155
+ $ this ->plugin ->afterRenderResult ( $ this -> layoutMock , $ this -> layoutMock , $ this ->httpMock );
163
156
}
164
157
}
0 commit comments