Skip to content

Commit efa91af

Browse files
author
Oleksandr Iegorov
committed
MC-29033: admin catalog can't load css in the cloud
1 parent c287fd8 commit efa91af

File tree

5 files changed

+106
-87
lines changed

5 files changed

+106
-87
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare (strict_types=1);
7+
8+
namespace Magento\Framework\View\Asset\PreProcessor;
9+
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\State;
12+
use Magento\Framework\View\Asset\Minification;
13+
14+
/**
15+
* Minification configuration provider
16+
*/
17+
class MinificationConfigProvider
18+
{
19+
/**
20+
* @var Minification
21+
*/
22+
private $minification;
23+
24+
/**
25+
* @var State
26+
*/
27+
private $appState;
28+
29+
/**
30+
* @var ScopeConfigInterface
31+
*/
32+
private $scopeConfig;
33+
34+
/**
35+
* @param Minification $minification
36+
* @param ScopeConfigInterface $scopeConfig
37+
* @param State $appState
38+
*/
39+
public function __construct(
40+
Minification $minification,
41+
ScopeConfigInterface $scopeConfig,
42+
State $appState
43+
) {
44+
$this->minification = $minification;
45+
$this->scopeConfig = $scopeConfig;
46+
$this->appState = $appState;
47+
}
48+
49+
/**
50+
* Check whether asset minification is on
51+
*
52+
* @param string $filename
53+
* @return bool
54+
*/
55+
public function isMinificationEnabled(string $filename): bool
56+
{
57+
$extension = pathinfo($filename, PATHINFO_EXTENSION);
58+
$result = $this->minification->isEnabled($extension);
59+
$pathParts = explode('/', $filename);
60+
if (!empty($pathParts) && isset($pathParts[0])) {
61+
$area = $pathParts[0];
62+
if ($area === 'adminhtml') {
63+
$result = $this->appState->getMode() != State::MODE_DEVELOPER &&
64+
$this->scopeConfig->isSetFlag(
65+
sprintf(Minification::XML_PATH_MINIFICATION_ENABLED, $extension),
66+
'default'
67+
);
68+
}
69+
}
70+
return $result;
71+
}
72+
}

lib/internal/Magento/Framework/View/Asset/PreProcessor/MinificationFilenameResolver.php

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
namespace Magento\Framework\View\Asset\PreProcessor;
77

88
use Magento\Framework\View\Asset\Minification;
9-
use Magento\Framework\App\Config\ScopeConfigInterface;
10-
use Magento\Framework\App\State;
119

1210
/**
1311
* Class MinificationFilenameResolver
@@ -25,30 +23,22 @@ class MinificationFilenameResolver implements FilenameResolverInterface
2523
private $minification;
2624

2725
/**
28-
* @var State
26+
* @var MinificationConfigProvider
2927
*/
30-
private $appState;
31-
32-
/**
33-
* @var ScopeConfigInterface
34-
*/
35-
private $scopeConfig;
28+
private $minificationConfig;
3629

3730
/**
3831
* Constructor
3932
*
4033
* @param Minification $minification
41-
* @param ScopeConfigInterface $scopeConfig
42-
* @param State $appState
34+
* @param MinificationConfigProvider $minificationConfig
4335
*/
4436
public function __construct(
4537
Minification $minification,
46-
ScopeConfigInterface $scopeConfig,
47-
State $appState
38+
MinificationConfigProvider $minificationConfig
4839
) {
4940
$this->minification = $minification;
50-
$this->scopeConfig = $scopeConfig;
51-
$this->appState = $appState;
41+
$this->minificationConfig = $minificationConfig;
5242
}
5343

5444
/**
@@ -60,34 +50,10 @@ public function __construct(
6050
public function resolve($path)
6151
{
6252
$result = $path;
63-
if ($this->isEnabledForArea($path)) {
53+
if ($this->minificationConfig->isMinificationEnabled($path)) {
6454
$result = str_replace(self::FILE_PART, '.', $path);
6555
}
6656

6757
return $result;
6858
}
69-
70-
/**
71-
* Check whether asset minification is on for specified content type and for area
72-
*
73-
* @param string $filename
74-
* @return bool
75-
*/
76-
private function isEnabledForArea(string $filename): bool
77-
{
78-
$extension = pathinfo($filename, PATHINFO_EXTENSION);
79-
$result = $this->minification->isEnabled($extension);
80-
$pathParts = explode('/', $filename);
81-
if (!empty($pathParts) && isset($pathParts[0])) {
82-
$area = $pathParts[0];
83-
if ($area === 'adminhtml') {
84-
$result = $this->appState->getMode() != State::MODE_DEVELOPER &&
85-
$this->scopeConfig->isSetFlag(
86-
sprintf(Minification::XML_PATH_MINIFICATION_ENABLED, $extension),
87-
'default'
88-
);
89-
}
90-
}
91-
return $result;
92-
}
9359
}

lib/internal/Magento/Framework/View/Asset/PreProcessor/Minify.php

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use Magento\Framework\View\Asset\Minification;
1010
use Magento\Framework\View\Asset\PreProcessor;
1111
use Magento\Framework\View\Asset\PreProcessorInterface;
12-
use Magento\Framework\App\Config\ScopeConfigInterface;
13-
use Magento\Framework\App\State;
1412

1513
/**
1614
* Assets minification pre-processor
@@ -28,29 +26,23 @@ class Minify implements PreProcessorInterface
2826
protected $minification;
2927

3028
/**
31-
* @var State
29+
* @var MinificationConfigProvider
3230
*/
33-
private $appState;
34-
35-
/**
36-
* @var ScopeConfigInterface
37-
*/
38-
private $scopeConfig;
31+
private $minificationConfig;
3932

