Skip to content

Commit

Permalink
Refactor to merge feature test into unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 26, 2024
1 parent 63b414a commit 9ba410a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 48 deletions.
46 changes: 0 additions & 46 deletions packages/framework/tests/Feature/AssetFacadeTest.php

This file was deleted.

44 changes: 42 additions & 2 deletions packages/framework/tests/Unit/Facades/AssetFacadeUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@

namespace Hyde\Framework\Testing\Unit\Facades;

use Hyde\Hyde;
use Hyde\Facades\Asset;
use Hyde\Testing\UnitTestCase;
use Hyde\Support\Facades\Render;
use Hyde\Support\Models\RenderData;
use Hyde\Testing\CreatesTemporaryFiles;

/**
* @covers \Hyde\Facades\Asset
*
* @see \Hyde\Framework\Testing\Feature\AssetFacadeTest
*/
class AssetFacadeUnitTest extends UnitTestCase
{
use CreatesTemporaryFiles;

protected function setUp(): void
{
self::needsKernel();
self::mockConfig();

Render::swap(new RenderData());
}

protected function tearDown(): void
{
$this->cleanUpFilesystem();
}

public function testHasMediaFileHelper()
Expand All @@ -29,4 +40,33 @@ public function testHasMediaFileHelperReturnsTrueForExistingFile()
{
$this->assertTrue(Asset::hasMediaFile('app.css'));
}

public function testMediaLinkReturnsMediaPathWithCacheKey()
{
$this->assertIsString($path = Asset::mediaLink('app.css'));
$this->assertSame('media/app.css?v='.md5_file(Hyde::path('_media/app.css')), $path);
}

public function testMediaLinkReturnsMediaPathWithoutCacheKeyIfCacheBustingIsDisabled()
{
self::mockConfig(['hyde.enable_cache_busting' => false]);

$path = Asset::mediaLink('app.css');

$this->assertIsString($path);
$this->assertSame('media/app.css', $path);
}

public function testMediaLinkSupportsCustomMediaDirectories()
{
$this->directory('_assets');
$this->file('_assets/app.css');

Hyde::setMediaDirectory('_assets');

$path = Asset::mediaLink('app.css');

$this->assertIsString($path);
$this->assertSame('assets/app.css?v='.md5_file(Hyde::path('_assets/app.css')), $path);
}
}

0 comments on commit 9ba410a

Please sign in to comment.