5
5
*/
6
6
namespace Magento \Email \Test \Unit \Model \Template ;
7
7
8
+ use Magento \Email \Model \Template \Css \Processor ;
9
+ use Magento \Email \Model \Template \Filter ;
10
+ use Magento \Framework \App \Area ;
11
+ use Magento \Framework \App \Filesystem \DirectoryList ;
12
+ use Magento \Framework \Filesystem \Directory \ReadInterface ;
13
+ use Magento \Framework \View \Asset \File \FallbackContext ;
14
+
8
15
/**
9
16
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
10
17
*/
@@ -94,7 +101,6 @@ protected function setUp()
94
101
95
102
$ this ->escaper = $ this ->getMockBuilder (\Magento \Framework \Escaper::class)
96
103
->disableOriginalConstructor ()
97
- ->enableProxyingToOriginalMethods ()
98
104
->getMock ();
99
105
100
106
$ this ->assetRepo = $ this ->getMockBuilder (\Magento \Framework \View \Asset \Repository::class)
@@ -138,7 +144,7 @@ protected function setUp()
138
144
139
145
/**
140
146
* @param array|null $mockedMethods Methods to mock
141
- * @return \Magento\Email\Model\Template\ Filter|\PHPUnit_Framework_MockObject_MockObject
147
+ * @return Filter|\PHPUnit_Framework_MockObject_MockObject
142
148
*/
143
149
protected function getModel ($ mockedMethods = null )
144
150
{
@@ -252,13 +258,23 @@ public function transDirectiveDataProvider()
252
258
public function testApplyInlineCss ($ html , $ css , $ expectedResults )
253
259
{
254
260
$ filter = $ this ->getModel (['getCssFilesContent ' ]);
261
+ $ cssProcessor = $ this ->getMockBuilder (Processor::class)
262
+ ->disableOriginalConstructor ()
263
+ ->getMock ();
264
+ $ reflectionClass = new \ReflectionClass (Filter::class);
265
+ $ reflectionProperty = $ reflectionClass ->getProperty ('cssProcessor ' );
266
+ $ reflectionProperty ->setAccessible (true );
267
+ $ reflectionProperty ->setValue ($ filter , $ cssProcessor );
268
+ $ cssProcessor ->expects ($ this ->any ())
269
+ ->method ('process ' )
270
+ ->willReturnArgument (0 );
255
271
256
272
$ filter ->expects ($ this ->exactly (count ($ expectedResults )))
257
273
->method ('getCssFilesContent ' )
258
274
->will ($ this ->returnValue ($ css ));
259
275
260
276
$ designParams = [
261
- 'area ' => \ Magento \ Framework \ App \ Area::AREA_FRONTEND ,
277
+ 'area ' => Area::AREA_FRONTEND ,
262
278
'theme ' => 'themeId ' ,
263
279
'locale ' => 'localeId ' ,
264
280
];
@@ -269,6 +285,60 @@ public function testApplyInlineCss($html, $css, $expectedResults)
269
285
}
270
286
}
271
287
288
+ public function testGetCssFilesContent ()
289
+ {
290
+ $ file = 'css/email.css ' ;
291
+ $ path = Area::AREA_FRONTEND . '/themeId/localeId ' ;
292
+ $ css = 'p{color:black} ' ;
293
+ $ designParams = [
294
+ 'area ' => Area::AREA_FRONTEND ,
295
+ 'theme ' => 'themeId ' ,
296
+ 'locale ' => 'localeId ' ,
297
+ ];
298
+ $ filter = $ this ->getModel ();
299
+
300
+ $ asset = $ this ->getMockBuilder (\Magento \Framework \View \Asset \File::class)
301
+ ->disableOriginalConstructor ()
302
+ ->getMock ();
303
+
304
+ $ fallbackContext = $ this ->getMockBuilder (FallbackContext::class)
305
+ ->disableOriginalConstructor ()
306
+ ->getMock ();
307
+ $ fallbackContext ->expects ($ this ->once ())
308
+ ->method ('getBaseDirType ' )
309
+ ->willReturn (DirectoryList::STATIC_VIEW );
310
+ $ asset ->expects ($ this ->atLeastOnce ())
311
+ ->method ('getContext ' )
312
+ ->willReturn ($ fallbackContext );
313
+
314
+ $ asset ->expects ($ this ->atLeastOnce ())
315
+ ->method ('getPath ' )
316
+ ->willReturn ($ path . DIRECTORY_SEPARATOR . $ file );
317
+ $ this ->assetRepo ->expects ($ this ->once ())
318
+ ->method ('createAsset ' )
319
+ ->with ($ file , $ designParams )
320
+ ->willReturn ($ asset );
321
+
322
+ $ pubDirectory = $ this ->getMockBuilder (ReadInterface::class)
323
+ ->getMockForAbstractClass ();
324
+ $ reflectionClass = new \ReflectionClass (Filter::class);
325
+ $ reflectionProperty = $ reflectionClass ->getProperty ('pubDirectory ' );
326
+ $ reflectionProperty ->setAccessible (true );
327
+ $ reflectionProperty ->setValue ($ filter , $ pubDirectory );
328
+ $ pubDirectory ->expects ($ this ->once ())
329
+ ->method ('isExist ' )
330
+ ->with ($ path . DIRECTORY_SEPARATOR . $ file )
331
+ ->willReturn (true );
332
+ $ pubDirectory ->expects ($ this ->once ())
333
+ ->method ('readFile ' )
334
+ ->with ($ path . DIRECTORY_SEPARATOR . $ file )
335
+ ->willReturn ($ css );
336
+
337
+ $ filter ->setDesignParams ($ designParams );
338
+
339
+ $ this ->assertEquals ($ css , $ filter ->getCssFilesContent ([$ file ]));
340
+ }
341
+
272
342
/**
273
343
* @return array
274
344
*/
@@ -301,7 +371,19 @@ public function applyInlineCssDataProvider()
301
371
*/
302
372
public function testApplyInlineCssThrowsExceptionWhenDesignParamsNotSet ()
303
373
{
304
- $ this ->getModel ()->applyInlineCss ('test ' );
374
+ $ filter = $ this ->getModel ();
375
+ $ cssProcessor = $ this ->getMockBuilder (Processor::class)
376
+ ->disableOriginalConstructor ()
377
+ ->getMock ();
378
+ $ reflectionClass = new \ReflectionClass (Filter::class);
379
+ $ reflectionProperty = $ reflectionClass ->getProperty ('cssProcessor ' );
380
+ $ reflectionProperty ->setAccessible (true );
381
+ $ reflectionProperty ->setValue ($ filter , $ cssProcessor );
382
+ $ cssProcessor ->expects ($ this ->any ())
383
+ ->method ('process ' )
384
+ ->willReturnArgument (0 );
385
+
386
+ $ filter ->applyInlineCss ('test ' );
305
387
}
306
388
307
389
/**
@@ -348,7 +430,10 @@ public function testConfigDirectiveAvailable()
348
430
$ construction = ["{{config path= {$ path }}} " , 'config ' , " path= {$ path }" ];
349
431
$ scopeConfigValue = 'value ' ;
350
432
351
- $ storeMock = $ this ->getMock (\Magento \Store \Api \Data \StoreInterface::class, [], [], '' , false );
433
+ $ storeMock = $ this ->getMockBuilder (\Magento \Store \Api \Data \StoreInterface::class)
434
+ ->disableOriginalConstructor ()
435
+ ->getMock ();
436
+
352
437
$ this ->storeManager ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ storeMock );
353
438
$ storeMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
354
439
@@ -369,7 +454,9 @@ public function testConfigDirectiveUnavailable()
369
454
$ construction = ["{{config path= {$ path }}} " , 'config ' , " path= {$ path }" ];
370
455
$ scopeConfigValue = '' ;
371
456
372
- $ storeMock = $ this ->getMock (\Magento \Store \Api \Data \StoreInterface::class, [], [], '' , false );
457
+ $ storeMock = $ this ->getMockBuilder (\Magento \Store \Api \Data \StoreInterface::class)
458
+ ->disableOriginalConstructor ()
459
+ ->getMock ();
373
460
$ this ->storeManager ->expects ($ this ->once ())->method ('getStore ' )->willReturn ($ storeMock );
374
461
$ storeMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
375
462
0 commit comments