9
9
10
10
use Magento \Csp \Model \SubresourceIntegrity ;
11
11
use Magento \Csp \Model \SubresourceIntegrityRepository ;
12
- use Magento \Framework \ App \ Request \ Http ;
12
+ use Magento \Csp \ Model \ SubresourceIntegrityRepositoryPool ;
13
13
use PHPUnit \Framework \MockObject \MockObject ;
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Magento \Csp \Plugin \AddDefaultPropertiesToGroupPlugin ;
16
16
use Magento \Framework \View \Asset \File ;
17
17
use Magento \Framework \View \Asset \GroupedCollection ;
18
+ use Magento \Framework \App \State ;
18
19
19
20
/**
20
21
* Test for class Magento\Csp\Plugin\AddDefaultPropertiesToGroupPlugin
@@ -26,17 +27,17 @@ class AddDefaultPropertiesToGroupPluginTest extends TestCase
26
27
/**
27
28
* @var MockObject
28
29
*/
29
- private MockObject $ requestMock ;
30
+ private MockObject $ assetInterfaceMock ;
30
31
31
32
/**
32
33
* @var MockObject
33
34
*/
34
- private MockObject $ assetInterfaceMock ;
35
+ private MockObject $ integrityRepositoryPoolMock ;
35
36
36
37
/**
37
38
* @var MockObject
38
39
*/
39
- private MockObject $ integrityRepositoryMock ;
40
+ private MockObject $ stateMock ;
40
41
41
42
/**
42
43
* @var array $controllerActions
@@ -56,23 +57,21 @@ class AddDefaultPropertiesToGroupPluginTest extends TestCase
56
57
protected function setUp (): void
57
58
{
58
59
parent ::setUp ();
59
- $ this ->integrityRepositoryMock = $ this ->getMockBuilder (SubresourceIntegrityRepository ::class)
60
+ $ this ->integrityRepositoryPoolMock = $ this ->getMockBuilder (SubresourceIntegrityRepositoryPool ::class)
60
61
->disableOriginalConstructor ()
61
- ->onlyMethods (['getByUrl ' ])
62
+ ->onlyMethods (['get ' ])
62
63
->getMock ();
63
64
$ this ->assetInterfaceMock = $ this ->getMockBuilder (File::class)
64
65
->disableOriginalConstructor ()
65
66
->onlyMethods (['getUrl ' , 'getContentType ' ])
66
67
->getMockForAbstractClass ();
67
- $ this ->requestMock = $ this ->getMockBuilder (Http ::class)
68
+ $ this ->stateMock = $ this ->getMockBuilder (State ::class)
68
69
->disableOriginalConstructor ()
69
- ->onlyMethods (['getFullActionName ' ])
70
+ ->onlyMethods (['getAreaCode ' ])
70
71
->getMock ();
71
- $ this ->controllerActions = ['checkout_index_index ' , 'sales_order_create ' ];
72
72
$ this ->plugin = new AddDefaultPropertiesToGroupPlugin (
73
- $ this ->requestMock ,
74
- $ this ->integrityRepositoryMock ,
75
- $ this ->controllerActions
73
+ $ this ->stateMock ,
74
+ $ this ->integrityRepositoryPoolMock
76
75
);
77
76
}
78
77
@@ -83,10 +82,15 @@ protected function setUp(): void
83
82
*/
84
83
public function testBeforeGetFilteredProperties (): void
85
84
{
85
+ $ integrityRepositoryMock = $ this ->getMockBuilder (SubresourceIntegrityRepository::class)
86
+ ->disableOriginalConstructor ()
87
+ ->onlyMethods (['getByUrl ' ])
88
+ ->getMock ();
86
89
$ groupedCollectionMock = $ this ->getMockBuilder (GroupedCollection::class)
87
90
->disableOriginalConstructor ()
88
91
->getMock ();
89
92
$ url = 'https://magento.test/static/version1708401324/frontend/Magento/luma/en_US/jquery.js ' ;
93
+ $ area = 'frontend ' ;
90
94
91
95
$ data = new SubresourceIntegrity (
92
96
[
@@ -97,29 +101,10 @@ public function testBeforeGetFilteredProperties(): void
97
101
$ properties ['attributes ' ]['integrity ' ] = $ data ->getHash ();
98
102
$ properties ['attributes ' ]['crossorigin ' ] = 'anonymous ' ;
99
103
$ expected = [$ this ->assetInterfaceMock , $ properties ];
100
- $ this ->assetInterfaceMock ->expects ($ this ->once ())->method ('getContentType ' )->willReturn ('js ' );
104
+ $ this ->stateMock ->expects ($ this ->once ())->method ('getAreaCode ' )->willReturn ($ area );
105
+ $ this ->integrityRepositoryPoolMock ->expects ($ this ->once ())->method ('get ' )->with ($ area )->willReturn ($ integrityRepositoryMock );
101
106
$ this ->assetInterfaceMock ->expects ($ this ->once ())->method ('getUrl ' )->willReturn ($ url );
102
- $ this ->integrityRepositoryMock ->expects ($ this ->once ())->method ('getByUrl ' )->with ($ url )->willReturn ($ data );
103
- $ this ->requestMock ->expects ($ this ->once ())->method ('getFullActionName ' )->willReturn ('sales_order_create ' );
104
- $ this ->assertEquals ($ expected ,
105
- $ this ->plugin ->beforeGetFilteredProperties ($ groupedCollectionMock , $ this ->assetInterfaceMock
106
- )
107
- );
108
- }
109
-
110
- /**
111
- * Test for plugin with css assets
112
- *
113
- * @return void
114
- */
115
- public function testBeforeGetFilteredPropertiesForCssAssets (): void
116
- {
117
- $ groupedCollectionMock = $ this ->getMockBuilder (GroupedCollection::class)
118
- ->disableOriginalConstructor ()
119
- ->getMock ();
120
- $ expected = [$ this ->assetInterfaceMock , []];
121
- $ this ->assetInterfaceMock ->expects ($ this ->once ())->method ('getContentType ' )->willReturn ('css ' );
122
- $ this ->requestMock ->expects ($ this ->once ())->method ('getFullActionName ' )->willReturn ('sales_order_create ' );
107
+ $ integrityRepositoryMock ->expects ($ this ->once ())->method ('getByUrl ' )->with ($ url )->willReturn ($ data );
123
108
$ this ->assertEquals ($ expected ,
124
109
$ this ->plugin ->beforeGetFilteredProperties ($ groupedCollectionMock , $ this ->assetInterfaceMock
125
110
)
0 commit comments