diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php b/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php index 792c5a0d10380..52e7137fa3ddf 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php @@ -44,6 +44,11 @@ class ConfigOptionsListConstants */ const CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION = 'static_content_on_demand_in_production'; + /** + * Paramater for forcing HTML minification even if file is already minified. + */ + const CONFIG_PATH_FORCE_HTML_MINIFICATION = 'force_html_minification'; + /**#@+ * Input keys for the options */ diff --git a/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php b/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php index de5503c144647..dff31a897e1ac 100644 --- a/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php +++ b/lib/internal/Magento/Framework/Stdlib/Cookie/PhpCookieManager.php @@ -204,14 +204,14 @@ private function checkAbilityToSendCookie($name, $value) $sizeOfCookie = $this->sizeOfCookie($name, $value); - if ($numCookies > PhpCookieManager::MAX_NUM_COOKIES) { + if ($numCookies > static::MAX_NUM_COOKIES) { $this->logger->warning( new Phrase('Unable to send the cookie. Maximum number of cookies would be exceeded.'), array_merge($_COOKIE, ['user-agent' => $this->httpHeader->getHttpUserAgent()]) ); } - if ($sizeOfCookie > PhpCookieManager::MAX_COOKIE_SIZE) { + if ($sizeOfCookie > static::MAX_COOKIE_SIZE) { throw new CookieSizeLimitReachedException( new Phrase( 'Unable to send the cookie. Size of \'%name\' is %size bytes.', diff --git a/lib/internal/Magento/Framework/Stdlib/Test/Unit/Cookie/PhpCookieManagerTest.php b/lib/internal/Magento/Framework/Stdlib/Test/Unit/Cookie/PhpCookieManagerTest.php index 75b8eb2cec8d6..1ea942f5e9013 100644 --- a/lib/internal/Magento/Framework/Stdlib/Test/Unit/Cookie/PhpCookieManagerTest.php +++ b/lib/internal/Magento/Framework/Stdlib/Test/Unit/Cookie/PhpCookieManagerTest.php @@ -47,8 +47,6 @@ class PhpCookieManagerTest extends \PHPUnit\Framework\TestCase const COOKIE_HTTP_ONLY = true; const COOKIE_NOT_HTTP_ONLY = false; const COOKIE_EXPIRE_END_OF_SESSION = 0; - const MAX_NUM_COOKIES = 50; - const MAX_COOKIE_SIZE = 4096; /** * Mapping from constant names to functions that handle the assertions. @@ -499,7 +497,9 @@ public function testSetCookieSizeTooLarge() ); $cookieValue = ''; - for ($i = 0; $i < self::MAX_COOKIE_SIZE + 1; $i++) { + + $cookieManager = $this->cookieManager; + for ($i = 0; $i < $cookieManager::MAX_COOKIE_SIZE + 1; $i++) { $cookieValue = $cookieValue . 'a'; } @@ -527,8 +527,9 @@ public function testSetTooManyCookies() $userAgent = 'some_user_agent'; - // Set self::MAX_NUM_COOKIES number of cookies in superglobal $_COOKIE. - for ($i = count($_COOKIE); $i < self::MAX_NUM_COOKIES; $i++) { + $cookieManager = $this->cookieManager; + // Set $cookieManager::MAX_NUM_COOKIES number of cookies in superglobal $_COOKIE. + for ($i = count($_COOKIE); $i < $cookieManager::MAX_NUM_COOKIES; $i++) { $_COOKIE['test_cookie_' . $i] = self::COOKIE_VALUE . '_' . $i; } diff --git a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/TemplateFile.php b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/TemplateFile.php index 09f87d878ad1c..47c0e905fc25a 100644 --- a/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/TemplateFile.php +++ b/lib/internal/Magento/Framework/View/Design/FileResolution/Fallback/TemplateFile.php @@ -12,7 +12,7 @@ use Magento\Framework\View\Template\Html\MinifierInterface; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\ObjectManager; -use Magento\Framework\Config\ConfigOptionsListConstants; +use Magento\Framework\Config\ConfigOptionsListConstants as Constants; /** * Provider of template view files @@ -107,11 +107,11 @@ public function getFile($area, ThemeInterface $themeModel, $file, $module = null */ private function getMinifiedTemplateInProduction($template) { - if ($this->deploymentConfig->getConfigData( - ConfigOptionsListConstants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION - )) { - return $this->templateMinifier->getMinified($template); - } - return $this->templateMinifier->getPathToMinified($template); + $forceMinification = $this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) + || $this->deploymentConfig->getConfigData(Constants::CONFIG_PATH_FORCE_HTML_MINIFICATION); + + return $forceMinification ? + $this->templateMinifier->getMinified($template) + : $this->templateMinifier->getPathToMinified($template); } } diff --git a/lib/internal/Magento/Framework/View/Test/Unit/Design/FileResolution/Fallback/TemplateFileTest.php b/lib/internal/Magento/Framework/View/Test/Unit/Design/FileResolution/Fallback/TemplateFileTest.php index 7e94d7e80a97f..1b87b2108f046 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/Design/FileResolution/Fallback/TemplateFileTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/Design/FileResolution/Fallback/TemplateFileTest.php @@ -92,10 +92,11 @@ public function testGetFileWhenStateDeveloper() * Cover getFile when mode is default * @param string $mode * @param integer $onDemandInProduction + * @param integer $forceMinification * @param string $method * @dataProvider getMinifiedDataProvider */ - public function testGetFileWhenModifiedNeeded($mode, $onDemandInProduction, $method) + public function testGetFileWhenModifiedNeeded($mode, $onDemandInProduction, $forceMinification, $method) { $this->assetConfig ->expects($this->once()) @@ -108,8 +109,10 @@ public function testGetFileWhenModifiedNeeded($mode, $onDemandInProduction, $met $this->deploymentConfigMock->expects($this->any()) ->method('getConfigData') - ->with(ConfigOptionsListConstants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION) - ->willReturn($onDemandInProduction); + ->willReturnMap([ + [ConfigOptionsListConstants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION, $onDemandInProduction], + [ConfigOptionsListConstants::CONFIG_PATH_FORCE_HTML_MINIFICATION, $forceMinification], + ]); $this->state->expects($this->once()) ->method('getMode') ->willReturn($mode); @@ -156,10 +159,11 @@ public function testGetFileIfMinificationIsDisabled() public function getMinifiedDataProvider() { return [ - 'default with on demand' => [State::MODE_DEFAULT, 1, 'getMinified'], - 'default without on demand' => [State::MODE_DEFAULT, 0, 'getMinified'], - 'production with on demand' => [State::MODE_PRODUCTION, 1, 'getMinified'], - 'production without on demand' => [State::MODE_PRODUCTION, 0, 'getPathToMinified'], + 'default with on demand' => [State::MODE_DEFAULT, 1, 1, 'getMinified'], + 'default without on demand' => [State::MODE_DEFAULT, 0, 0, 'getMinified'], + 'production with on demand' => [State::MODE_PRODUCTION, 1, 0, 'getMinified'], + 'production without on demand' => [State::MODE_PRODUCTION, 0, 0, 'getPathToMinified'], + 'production without on demand with minified' => [State::MODE_PRODUCTION, 0, 1, 'getMinified'], ]; } }