@@ -65,22 +65,175 @@ public function testUnversionedElixir()
65
65
66
66
public function testMixDoesNotIncludeHost ()
67
67
{
68
- $ file = 'unversioned.css ' ;
68
+ $ manifest = $ this ->makeManifest ();
69
+
70
+ $ result = mix ('/unversioned.css ' );
71
+
72
+ $ this ->assertSame ('/versioned.css ' , $ result ->toHtml ());
73
+
74
+ unlink ($ manifest );
75
+ }
76
+
77
+ public function testMixCachesManifestForSubsequentCalls ()
78
+ {
79
+ $ manifest = $ this ->makeManifest ();
80
+ mix ('unversioned.css ' );
81
+ unlink ($ manifest );
82
+
83
+ $ result = mix ('/unversioned.css ' );
84
+
85
+ $ this ->assertSame ('/versioned.css ' , $ result ->toHtml ());
86
+ }
87
+
88
+ public function testMixAssetMissingStartingSlashHaveItAdded ()
89
+ {
90
+ $ manifest = $ this ->makeManifest ();
91
+
92
+ $ result = mix ('unversioned.css ' );
93
+
94
+ $ this ->assertSame ('/versioned.css ' , $ result ->toHtml ());
95
+
96
+ unlink ($ manifest );
97
+ }
98
+
99
+ /**
100
+ * @expectedException \Exception
101
+ * @expectedExceptionMessage The Mix manifest does not exist.
102
+ */
103
+ public function testMixMissingManifestThrowsException ()
104
+ {
105
+ mix ('unversioned.css ' , 'missing ' );
106
+ }
107
+
108
+ public function testMixWithManifestDirectory ()
109
+ {
110
+ mkdir ($ directory = __DIR__ .'/mix ' );
111
+ $ manifest = $ this ->makeManifest ('mix ' );
112
+
113
+ $ result = mix ('unversioned.css ' , 'mix ' );
114
+
115
+ $ this ->assertSame ('/mix/versioned.css ' , $ result ->toHtml ());
116
+
117
+ unlink ($ manifest );
118
+ rmdir ($ directory );
119
+ }
120
+
121
+ public function testMixManifestDirectoryMissingStartingSlashHasItAdded ()
122
+ {
123
+ mkdir ($ directory = __DIR__ .'/mix ' );
124
+ $ manifest = $ this ->makeManifest ('/mix ' );
125
+
126
+ $ result = mix ('unversioned.css ' , 'mix ' );
127
+
128
+ $ this ->assertSame ('/mix/versioned.css ' , $ result ->toHtml ());
129
+
130
+ unlink ($ manifest );
131
+ rmdir ($ directory );
132
+ }
133
+
134
+ public function testMixHotModuleReloadingGetsUrlFromFileWithHttps ()
135
+ {
136
+ $ path = $ this ->makeHotModuleReloadFile ('https://laravel.com/docs ' );
137
+
138
+ $ result = mix ('unversioned.css ' );
139
+
140
+ $ this ->assertSame ('//laravel.com/docs/unversioned.css ' , $ result ->toHtml ());
141
+
142
+ unlink ($ path );
143
+ }
69
144
145
+ public function testMixHotModuleReloadingGetsUrlFromFileWithHttp ()
146
+ {
147
+ $ path = $ this ->makeHotModuleReloadFile ('http://laravel.com/docs ' );
148
+
149
+ $ result = mix ('unversioned.css ' );
150
+
151
+ $ this ->assertSame ('//laravel.com/docs/unversioned.css ' , $ result ->toHtml ());
152
+
153
+ unlink ($ path );
154
+ }
155
+
156
+ public function testMixHotModuleReloadingGetsUrlFromFileWithManifestDirectoryAndHttps ()
157
+ {
158
+ mkdir ($ directory = __DIR__ .'/mix ' );
159
+ $ path = $ this ->makeHotModuleReloadFile ('https://laravel.com/docs ' , 'mix ' );
160
+
161
+ $ result = mix ('unversioned.css ' , 'mix ' );
162
+
163
+ $ this ->assertSame ('//laravel.com/docs/unversioned.css ' , $ result ->toHtml ());
164
+
165
+ unlink ($ path );
166
+ rmdir ($ directory );
167
+ }
168
+
169
+ public function testMixHotModuleReloadingGetsUrlFromFileWithManifestDirectoryAndHttp ()
170
+ {
171
+ mkdir ($ directory = __DIR__ .'/mix ' );
172
+ $ path = $ this ->makeHotModuleReloadFile ('http://laravel.com/docs ' , 'mix ' );
173
+
174
+ $ result = mix ('unversioned.css ' , 'mix ' );
175
+
176
+ $ this ->assertSame ('//laravel.com/docs/unversioned.css ' , $ result ->toHtml ());
177
+
178
+ unlink ($ path );
179
+ rmdir ($ directory );
180
+ }
181
+
182
+ public function testMixHotModuleReloadingUsesLocalhostIfNoHttpScheme ()
183
+ {
184
+ $ path = $ this ->makeHotModuleReloadFile ('' );
185
+
186
+ $ result = mix ('unversioned.css ' );
187
+
188
+ $ this ->assertSame ('//localhost:8080/unversioned.css ' , $ result ->toHtml ());
189
+
190
+ unlink ($ path );
191
+ }
192
+
193
+ public function testMixHotModuleReloadingWithManifestDirectoryUsesLocalhostIfNoHttpScheme ()
194
+ {
195
+ mkdir ($ directory = __DIR__ .'/mix ' );
196
+ $ path = $ this ->makeHotModuleReloadFile ('' , 'mix ' );
197
+
198
+ $ result = mix ('unversioned.css ' , 'mix ' );
199
+
200
+ $ this ->assertSame ('//localhost:8080/unversioned.css ' , $ result ->toHtml ());
201
+
202
+ unlink ($ path );
203
+ rmdir ($ directory );
204
+ }
205
+
206
+ protected function makeHotModuleReloadFile ($ url , $ directory = '' )
207
+ {
208
+ app ()->singleton ('path.public ' , function () {
209
+ return __DIR__ ;
210
+ });
211
+
212
+ $ path = public_path (str_finish ($ directory , '/ ' ).'hot ' );
213
+
214
+ // Laravel mix when run 'hot' has a new line after the
215
+ // url, so for consistency this "\n" is added.
216
+ file_put_contents ($ path , "{$ url }\n" );
217
+
218
+ return $ path ;
219
+ }
220
+
221
+ protected function makeManifest ($ directory = '' )
222
+ {
70
223
app ()->singleton ('path.public ' , function () {
71
224
return __DIR__ ;
72
225
});
73
226
74
- touch ( public_path (' mix-manifest.json ') );
227
+ $ path = public_path (str_finish ( $ directory , ' / ' ). ' mix-manifest.json ' );
75
228
76
- file_put_contents (public_path ('mix-manifest.json ' ), json_encode ([
77
- '/unversioned.css ' => '/versioned.css ' ,
78
- ]));
229
+ touch ($ path );
79
230
80
- $ result = mix ($ file );
231
+ // Laravel mix prints JSON pretty and with escaped
232
+ // slashes, so we are doing that here for consistency.
233
+ $ content = json_encode (['/unversioned.css ' => '/versioned.css ' ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
81
234
82
- $ this -> assertEquals ( ' /versioned.css ' , $ result );
235
+ file_put_contents ( $ path , $ content );
83
236
84
- unlink ( public_path ( ' mix-manifest.json ' )) ;
237
+ return $ path ;
85
238
}
86
239
}
0 commit comments