Skip to content

Commit 50463f5

Browse files
committed
MAGETWO-44603: Styles are lost on Storefront if CSS files minification is enabled in "default" mode
- Fixed test - Create new integration test
1 parent c24bf97 commit 50463f5

File tree

5 files changed

+159
-6
lines changed

5 files changed

+159
-6
lines changed

app/code/Magento/Deploy/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"require": {
55
"php": "~5.5.0|~5.6.0|~7.0.0",
66
"magento/framework": "1.0.0-beta",
7-
"magento/module-developer": "1.0.0-beta",
87
"magento/module-store": "1.0.0-beta",
98
"magento/module-theme": "1.0.0-beta",
109
"magento/module-require-js": "1.0.0-beta"

app/code/Magento/Deploy/etc/module.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<module name="Magento_Deploy" setup_version="2.0.0">
1010
<sequence>
1111
<module name="Magento_Store"/>
12-
<module name="Magento_Developer"/>
1312
</sequence>
1413
</module>
1514
</config>

app/code/Magento/Email/Model/Template/Filter.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Email\Model\Template;
77

8+
use Magento\Framework\View\Asset\ContentProcessorException;
89
use Magento\Framework\View\Asset\ContentProcessorInterface;
910

1011
/**
@@ -885,10 +886,15 @@ public function getCssFilesContent(array $files)
885886
);
886887
}
887888
$css = '';
888-
foreach ($files as $file) {
889-
$asset = $this->_assetRepo->createAsset($file, $designParams);
890-
$css .= $asset->getContent();
889+
try {
890+
foreach ($files as $file) {
891+
$asset = $this->_assetRepo->createAsset($file, $designParams);
892+
$css .= $asset->getContent();
893+
}
894+
} catch (ContentProcessorException $exception) {
895+
$css = $exception->getMessage();
891896
}
897+
892898
return $css;
893899
}
894900

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Developer\Console\Command;
7+
8+
use Magento\Framework\Validator\Locale;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Output\OutputInterface;
12+
13+
/**
14+
* Class SourceThemeDeployCommandTest
15+
*
16+
* @see \Magento\Developer\Console\Command\SourceThemeDeployCommand
17+
*/
18+
class SourceThemeDeployCommandTest extends \PHPUnit_Framework_TestCase
19+
{
20+
const PUB_STATIC_DIRECTORY = 'pub_static';
21+
22+
const AREA_TEST_VALUE = 'frontend';
23+
24+
const LOCALE_TEST_VALUE = 'en_US';
25+
26+
const THEME_TEST_VALUE = 'Magento/luma';
27+
28+
const TYPE_TEST_VALUE = 'less';
29+
30+
/**
31+
* @var Locale|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $validatorMock;
34+
35+
/**
36+
* @var SourceThemeDeployCommand
37+
*/
38+
private $command;
39+
40+
/**
41+
* @var string
42+
*/
43+
private $pubStatic;
44+
45+
/**
46+
* @var array
47+
*/
48+
private $compiledFiles = ['css/styles-m', 'css/styles-l'];
49+
50+
/**
51+
* Set up
52+
*/
53+
protected function setUp()
54+
{
55+
global $installDir;
56+
57+
$this->validatorMock = $this->getMockBuilder(Locale::class)
58+
->disableOriginalConstructor()
59+
->getMock();
60+
61+
$this->pubStatic = $installDir . DIRECTORY_SEPARATOR . self::PUB_STATIC_DIRECTORY;
62+
$this->command = Bootstrap::getObjectManager()->get(SourceThemeDeployCommand::class);
63+
}
64+
65+
/**
66+
* Run test for execute method
67+
*/
68+
public function testExecute()
69+
{
70+
$error = [];
71+
72+
/** @var OutputInterface|\PHPUnit_Framework_MockObject_MockObject $outputMock */
73+
$outputMock = $this->getMockBuilder(OutputInterface::class)
74+
->getMockForAbstractClass();
75+
76+
$this->clearStaticDirectory();
77+
78+
$this->command->run($this->getInputMock(), $outputMock);
79+
80+
/** @var \SplFileInfo $file */
81+
foreach ($this->collectFiles($this->pubStatic) as $file) {
82+
$fileInfo = pathinfo($file->getFilename());
83+
if (!in_array('css/' . $fileInfo['filename'], $this->compiledFiles, true)
84+
&& !$file->isLink()
85+
) {
86+
$error[] = 'Bad file -> ' . $file->getFilename() . PHP_EOL;
87+
}
88+
}
89+
90+
$this->clearStaticDirectory();
91+
92+
self::assertEmpty($error, implode($error));
93+
}
94+
95+
/**
96+
* @return void
97+
*/
98+
private function clearStaticDirectory()
99+
{
100+
/** @var \SplFileInfo $file */
101+
foreach ($this->collectFiles($this->pubStatic) as $file) {
102+
@unlink($file->getPathname());
103+
}
104+
}
105+
106+
/**
107+
* @param string $path
108+
* @return \RegexIterator
109+
*/
110+
private function collectFiles($path)
111+
{
112+
$flags = \FilesystemIterator::CURRENT_AS_FILEINFO
113+
| \FilesystemIterator::SKIP_DOTS;
114+
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, $flags));
115+
116+
return new \RegexIterator(
117+
$iterator,
118+
'#\.less$#',
119+
\RegexIterator::MATCH,
120+
\RegexIterator::USE_KEY
121+
);
122+
}
123+
124+
/**
125+
* @return InputInterface|\PHPUnit_Framework_MockObject_MockObject
126+
*/
127+
private function getInputMock()
128+
{
129+
$inputMock = $this->getMockBuilder(InputInterface::class)
130+
->getMockForAbstractClass();
131+
132+
$inputMock->expects(self::exactly(4))
133+
->method('getOption')
134+
->willReturnMap(
135+
[
136+
['area', self::AREA_TEST_VALUE],
137+
['locale', self::LOCALE_TEST_VALUE],
138+
['theme', self::THEME_TEST_VALUE],
139+
['type', self::TYPE_TEST_VALUE]
140+
]
141+
);
142+
$inputMock->expects(self::once())
143+
->method('getArgument')
144+
->with('file')
145+
->willReturn($this->compiledFiles);
146+
147+
return $inputMock;
148+
}
149+
}

lib/internal/Magento/Framework/Css/PreProcessor/Adapter/Less/Processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Framework\Css\PreProcessor\Adapter\Less;
77

8-
use Magento\Setup\Module\I18n\Dictionary\Phrase;
8+
use Magento\Framework\Phrase;
99
use Psr\Log\LoggerInterface;
1010
use Magento\Framework\App\State;
1111
use Magento\Framework\View\Asset\File;

0 commit comments

Comments
 (0)