7
7
8
8
namespace Magento \Theme \Test \Unit \Controller \Result ;
9
9
10
- use Magento \Theme \Controller \Result \JsFooterPlugin ;
11
- use Magento \Framework \App \Response \Http ;
12
- use PHPUnit \Framework \TestCase ;
13
- use PHPUnit \Framework \MockObject \MockObject ;
14
10
use Magento \Framework \App \Config \ScopeConfigInterface ;
15
- use Magento \Store \ Model \ ScopeInterface ;
11
+ use Magento \Framework \ App \ Response \ Http ;
16
12
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
13
+ use Magento \Framework \View \Result \Layout ;
14
+ use Magento \Store \Model \ScopeInterface ;
15
+ use Magento \Theme \Controller \Result \JsFooterPlugin ;
16
+ use PHPUnit \Framework \MockObject \MockObject ;
17
+ use PHPUnit \Framework \TestCase ;
17
18
18
19
/**
19
20
* Unit test for Magento\Theme\Test\Unit\Controller\Result\JsFooterPlugin.
@@ -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 ' => [
@@ -98,31 +97,29 @@ 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
*/
@@ -136,21 +133,25 @@ public function ifGetContentIsNotAStringDataProvider(): array
136
133
}
137
134
138
135
/**
139
- * Test BeforeSendResponse if content is not a string
136
+ * Test AfterRenderResult if content is not a string
140
137
*
141
138
* @param string $content
142
139
* @return void
143
140
* @dataProvider ifGetContentIsNotAStringDataProvider
144
141
*/
145
- public function testBeforeSendResponseIfGetContentIsNotAString ($ content ): void
142
+ public function testAfterRenderResultIfGetContentIsNotAString ($ content ): void
146
143
{
144
+ $ this ->scopeConfigMock ->method ('isSetFlag ' )
145
+ ->with (self ::STUB_XML_PATH_DEV_MOVE_JS_TO_BOTTOM , ScopeInterface::SCOPE_STORE )
146
+ ->willReturn (true );
147
+
147
148
$ this ->httpMock ->expects ($ this ->once ())
148
149
->method ('getContent ' )
149
150
->willReturn ($ content );
150
151
151
152
$ this ->httpMock ->expects ($ this ->never ())
152
153
->method ('setContent ' );
153
154
154
- $ this ->plugin ->beforeSendResponse ( $ this ->httpMock );
155
+ $ this ->plugin ->afterRenderResult ( $ this -> layoutMock , $ this -> layoutMock , $ this ->httpMock );
155
156
}
156
157
}
0 commit comments