Skip to content

Commit 43f4455

Browse files
author
Roman Ganin
committed
MAGETWO-32396: Create integration test for minifier
- added static resource minification test for minfied files and for minification turned off
1 parent cf5ba01 commit 43f4455

File tree

2 files changed

+76
-16
lines changed

2 files changed

+76
-16
lines changed

dev/tests/integration/testsuite/Magento/Framework/View/Asset/MinifierTest.php

Lines changed: 67 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ protected function setUp()
2727
{
2828
$this->objectManager = Bootstrap::getInstance()->getObjectManager();
2929
$this->objectManager->get('Magento\Framework\App\State')->setAreaCode('frontend');
30+
Bootstrap::getInstance()->reinitialize();
3031
}
3132

3233
/**
@@ -56,10 +57,7 @@ public function testCssMinifierLibrary()
5657
);
5758
}
5859

59-
/**
60-
* @magentoConfigFixture current_store dev/css/minify_files 1
61-
*/
62-
public function testCssMinification()
60+
protected function _testCssMinification($requestedUri, $requestedFilePath, $testFile, $assertionCallback)
6361
{
6462
/** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject $appState */
6563
$appState = $this->getMock('\Magento\Framework\App\State', ['getMode'], [], '', false);
@@ -69,8 +67,8 @@ public function testCssMinification()
6967

7068
/** @var \Magento\Framework\App\Request\Http $request */
7169
$request = $this->objectManager->get('Magento\Framework\App\Request\Http');
72-
$request->setRequestUri(self::REQUEST_PATH);
73-
$request->setParam('resource', self::REQUEST_PATH);
70+
$request->setRequestUri($requestedUri);
71+
$request->setParam('resource', $requestedUri);
7472

7573
$response = $this->getMockForAbstractClass(
7674
'Magento\Framework\App\Response\FileInterface',
@@ -87,13 +85,7 @@ public function testCssMinification()
8785
'setFilePath'
8886
)->will(
8987
$this->returnCallback(
90-
function ($path) {
91-
$this->assertEquals(
92-
file_get_contents(dirname(__DIR__) . '/_files/static/css/styles.magento.min.css'),
93-
file_get_contents($path),
94-
'Minified files are not equal or minification did not work for requested CSS'
95-
);
96-
}
88+
$assertionCallback
9789
)
9890
);
9991

@@ -114,16 +106,75 @@ function ($path) {
114106
);
115107
$initParams = Bootstrap::getInstance()->getAppInitParams();
116108
$designPath = $initParams[\Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]['design']['path'];
117-
$destFile = $designPath . '/frontend/Magento/blank/web/css/styles.css';
109+
$destFile = $designPath . $requestedFilePath;
118110

119111
if (!is_readable(dirname($destFile))) {
120112
mkdir(dirname($destFile), 777, true);
121113
}
122-
123-
copy(dirname(__DIR__) . '/_files/static/css/styles.css', $destFile);
114+
115+
copy($testFile, $destFile);
124116

125117
$staticResourceApp->launch();
126118

127119
unlink($destFile);
128120
}
121+
122+
/**
123+
* @magentoConfigFixture current_store dev/css/minify_files 1
124+
*/
125+
public function testCssMinification()
126+
{
127+
$this->_testCssMinification(
128+
self::REQUEST_PATH,
129+
'/frontend/Magento/blank/web/css/styles.css',
130+
dirname(__DIR__) . '/_files/static/css/styles.css',
131+
function ($path) {
132+
$this->assertEquals(
133+
file_get_contents(dirname(__DIR__) . '/_files/static/css/styles.magento.min.css'),
134+
file_get_contents($path),
135+
'Minified files are not equal or minification did not work for requested CSS'
136+
);
137+
}
138+
);
139+
}
140+
141+
/**
142+
* @magentoConfigFixture current_store dev/css/minify_files 0
143+
*/
144+
public function testCssMinificationOff()
145+
{
146+
$this->_testCssMinification(
147+
self::REQUEST_PATH,
148+
'/frontend/Magento/blank/web/css/styles.css',
149+
dirname(__DIR__) . '/_files/static/css/styles.css',
150+
function ($path) {
151+
$content = file_get_contents($path);
152+
$this->assertNotEmpty($content);
153+
$this->assertContains('Magento/backend', $content);
154+
$this->assertNotEquals(
155+
file_get_contents(dirname(__DIR__) . '/_files/static/css/styles.magento.min.css'),
156+
$content,
157+
'CSS is minified when minification turned off'
158+
);
159+
}
160+
);
161+
}
162+
163+
/**
164+
* @magentoConfigFixture current_store dev/css/minify_files 1
165+
*/
166+
public function testCssMinificationForMinifiedFiles()
167+
{
168+
$this->_testCssMinification(
169+
'/frontend/Magento/blank/en_US/css/styles.min.css',
170+
'/frontend/Magento/blank/web/css/styles.min.css',
171+
dirname(__DIR__) . '/_files/static/css/styles.min.css',
172+
function ($path) {
173+
$content = file_get_contents($path);
174+
$this->assertNotEmpty($content);
175+
$this->assertContains('Magento/backend', $content);
176+
$this->assertContains('semi-minified file', $content);
177+
}
178+
);
179+
}
129180
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
/*
6+
* Magento/backend
7+
* semi-minified file to check that .min.css files are not minified with library
8+
*/
9+
table > caption { margin-bottom: 5px;}table thead { background: #676056; color: #f7f3eb;}table thead .headings { background: #807a6e;}

0 commit comments

Comments
 (0)