@@ -27,6 +27,7 @@ protected function setUp()
27
27
{
28
28
$ this ->objectManager = Bootstrap::getInstance ()->getObjectManager ();
29
29
$ this ->objectManager ->get ('Magento\Framework\App\State ' )->setAreaCode ('frontend ' );
30
+ Bootstrap::getInstance ()->reinitialize ();
30
31
}
31
32
32
33
/**
@@ -56,10 +57,7 @@ public function testCssMinifierLibrary()
56
57
);
57
58
}
58
59
59
- /**
60
- * @magentoConfigFixture current_store dev/css/minify_files 1
61
- */
62
- public function testCssMinification ()
60
+ protected function _testCssMinification ($ requestedUri , $ requestedFilePath , $ testFile , $ assertionCallback )
63
61
{
64
62
/** @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject $appState */
65
63
$ appState = $ this ->getMock ('\Magento\Framework\App\State ' , ['getMode ' ], [], '' , false );
@@ -69,8 +67,8 @@ public function testCssMinification()
69
67
70
68
/** @var \Magento\Framework\App\Request\Http $request */
71
69
$ 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 );
74
72
75
73
$ response = $ this ->getMockForAbstractClass (
76
74
'Magento\Framework\App\Response\FileInterface ' ,
@@ -87,13 +85,7 @@ public function testCssMinification()
87
85
'setFilePath '
88
86
)->will (
89
87
$ 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
97
89
)
98
90
);
99
91
@@ -114,16 +106,75 @@ function ($path) {
114
106
);
115
107
$ initParams = Bootstrap::getInstance ()->getAppInitParams ();
116
108
$ 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 ;
118
110
119
111
if (!is_readable (dirname ($ destFile ))) {
120
112
mkdir (dirname ($ destFile ), 777 , true );
121
113
}
122
-
123
- copy (dirname ( __DIR__ ) . ' /_files/static/css/styles.css ' , $ destFile );
114
+
115
+ copy ($ testFile , $ destFile );
124
116
125
117
$ staticResourceApp ->launch ();
126
118
127
119
unlink ($ destFile );
128
120
}
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
+ }
129
180
}
0 commit comments