4033
/**
4134
* @param AdapterInterface $adapter
4235
* @param Minification $minification
36+
* @param MinificationConfigProvider $minificationConfig
4337
*/
4438
public function __construct(
4539
AdapterInterface $adapter,
4640
Minification $minification,
47-
ScopeConfigInterface $scopeConfig,
48-
State $appState
41+
MinificationConfigProvider $minificationConfig
4942
) {
5043
$this->adapter = $adapter;
5144
$this->minification = $minification;
52-
$this->scopeConfig = $scopeConfig;
53-
$this->appState = $appState;
45+
$this->minificationConfig = $minificationConfig;
5446
}
5547

5648
/**
@@ -61,36 +53,12 @@ public function __construct(
6153
*/
6254
public function process(PreProcessor\Chain $chain)
6355
{
64-
if ($this->isEnabledForArea($chain->getTargetAssetPath()) &&
56+
if ($this->minificationConfig->isMinificationEnabled($chain->getTargetAssetPath()) &&
6557
$this->minification->isMinifiedFilename($chain->getTargetAssetPath()) &&
6658
!$this->minification->isMinifiedFilename($chain->getOrigAssetPath())
6759
) {
6860
$content = $this->adapter->minify($chain->getContent());
6961
$chain->setContent($content);
7062
}
7163
}
72-
73-
/**
74-
* Check whether asset minification is on for specified content type and for area
75-
*
76-
* @param string $filename
77-
* @return bool
78-
*/
79-
private function isEnabledForArea(string $filename): bool
80-
{
81-
$extension = pathinfo($filename, PATHINFO_EXTENSION);
82-
$result = $this->minification->isEnabled($extension);
83-
$pathParts = explode('/', $filename);
84-
if (!empty($pathParts) && isset($pathParts[0])) {
85-
$area = $pathParts[0];
86-
if ($area === 'adminhtml') {
87-
$result = $this->appState->getMode() != State::MODE_DEVELOPER &&
88-
$this->scopeConfig->isSetFlag(
89-
sprintf(Minification::XML_PATH_MINIFICATION_ENABLED, $extension),
90-
'default'
91-
);
92-
}
93-
}
94-
return $result;
95-
}
9664
}

lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/MinificationFilenameResolverTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Framework\View\Asset\Minification;
99
use Magento\Framework\View\Asset\PreProcessor\MinificationFilenameResolver;
10+
use Magento\Framework\View\Asset\PreProcessor\MinificationConfigProvider;
1011

1112
/**
1213
* Class MinificationFilenameResolverTest
@@ -29,13 +30,15 @@ public function testResolve($isMin, $input, $expected)
2930
$minificationMock = $this->getMockBuilder(Minification::class)
3031
->disableOriginalConstructor()
3132
->getMock();
32-
33-
$minificationMock->expects(self::once())
34-
->method('isEnabled')
35-
->with('ext')
33+
$minificationConfigMock = $this->getMockBuilder(MinificationConfigProvider::class)
34+
->disableOriginalConstructor()
35+
->getMock();
36+
$minificationConfigMock->expects(self::once())
37+
->method('isMinificationEnabled')
38+
->with($input)
3639
->willReturn($isMin);
3740

38-
$resolver = new MinificationFilenameResolver($minificationMock);
41+
$resolver = new MinificationFilenameResolver($minificationMock, $minificationConfigMock);
3942

4043
self::assertEquals($expected, $resolver->resolve($input));
4144
}

lib/internal/Magento/Framework/View/Test/Unit/Asset/PreProcessor/MinifyTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Framework\View\Test\Unit\Asset\PreProcessor;
88

99
use Magento\Framework\View\Asset\PreProcessor\Minify;
10+
use Magento\Framework\View\Asset\PreProcessor\MinificationConfigProvider;
1011

1112
/**
1213
* Unit test for Magento\Framework\View\Asset\PreProcessor\Minify
@@ -28,6 +29,11 @@ class MinifyTest extends \PHPUnit\Framework\TestCase
2829
*/
2930
protected $minificationMock;
3031

32+
/**
33+
* @var MinificationConfigProvider|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $minificationConfigMock;
36+
3137
/**
3238
* {@inheritDoc}
3339
*/
@@ -40,10 +46,14 @@ protected function setUp()
4046
$this->minificationMock = $this->getMockBuilder(\Magento\Framework\View\Asset\Minification::class)
4147
->disableOriginalConstructor()
4248
->getMock();
49+
$this->minificationConfigMock = $this->getMockBuilder(MinificationConfigProvider::class)
50+
->disableOriginalConstructor()
51+
->getMock();
4352

4453
$this->minify = new Minify(
4554
$this->adapterMock,
46-
$this->minificationMock
55+
$this->minificationMock,
56+
$this->minificationConfigMock
4757
);
4858
}
4959

@@ -84,10 +94,10 @@ public function testProcess($targetPath, $originalPath, $minifyCalls, $setConten
8494
->with('original content')
8595
->willReturn('minified content');
8696

87-
$this->minificationMock
97+
$this->minificationConfigMock
8898
->expects($this->any())
89-
->method('isEnabled')
90-
->willReturnMap([['css', $isEnabled]]);
99+
->method('isMinificationEnabled')
100+
->willReturnMap([[$targetPath, $isEnabled]]);
91101

92102
$this->minificationMock
93103
->expects($this->any())

0 commit comments

Comments
 (0)