44
55namespace Hyde \Framework \Testing \Unit \Facades ;
66
7+ use Hyde \Hyde ;
78use Hyde \Facades \Asset ;
89use Hyde \Testing \UnitTestCase ;
10+ use Hyde \Support \Facades \Render ;
11+ use Hyde \Support \Models \RenderData ;
12+ use Hyde \Testing \CreatesTemporaryFiles ;
913
1014/**
1115 * @covers \Hyde\Facades\Asset
12- *
13- * @see \Hyde\Framework\Testing\Feature\AssetFacadeTest
1416 */
1517class AssetFacadeUnitTest extends UnitTestCase
1618{
19+ use CreatesTemporaryFiles;
20+
1721 protected function setUp (): void
1822 {
1923 self ::needsKernel ();
2024 self ::mockConfig ();
25+
26+ Render::swap (new RenderData ());
27+ }
28+
29+ protected function tearDown (): void
30+ {
31+ $ this ->cleanUpFilesystem ();
2132 }
2233
2334 public function testHasMediaFileHelper ()
@@ -29,4 +40,33 @@ public function testHasMediaFileHelperReturnsTrueForExistingFile()
2940 {
3041 $ this ->assertTrue (Asset::hasMediaFile ('app.css ' ));
3142 }
43+
44+ public function testMediaLinkReturnsMediaPathWithCacheKey ()
45+ {
46+ $ this ->assertIsString ($ path = Asset::mediaLink ('app.css ' ));
47+ $ this ->assertSame ('media/app.css?v= ' .md5_file (Hyde::path ('_media/app.css ' )), $ path );
48+ }
49+
50+ public function testMediaLinkReturnsMediaPathWithoutCacheKeyIfCacheBustingIsDisabled ()
51+ {
52+ self ::mockConfig (['hyde.enable_cache_busting ' => false ]);
53+
54+ $ path = Asset::mediaLink ('app.css ' );
55+
56+ $ this ->assertIsString ($ path );
57+ $ this ->assertSame ('media/app.css ' , $ path );
58+ }
59+
60+ public function testMediaLinkSupportsCustomMediaDirectories ()
61+ {
62+ $ this ->directory ('_assets ' );
63+ $ this ->file ('_assets/app.css ' );
64+
65+ Hyde::setMediaDirectory ('_assets ' );
66+
67+ $ path = Asset::mediaLink ('app.css ' );
68+
69+ $ this ->assertIsString ($ path );
70+ $ this ->assertSame ('assets/app.css?v= ' .md5_file (Hyde::path ('_assets/app.css ' )), $ path );
71+ }
3272}
0 commit comments