10
10
use Magento \Framework \View \Design \Fallback \RulePool ;
11
11
use Magento \Framework \View \Design \FileResolution \Fallback \TemplateFile ;
12
12
use Magento \Framework \View \Design \FileResolution \Fallback \ResolverInterface ;
13
+ use Magento \Framework \View \Template \Html \MinifierInterface ;
14
+ use Magento \Framework \View \Asset \ConfigInterface ;
15
+ use Magento \Framework \App \DeploymentConfig ;
16
+ use Magento \Framework \Config \ConfigOptionsListConstants ;
13
17
14
18
class TemplateFileTest extends \PHPUnit \Framework \TestCase
15
19
{
@@ -19,12 +23,12 @@ class TemplateFileTest extends \PHPUnit\Framework\TestCase
19
23
protected $ resolver ;
20
24
21
25
/**
22
- * @var \Magento\Framework\View\Template\Html\ MinifierInterface|\PHPUnit_Framework_MockObject_MockObject
26
+ * @var MinifierInterface|\PHPUnit_Framework_MockObject_MockObject
23
27
*/
24
28
protected $ minifier ;
25
29
26
30
/**
27
- * @var \Magento\Framework\App\ State|\PHPUnit_Framework_MockObject_MockObject
31
+ * @var State|\PHPUnit_Framework_MockObject_MockObject
28
32
*/
29
33
protected $ state ;
30
34
@@ -34,26 +38,29 @@ class TemplateFileTest extends \PHPUnit\Framework\TestCase
34
38
protected $ object ;
35
39
36
40
/**
37
- * @var \Magento\Framework\View\Asset\ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
41
+ * @var DeploymentConfig|\PHPUnit_Framework_MockObject_MockObject
42
+ */
43
+ private $ deploymentConfigMock ;
44
+
45
+ /**
46
+ * @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
38
47
*/
39
48
protected $ assetConfig ;
40
49
41
50
protected function setUp ()
42
51
{
43
- $ this ->resolver = $ this ->createMock (
44
- \Magento \Framework \View \Design \FileResolution \Fallback \ResolverInterface::class
45
- );
46
- $ this ->minifier = $ this ->createMock (\Magento \Framework \View \Template \Html \MinifierInterface::class);
47
- $ this ->state = $ this ->getMockBuilder (
48
- \Magento \Framework \App \State::class
49
- )->disableOriginalConstructor ()->getMock ();
50
- $ this ->assetConfig = $ this ->getMockForAbstractClass (
51
- \Magento \Framework \View \Asset \ConfigInterface::class,
52
- [],
53
- '' ,
54
- false
52
+ $ this ->resolver = $ this ->getMockForAbstractClass (ResolverInterface::class);
53
+ $ this ->minifier = $ this ->getMockForAbstractClass (MinifierInterface::class);
54
+ $ this ->state = $ this ->createMock (State::class);
55
+ $ this ->assetConfig = $ this ->getMockForAbstractClass (ConfigInterface::class);
56
+ $ this ->deploymentConfigMock = $ this ->createMock (DeploymentConfig::class);
57
+ $ this ->object = new TemplateFile (
58
+ $ this ->resolver ,
59
+ $ this ->minifier ,
60
+ $ this ->state ,
61
+ $ this ->assetConfig ,
62
+ $ this ->deploymentConfigMock
55
63
);
56
- $ this ->object = new TemplateFile ($ this ->resolver , $ this ->minifier , $ this ->state , $ this ->assetConfig );
57
64
}
58
65
59
66
/**
@@ -75,7 +82,7 @@ public function testGetFileWhenStateDeveloper()
75
82
$ this ->resolver ->expects ($ this ->once ())
76
83
->method ('resolve ' )
77
84
->with (RulePool::TYPE_TEMPLATE_FILE , 'file.ext ' , 'frontend ' , $ theme , null , 'Magento_Module ' )
78
- ->will ( $ this -> returnValue ( $ expected) );
85
+ ->willReturn ( $ expected );
79
86
80
87
$ actual = $ this ->object ->getFile ('frontend ' , $ theme , 'file.ext ' , 'Magento_Module ' );
81
88
$ this ->assertSame ($ expected , $ actual );
@@ -84,10 +91,11 @@ public function testGetFileWhenStateDeveloper()
84
91
/**
85
92
* Cover getFile when mode is default
86
93
* @param string $mode
94
+ * @param integer $onDemandInProduction
87
95
* @param string $method
88
96
* @dataProvider getMinifiedDataProvider
89
97
*/
90
- public function testGetFileWhenModifiedNeeded ($ mode , $ method )
98
+ public function testGetFileWhenModifiedNeeded ($ mode , $ onDemandInProduction , $ method )
91
99
{
92
100
$ this ->assetConfig
93
101
->expects ($ this ->once ())
@@ -98,13 +106,17 @@ public function testGetFileWhenModifiedNeeded($mode, $method)
98
106
$ expected = 'some/file.ext ' ;
99
107
$ expectedMinified = '/path/to/minified/some/file.ext ' ;
100
108
109
+ $ this ->deploymentConfigMock ->expects ($ this ->any ())
110
+ ->method ('getConfigData ' )
111
+ ->with (ConfigOptionsListConstants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION )
112
+ ->willReturn ($ onDemandInProduction );
101
113
$ this ->state ->expects ($ this ->once ())
102
114
->method ('getMode ' )
103
115
->willReturn ($ mode );
104
116
$ this ->resolver ->expects ($ this ->once ())
105
117
->method ('resolve ' )
106
118
->with (RulePool::TYPE_TEMPLATE_FILE , 'file.ext ' , 'frontend ' , $ theme , null , 'Magento_Module ' )
107
- ->will ( $ this -> returnValue ( $ expected) );
119
+ ->willReturn ( $ expected );
108
120
$ this ->minifier ->expects ($ this ->once ())
109
121
->method ($ method )
110
122
->with ($ expected )
@@ -127,9 +139,10 @@ public function testGetFileIfMinificationIsDisabled()
127
139
$ this ->resolver ->expects ($ this ->once ())
128
140
->method ('resolve ' )
129
141
->with (RulePool::TYPE_TEMPLATE_FILE , 'file.ext ' , 'frontend ' , $ theme , null , 'Magento_Module ' )
130
- ->will ( $ this -> returnValue ( $ expected) );
142
+ ->willReturn ( $ expected );
131
143
132
- $ this ->state ->expects ($ this ->never ())->method ('getMode ' );
144
+ $ this ->state ->expects ($ this ->never ())
145
+ ->method ('getMode ' );
133
146
134
147
$ actual = $ this ->object ->getFile ('frontend ' , $ theme , 'file.ext ' , 'Magento_Module ' );
135
148
$ this ->assertSame ($ expected , $ actual );
@@ -143,8 +156,10 @@ public function testGetFileIfMinificationIsDisabled()
143
156
public function getMinifiedDataProvider ()
144
157
{
145
158
return [
146
- 'default ' => [State::MODE_DEFAULT , 'getMinified ' ],
147
- 'production ' => [State::MODE_PRODUCTION , 'getPathToMinified ' ],
159
+ 'default with on demand ' => [State::MODE_DEFAULT , 1 , 'getMinified ' ],
160
+ 'default without on demand ' => [State::MODE_DEFAULT , 0 , 'getMinified ' ],
161
+ 'production with on demand ' => [State::MODE_PRODUCTION , 1 , 'getMinified ' ],
162
+ 'production without on demand ' => [State::MODE_PRODUCTION , 0 , 'getPathToMinified ' ],
148
163
];
149
164
}
150
165
}
0 commit comments