7
7
8
8
namespace Magento \Framework \Css \Test \Unit \PreProcessor \Instruction ;
9
9
10
+ use Magento \Framework \App \DeploymentConfig ;
10
11
use Magento \Framework \Css \PreProcessor \ErrorHandlerInterface ;
11
12
use Magento \Framework \Css \PreProcessor \Instruction \Import ;
12
13
use Magento \Framework \Css \PreProcessor \Instruction \MagentoImport ;
16
17
use Magento \Framework \View \Asset \File \FallbackContext ;
17
18
use Magento \Framework \View \Asset \PreProcessor \Chain ;
18
19
use Magento \Framework \View \Asset \Repository ;
20
+ use Magento \Framework \View \Design \Theme \ListInterface as ThemeListInterface ;
19
21
use Magento \Framework \View \Design \Theme \ThemeProviderInterface ;
20
22
use Magento \Framework \View \Design \ThemeInterface ;
21
23
use Magento \Framework \View \DesignInterface ;
@@ -54,36 +56,50 @@ class MagentoImportTest extends TestCase
54
56
private $ assetRepoMock ;
55
57
56
58
/**
57
- * @var ThemeProviderInterface |MockObject
59
+ * @var ThemeListInterface |MockObject
58
60
*/
59
- private $ themeProviderMock ;
61
+ private $ themeListMock ;
62
+
63
+ /**
64
+ * @var DeploymentConfig|MockObject
65
+ */
66
+ private $ deploymentConfigMock ;
60
67
61
68
/**
62
69
* @var ModuleManager|MockObject
63
70
*/
64
71
private $ moduleManagerMock ;
65
72
73
+ /**
74
+ * @var ThemeProviderInterface|MockObject
75
+ */
76
+ private $ themeProviderMock ;
66
77
/**
67
78
* @var Import
68
79
*/
69
80
private $ object ;
70
81
71
82
protected function setUp (): void
72
83
{
73
- $ this ->designMock = $ this ->getMockForAbstractClass (DesignInterface::class);
74
- $ this ->fileSourceMock = $ this ->getMockForAbstractClass (CollectorInterface::class);
75
- $ this ->errorHandlerMock = $ this ->getMockForAbstractClass (ErrorHandlerInterface::class);
84
+ $ this ->designMock = $ this ->createMock (DesignInterface::class);
85
+ $ this ->fileSourceMock = $ this ->createMock (CollectorInterface::class);
86
+ $ this ->errorHandlerMock = $ this ->createMock (ErrorHandlerInterface::class);
76
87
$ this ->assetMock = $ this ->createMock (File::class);
77
- $ this ->assetMock ->expects ( $ this -> any ())-> method ('getContentType ' )->willReturn ('css ' );
88
+ $ this ->assetMock ->method ('getContentType ' )->willReturn ('css ' );
78
89
$ this ->assetRepoMock = $ this ->createMock (Repository::class);
79
- $ this ->themeProviderMock = $ this ->getMockForAbstractClass (ThemeProviderInterface::class);
90
+ $ this ->themeListMock = $ this ->createMock (ThemeListInterface::class);
91
+ $ this ->deploymentConfigMock = $ this ->createMock (DeploymentConfig::class);
80
92
$ this ->moduleManagerMock = $ this ->createMock (ModuleManager::class);
81
93
94
+ $ this ->themeProviderMock = $ this ->createMock (ThemeProviderInterface::class);
95
+
82
96
$ this ->object = (new ObjectManager ($ this ))->getObject (MagentoImport::class, [
83
97
'design ' => $ this ->designMock ,
84
98
'fileSource ' => $ this ->fileSourceMock ,
85
99
'errorHandler ' => $ this ->errorHandlerMock ,
86
100
'assetRepo ' => $ this ->assetRepoMock ,
101
+ 'themeList ' => $ this ->themeListMock ,
102
+ 'deploymentConfig ' => $ this ->deploymentConfigMock ,
87
103
'moduleManager ' => $ this ->moduleManagerMock ,
88
104
// Mocking private property
89
105
'themeProvider ' => $ this ->themeProviderMock ,
@@ -97,7 +113,7 @@ protected function setUp(): void
97
113
* @param array $foundFiles
98
114
* @param string $expectedContent
99
115
* @param array $enabledModules
100
- *
116
+ * @param bool $onlyEnabled
101
117
* @dataProvider processDataProvider
102
118
*/
103
119
public function testProcess (
@@ -106,7 +122,8 @@ public function testProcess(
106
122
string $ resolvedPath ,
107
123
array $ foundFiles ,
108
124
string $ expectedContent ,
109
- array $ enabledModules
125
+ array $ enabledModules ,
126
+ bool $ onlyEnabled
110
127
): void
111
128
{
112
129
$ chain = new Chain ($ this ->assetMock , $ originalContent , 'css ' , 'path ' );
@@ -125,10 +142,10 @@ public function testProcess(
125
142
$ files = [];
126
143
foreach ($ foundFiles as $ file ) {
127
144
$ fileObject = $ this ->createMock (\Magento \Framework \View \File::class);
128
- $ fileObject-> expects ( $ this -> any ())
145
+ $ fileObject
129
146
->method ('getModule ' )
130
147
->willReturn ($ file ['module ' ]);
131
- $ fileObject-> expects ( $ this -> any ())
148
+ $ fileObject
132
149
->method ('getFilename ' )
133
150
->willReturn ($ file ['filename ' ]);
134
151
$ files [] = $ fileObject ;
@@ -138,7 +155,10 @@ public function testProcess(
138
155
->with ($ theme , $ resolvedPath )
139
156
->willReturn ($ files );
140
157
141
- $ this ->moduleManagerMock ->expects ($ this ->any ())->method ('isEnabled ' )
158
+ $ this ->deploymentConfigMock ->method ('get ' )->with ('static_content_only_enabled_modules ' )
159
+ ->willReturn ($ onlyEnabled );
160
+
161
+ $ this ->moduleManagerMock ->method ('isEnabled ' )
142
162
->willReturnCallback (function ($ moduleName ) use ($ enabledModules ) {
143
163
return in_array ($ moduleName , $ enabledModules , true );
144
164
});
@@ -164,6 +184,7 @@ public function processDataProvider(): array
164
184
],
165
185
"@import 'some/file.css'; \n@import 'some/file.css'; \n" ,
166
186
[],
187
+ true
167
188
],
168
189
'modular ' => [
169
190
'//@magento_import "Magento_Module::some/file.css"; ' ,
@@ -175,6 +196,7 @@ public function processDataProvider(): array
175
196
],
176
197
"@import 'Magento_Module::some/file.css'; \n@import 'Magento_Two::some/file.css'; \n" ,
177
198
['Magento_Module ' , 'Magento_Two ' ],
199
+ true
178
200
],
179
201
'modular with disabled module ' => [
180
202
'//@magento_import "Magento_Module::some/file.css"; ' ,
@@ -186,6 +208,7 @@ public function processDataProvider(): array
186
208
],
187
209
"@import 'Magento_Two::some/file.css'; \n" ,
188
210
['Magento_Two ' ],
211
+ true
189
212
],
190
213
'modular with disabled all modules ' => [
191
214
'//@magento_import "Magento_Module::some/file.css"; ' ,
@@ -197,6 +220,7 @@ public function processDataProvider(): array
197
220
],
198
221
'' ,
199
222
[],
223
+ true
200
224
],
201
225
'non-modular reference notation ' => [
202
226
'//@magento_import (reference) "some/file.css"; ' ,
@@ -208,6 +232,7 @@ public function processDataProvider(): array
208
232
],
209
233
"@import (reference) 'some/file.css'; \n@import (reference) 'some/file.css'; \n" ,
210
234
[],
235
+ true
211
236
],
212
237
'modular reference ' => [
213
238
'//@magento_import (reference) "Magento_Module::some/file.css"; ' ,
@@ -220,6 +245,7 @@ public function processDataProvider(): array
220
245
"@import (reference) 'Magento_Module::some/file.css'; \n" .
221
246
"@import (reference) 'Magento_Two::some/file.css'; \n" ,
222
247
['Magento_Module ' , 'Magento_Two ' ],
248
+ true
223
249
],
224
250
'modular reference with disabled module ' => [
225
251
'//@magento_import (reference) "Magento_Module::some/file.css"; ' ,
@@ -231,6 +257,20 @@ public function processDataProvider(): array
231
257
],
232
258
"@import (reference) 'Magento_Module::some/file.css'; \n" ,
233
259
['Magento_Module ' ],
260
+ true
261
+ ],
262
+ 'modular reference with disabled module and disabled "only enabled modules" flag ' => [
263
+ '//@magento_import (reference) "Magento_Module::some/file.css"; ' ,
264
+ 'Magento_Module::some/file.css ' ,
265
+ 'some/file.css ' ,
266
+ [
267
+ ['module ' => 'Magento_Module ' , 'filename ' => 'some/file.css ' ],
268
+ ['module ' => 'Magento_Two ' , 'filename ' => 'some/file.css ' ],
269
+ ],
270
+ "@import (reference) 'Magento_Module::some/file.css'; \n" .
271
+ "@import (reference) 'Magento_Two::some/file.css'; \n" ,
272
+ ['Magento_Module ' ],
273
+ false
234
274
],
235
275
'modular reference with disabled all modules ' => [
236
276
'//@magento_import (reference) "Magento_Module::some/file.css"; ' ,
@@ -242,6 +282,20 @@ public function processDataProvider(): array
242
282
],
243
283
'' ,
244
284
[],
285
+ true
286
+ ],
287
+ 'modular reference with disabled all modules and disabled "only enabled modules" flag ' => [
288
+ '//@magento_import (reference) "Magento_Module::some/file.css"; ' ,
289
+ 'Magento_Module::some/file.css ' ,
290
+ 'some/file.css ' ,
291
+ [
292
+ ['module ' => 'Magento_Module ' , 'filename ' => 'some/file.css ' ],
293
+ ['module ' => 'Magento_Two ' , 'filename ' => 'some/file.css ' ],
294
+ ],
295
+ "@import (reference) 'Magento_Module::some/file.css'; \n" .
296
+ "@import (reference) 'Magento_Two::some/file.css'; \n" ,
297
+ [],
298
+ false
245
299
],
246
300
];
247
301
}
0 commit comments