3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
7
+ declare (strict_types=1 );
8
+
6
9
namespace Magento \Email \Test \Unit \Model \Template ;
7
10
8
11
use Magento \Email \Model \Template \Css \Processor ;
14
17
15
18
/**
16
19
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20
+ * @SuppressWarnings(PHPMD.TooManyFields)
17
21
*/
18
22
class FilterTest extends \PHPUnit \Framework \TestCase
19
23
{
@@ -92,6 +96,31 @@ class FilterTest extends \PHPUnit\Framework\TestCase
92
96
*/
93
97
private $ cssInliner ;
94
98
99
+ /**
100
+ * @var \PHPUnit\Framework\MockObject\MockObject|\Magento\Email\Model\Template\Css\Processor
101
+ */
102
+ private $ cssProcessor ;
103
+
104
+ /**
105
+ * @var \PHPUnit\Framework\MockObject\MockObject|\Magento\Framework\Filesystem
106
+ */
107
+ private $ pubDirectory ;
108
+
109
+ /**
110
+ * @var \PHPUnit\Framework\MockObject\MockObject|\Magento\Framework\Filesystem\Directory\Read
111
+ */
112
+ private $ pubDirectoryRead ;
113
+
114
+ /**
115
+ * @var \PHPUnit\Framework\MockObject\MockObject|\Magento\Framework\Filter\VariableResolver\StrategyResolver
116
+ */
117
+ private $ variableResolver ;
118
+
119
+ /**
120
+ * @var array
121
+ */
122
+ private $ directiveProcessors ;
123
+
95
124
protected function setUp ()
96
125
{
97
126
$ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
@@ -147,6 +176,41 @@ protected function setUp()
147
176
$ this ->cssInliner = $ this ->objectManager ->getObject (
148
177
\Magento \Framework \Css \PreProcessor \Adapter \CssInliner::class
149
178
);
179
+
180
+ $ this ->cssProcessor = $ this ->getMockBuilder (\Magento \Email \Model \Template \Css \Processor::class)
181
+ ->disableOriginalConstructor ()
182
+ ->getMock ();
183
+
184
+ $ this ->pubDirectory = $ this ->getMockBuilder (\Magento \Framework \Filesystem::class)
185
+ ->disableOriginalConstructor ()
186
+ ->getMock ();
187
+
188
+ $ this ->pubDirectoryRead = $ this ->getMockBuilder (\Magento \Framework \Filesystem \Directory \Read::class)
189
+ ->disableOriginalConstructor ()
190
+ ->getMock ();
191
+ $ this ->variableResolver =
192
+ $ this ->getMockBuilder (\Magento \Framework \Filter \VariableResolver \StrategyResolver::class)
193
+ ->disableOriginalConstructor ()
194
+ ->getMock ();
195
+
196
+ $ this ->directiveProcessors = [
197
+ 'depend ' =>
198
+ $ this ->getMockBuilder (\Magento \Framework \Filter \DirectiveProcessor \DependDirective::class)
199
+ ->disableOriginalConstructor ()
200
+ ->getMock (),
201
+ 'if ' =>
202
+ $ this ->getMockBuilder (\Magento \Framework \Filter \DirectiveProcessor \IfDirective::class)
203
+ ->disableOriginalConstructor ()
204
+ ->getMock (),
205
+ 'template ' =>
206
+ $ this ->getMockBuilder (\Magento \Framework \Filter \DirectiveProcessor \TemplateDirective::class)
207
+ ->disableOriginalConstructor ()
208
+ ->getMock (),
209
+ 'legacy ' =>
210
+ $ this ->getMockBuilder (\Magento \Framework \Filter \DirectiveProcessor \LegacyDirective::class)
211
+ ->disableOriginalConstructor ()
212
+ ->getMock (),
213
+ ];
150
214
}
151
215
152
216
/**
@@ -173,6 +237,10 @@ protected function getModel($mockedMethods = null)
173
237
$ this ->configVariables ,
174
238
[],
175
239
$ this ->cssInliner ,
240
+ $ this ->directiveProcessors ,
241
+ $ this ->variableResolver ,
242
+ $ this ->cssProcessor ,
243
+ $ this ->pubDirectory
176
244
]
177
245
)
178
246
->setMethods ($ mockedMethods )
@@ -252,17 +320,16 @@ public function testGetCssFilesContent()
252
320
->with ($ file , $ designParams )
253
321
->willReturn ($ asset );
254
322
255
- $ pubDirectory = $ this ->getMockBuilder (ReadInterface::class)
256
- ->getMockForAbstractClass ();
257
- $ reflectionClass = new \ReflectionClass (Filter::class);
258
- $ reflectionProperty = $ reflectionClass ->getProperty ('pubDirectory ' );
259
- $ reflectionProperty ->setAccessible (true );
260
- $ reflectionProperty ->setValue ($ filter , $ pubDirectory );
261
- $ pubDirectory ->expects ($ this ->once ())
323
+ $ this ->pubDirectory
324
+ ->expects ($ this ->once ())
325
+ ->method ('getDirectoryRead ' )
326
+ ->willReturn ($ this ->pubDirectoryRead );
327
+
328
+ $ this ->pubDirectoryRead ->expects ($ this ->once ())
262
329
->method ('isExist ' )
263
330
->with ($ path . DIRECTORY_SEPARATOR . $ file )
264
331
->willReturn (true );
265
- $ pubDirectory ->expects ($ this ->once ())
332
+ $ this -> pubDirectoryRead ->expects ($ this ->once ())
266
333
->method ('readFile ' )
267
334
->with ($ path . DIRECTORY_SEPARATOR . $ file )
268
335
->willReturn ($ css );
@@ -319,43 +386,6 @@ public function testApplyInlineCssThrowsExceptionWhenDesignParamsNotSet()
319
386
$ filter ->applyInlineCss ('test ' );
320
387
}
321
388
322
- /**
323
- * Ensure that after filter callbacks are reset after exception is thrown during filtering
324
- */
325
- public function testAfterFilterCallbackGetsResetWhenExceptionTriggered ()
326
- {
327
- $ value = '{{var random_var}} ' ;
328
- $ exception = new \Exception ('Test exception ' );
329
- $ exceptionResult = sprintf (__ ('Error filtering template: %s ' ), $ exception ->getMessage ());
330
-
331
- $ this ->appState ->expects ($ this ->once ())
332
- ->method ('getMode ' )
333
- ->will ($ this ->returnValue (\Magento \Framework \App \State::MODE_DEVELOPER ));
334
- $ this ->logger ->expects ($ this ->once ())
335
- ->method ('critical ' )
336
- ->with ($ exception );
337
-
338
- $ filter = $ this ->getModel (['varDirective ' , 'resetAfterFilterCallbacks ' ]);
339
- $ filter ->expects ($ this ->once ())
340
- ->method ('varDirective ' )
341
- ->will ($ this ->throwException ($ exception ));
342
-
343
- // Callbacks must be reset after exception is thrown
344
- $ filter ->expects ($ this ->once ())
345
- ->method ('resetAfterFilterCallbacks ' );
346
-
347
- // Build arbitrary object to pass into the addAfterFilterCallback method
348
- $ callbackObject = $ this ->getMockBuilder ('stdObject ' )
349
- ->setMethods (['afterFilterCallbackMethod ' ])
350
- ->getMock ();
351
- // Callback should never run due to exception happening during filtering
352
- $ callbackObject ->expects ($ this ->never ())
353
- ->method ('afterFilterCallbackMethod ' );
354
- $ filter ->addAfterFilterCallback ([$ callbackObject , 'afterFilterCallbackMethod ' ]);
355
-
356
- $ this ->assertEquals ($ exceptionResult , $ filter ->filter ($ value ));
357
- }
358
-
359
389
public function testConfigDirectiveAvailable ()
360
390
{
361
391
$ path = "web/unsecure/base_url " ;
0 commit comments