|
10 | 10 | /**
|
11 | 11 | * Tests for minifier
|
12 | 12 | */
|
13 |
| -class FileSystemTest extends \PHPUnit_Framework_TestCase |
| 13 | +class MinifierTest extends \PHPUnit_Framework_TestCase |
14 | 14 | {
|
| 15 | + /** |
| 16 | + * Request path for test minifier |
| 17 | + */ |
| 18 | + const REQUEST_PATH = '/frontend/Magento/blank/en_US/css/styles.css'; |
| 19 | + |
15 | 20 | /**
|
16 | 21 | * @var \Magento\Framework\ObjectManagerInterface
|
17 | 22 | */
|
@@ -50,4 +55,75 @@ public function testCssMinifierLibrary()
|
50 | 55 | . 'and replace old minified snapshot with new one.'
|
51 | 56 | );
|
52 | 57 | }
|
| 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 | + } |
53 | 129 | }
|
0 commit comments