Skip to content

Commit cf5ba01

Browse files
author
Roman Ganin
committed
MAGETWO-32396: Create integration test for minifier
- added static resource minification test for CSS content type
1 parent aa14f99 commit cf5ba01

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

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

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
/**
1111
* Tests for minifier
1212
*/
13-
class FileSystemTest extends \PHPUnit_Framework_TestCase
13+
class MinifierTest extends \PHPUnit_Framework_TestCase
1414
{
15+
/**
16+
* Request path for test minifier
17+
*/
18+
const REQUEST_PATH = '/frontend/Magento/blank/en_US/css/styles.css';
19+
1520
/**
1621
* @var \Magento\Framework\ObjectManagerInterface
1722
*/
@@ -50,4 +55,75 @@ public function testCssMinifierLibrary()
5055
. 'and replace old minified snapshot with new one.'
5156
);
5257
}
58+
59+
/**
60+
* @magentoConfigFixture current_store dev/css/minify_files 1
61+
*/
62+
public function testCssMinification()
63+
{
64+
/** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject $appState */
65+
$appState = $this->getMock('\Magento\Framework\App\State', ['getMode'], [], '', false);
66+
$appState->expects($this->any())
67+
->method('getMode')
68+
->will($this->returnValue(\Magento\Framework\App\State::MODE_DEFAULT));
69+
70+
/** @var \Magento\Framework\App\Request\Http $request */
71+
$request = $this->objectManager->get('Magento\Framework\App\Request\Http');
72+
$request->setRequestUri(self::REQUEST_PATH);
73+
$request->setParam('resource', self::REQUEST_PATH);
74+
75+
$response = $this->getMockForAbstractClass(
76+
'Magento\Framework\App\Response\FileInterface',
77+
[],
78+
'',
79+
false,
80+
false,
81+
true,
82+
['setFilePath']
83+
);
84+
$response->expects(
85+
$this->any()
86+
)->method(
87+
'setFilePath'
88+
)->will(
89+
$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+
}
97+
)
98+
);
99+
100+
$publisher = $this->objectManager->create(
101+
'Magento\Framework\App\View\Asset\Publisher',
102+
[
103+
'appState' => $appState
104+
]
105+
);
106+
107+
/** @var \Magento\Framework\App\StaticResource $staticResourceApp */
108+
$staticResourceApp = $this->objectManager->create(
109+
'Magento\Framework\App\StaticResource',
110+
[
111+
'response' => $response,
112+
'publisher' => $publisher
113+
]
114+
);
115+
$initParams = Bootstrap::getInstance()->getAppInitParams();
116+
$designPath = $initParams[\Magento\Framework\App\Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS]['design']['path'];
117+
$destFile = $designPath . '/frontend/Magento/blank/web/css/styles.css';
118+
119+
if (!is_readable(dirname($destFile))) {
120+
mkdir(dirname($destFile), 777, true);
121+
}
122+
123+
copy(dirname(__DIR__) . '/_files/static/css/styles.css', $destFile);
124+
125+
$staticResourceApp->launch();
126+
127+
unlink($destFile);
128+
}
53129
}

0 commit comments

Comments
 (0)