1
1
<?php
2
+
2
3
/**
3
4
* Copyright © Magento, Inc. All rights reserved.
4
5
* See COPYING.txt for license details.
5
6
*/
7
+
6
8
declare (strict_types=1 );
7
9
8
10
namespace Magento \Theme \Test \Unit \Controller \Result ;
9
11
10
12
use Magento \Theme \Controller \Result \AsyncCssPlugin ;
13
+ use Magento \Csp \Api \InlineUtilInterface ;
11
14
use Magento \Framework \App \Response \Http ;
12
15
use PHPUnit \Framework \TestCase ;
13
16
use PHPUnit \Framework \MockObject \MockObject ;
@@ -38,9 +41,16 @@ class AsyncCssPluginTest extends TestCase
38
41
*/
39
42
private $ httpMock ;
40
43
41
- /** @var Layout|MockObject */
44
+ /**
45
+ * @var Layout|MockObject
46
+ */
42
47
private $ layoutMock ;
43
48
49
+ /**
50
+ * @var InlineUtilInterface|MockObject
51
+ */
52
+ private $ cspInlineUtilMock ;
53
+
44
54
/**
45
55
* @inheritdoc
46
56
*/
@@ -53,12 +63,14 @@ protected function setUp(): void
53
63
54
64
$ this ->httpMock = $ this ->createMock (Http::class);
55
65
$ this ->layoutMock = $ this ->createMock (Layout::class);
66
+ $ this ->cspInlineUtilMock = $ this ->createMock (InlineUtilInterface::class);
56
67
57
68
$ objectManager = new ObjectManagerHelper ($ this );
58
69
$ this ->plugin = $ objectManager ->getObject (
59
70
AsyncCssPlugin::class,
60
71
[
61
- 'scopeConfig ' => $ this ->scopeConfigMock
72
+ 'scopeConfig ' => $ this ->scopeConfigMock ,
73
+ 'cspInlineUtil ' => $ this ->cspInlineUtilMock
62
74
]
63
75
);
64
76
}
@@ -149,6 +161,14 @@ public function testAfterRenderResult(string $content, bool $isSetFlag, string $
149
161
->with (self ::STUB_XML_PATH_USE_CSS_CRITICAL_PATH , ScopeInterface::SCOPE_STORE )
150
162
->willReturn ($ isSetFlag );
151
163
164
+ if ($ isSetFlag ) {
165
+ $ this ->cspInlineUtilMock ->expects ($ this ->any ())
166
+ ->method ('renderEventListener ' )
167
+ ->with (
168
+ 'onload ' ,
169
+ "this.onload=null;this.media='all' "
170
+ )->willReturn ('onload="this.onload=null;this.media= \'all \'" ' );
171
+ }
152
172
// Expects
153
173
$ this ->httpMock ->expects ($ this ->any ())
154
174
->method ('setContent ' )
0 commit comments