Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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';
}

Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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);
Expand Down Expand Up @@ -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'],
];
}
}