Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit b032bbc

Browse files
author
Yevhen Miroshnychenko
authored
Merge pull request #2225 from magento-thunder/MAGETWO-89229
Fixed issues: - MAGETWO-89229: Add ability to force HTML minification in production mode
2 parents c33674d + e0118a0 commit b032bbc

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class ConfigOptionsListConstants
4444
*/
4545
const CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION = 'static_content_on_demand_in_production';
4646

47+
/**
48+
* Paramater for forcing HTML minification even if file is already minified.
49+
*/
50+
const CONFIG_PATH_FORCE_HTML_MINIFICATION = 'force_html_minification';
51+
4752
/**#@+
4853
* Input keys for the options
4954
*/

lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/TemplateFile.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Magento\Framework\View\Template\Html\MinifierInterface;
1313
use Magento\Framework\App\DeploymentConfig;
1414
use Magento\Framework\App\ObjectManager;
15-
use Magento\Framework\Config\ConfigOptionsListConstants;
15+
use Magento\Framework\Config\ConfigOptionsListConstants as Constants;
1616

1717
/**
1818
* Provider of template view files
@@ -107,11 +107,11 @@ public function getFile($area, ThemeInterface $themeModel, $file, $module = null
107107
*/
108108
private function getMinifiedTemplateInProduction($template)
109109
{
110-
if ($this->deploymentConfig->getConfigData(
111-
ConfigOptionsListConstants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION
112-
)) {
113-
return $this->templateMinifier->getMinified($template);
114-
}
115-
return $this->templateMinifier->getPathToMinified($template);
110+
$forceMinification = $this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)
111+
|| $this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_FORCE_HTML_MINIFICATION);
112+
113+
return $forceMinification ?
114+
$this->templateMinifier->getMinified($template)
115+
: $this->templateMinifier->getPathToMinified($template);
116116
}
117117
}

lib/internal/Magento/Framework/View/Test/Unit/Design/FileResolution/Fallback/TemplateFileTest.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ public function testGetFileWhenStateDeveloper()
9292
* Cover getFile when mode is default
9393
* @param string $mode
9494
* @param integer $onDemandInProduction
95+
* @param integer $forceMinification
9596
* @param string $method
9697
* @dataProvider getMinifiedDataProvider
9798
*/
98-
public function testGetFileWhenModifiedNeeded($mode, $onDemandInProduction, $method)
99+
public function testGetFileWhenModifiedNeeded($mode, $onDemandInProduction, $forceMinification, $method)
99100
{
100101
$this->assetConfig
101102
->expects($this->once())
@@ -108,8 +109,10 @@ public function testGetFileWhenModifiedNeeded($mode, $onDemandInProduction, $met
108109

109110
$this->deploymentConfigMock->expects($this->any())
110111
->method('getConfigData')
111-
->with(ConfigOptionsListConstants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION)
112-
->willReturn($onDemandInProduction);
112+
->willReturnMap([
113+
[ConfigOptionsListConstants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION, $onDemandInProduction],
114+
[ConfigOptionsListConstants::CONFIG_PATH_FORCE_HTML_MINIFICATION, $forceMinification],
115+
]);
113116
$this->state->expects($this->once())
114117
->method('getMode')
115118
->willReturn($mode);
@@ -156,10 +159,11 @@ public function testGetFileIfMinificationIsDisabled()
156159
public function getMinifiedDataProvider()
157160
{
158161
return [
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'],
162+
'default with on demand' => [State::MODE_DEFAULT, 1, 1, 'getMinified'],
163+
'default without on demand' => [State::MODE_DEFAULT, 0, 0, 'getMinified'],
164+
'production with on demand' => [State::MODE_PRODUCTION, 1, 0, 'getMinified'],
165+
'production without on demand' => [State::MODE_PRODUCTION, 0, 0, 'getPathToMinified'],
166+
'production without on demand with minified' => [State::MODE_PRODUCTION, 0, 1, 'getMinified'],
163167
];
164168
}
165169
}

0 commit comments

Comments
 (0)