11<?php
2+
23/**
34 * Copyright © Magento, Inc. All rights reserved.
45 * See COPYING.txt for license details.
56 */
7+
68declare (strict_types=1 );
79
810namespace Magento \Theme \Test \Unit \Controller \Result ;
911
1012use Magento \Theme \Controller \Result \AsyncCssPlugin ;
13+ use Magento \Csp \Api \InlineUtilInterface ;
1114use Magento \Framework \App \Response \Http ;
1215use PHPUnit \Framework \TestCase ;
1316use PHPUnit \Framework \MockObject \MockObject ;
@@ -38,9 +41,16 @@ class AsyncCssPluginTest extends TestCase
3841 */
3942 private $ httpMock ;
4043
41- /** @var Layout|MockObject */
44+ /**
45+ * @var Layout|MockObject
46+ */
4247 private $ layoutMock ;
4348
49+ /**
50+ * @var InlineUtilInterface|MockObject
51+ */
52+ private $ cspInlineUtilMock ;
53+
4454 /**
4555 * @inheritdoc
4656 */
@@ -53,12 +63,14 @@ protected function setUp(): void
5363
5464 $ this ->httpMock = $ this ->createMock (Http::class);
5565 $ this ->layoutMock = $ this ->createMock (Layout::class);
66+ $ this ->cspInlineUtilMock = $ this ->createMock (InlineUtilInterface::class);
5667
5768 $ objectManager = new ObjectManagerHelper ($ this );
5869 $ this ->plugin = $ objectManager ->getObject (
5970 AsyncCssPlugin::class,
6071 [
61- 'scopeConfig ' => $ this ->scopeConfigMock
72+ 'scopeConfig ' => $ this ->scopeConfigMock ,
73+ 'cspInlineUtil ' => $ this ->cspInlineUtilMock
6274 ]
6375 );
6476 }
@@ -149,6 +161,14 @@ public function testAfterRenderResult(string $content, bool $isSetFlag, string $
149161 ->with (self ::STUB_XML_PATH_USE_CSS_CRITICAL_PATH , ScopeInterface::SCOPE_STORE )
150162 ->willReturn ($ isSetFlag );
151163
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+ }
152172 // Expects
153173 $ this ->httpMock ->expects ($ this ->any ())
154174 ->method ('setContent ' )
0 commit comments