Skip to content

Commit

Permalink
False by default for asset file for styles
Browse files Browse the repository at this point in the history
  • Loading branch information
dpanta94 committed Dec 17, 2024
1 parent b0432d1 commit fdcb23b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ class Asset {
/**
* Whether or not to attempt to load an .asset.php file.
*
* By default is true for scripts and false for styles.
*
* @since 1.3.1
*
* @var bool
Expand Down Expand Up @@ -1173,12 +1175,14 @@ public function in_header() {
* Set the asset type.
*
* @since 1.0.0
* @since TBD - For css files, we dont want to use asset file for dependencies by default.
*/
protected function infer_type() {
if ( substr( $this->file, -3, 3 ) === '.js' ) {
$this->type = 'js';
} elseif ( substr( $this->file, -4, 4 ) === '.css' ) {
$this->type = 'css';
$this->use_asset_file( false );
}
}

Expand Down
33 changes: 25 additions & 8 deletions tests/wpunit/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,28 +637,36 @@ public function should_allow_setting_dependencies_with_a_callable(): void {
/**
* @test
*/
public function it_should_use_include_css_asset_file_dependencies_when_no_dependencies_are_set(): void {
public function it_should_not_use_include_css_asset_file_dependencies_when_no_dependencies_are_set(): void {
$asset = Asset::add( 'my-style' . uniqid(), 'fake4.css' );

$this->assertContains( 'some-dependency', $asset->get_dependencies() );
$this->assertEmpty( $asset->get_dependencies() );
}

/**
* @test
*/
public function it_should_use_include_css_asset_file_dependencies_when_no_dependencies_are_set(): void {
$asset = Asset::add( 'my-style' . uniqid(), 'fake4.css' )->use_asset_file( true );

$this->assertEquals( ['some-dependency'], $asset->get_dependencies() );
}

/**
* @test
*/
public function it_should_use_include_css_asset_file_dependencies_when_dependencies_are_set(): void {
$asset = Asset::add( 'my-style' . uniqid(), 'fake4.css' );
$asset = Asset::add( 'my-style' . uniqid(), 'fake4.css' )->use_asset_file( true );
$asset->set_dependencies( 'fake1' );

$this->assertContains( 'fake1', $asset->get_dependencies() );
$this->assertContains( 'some-dependency', $asset->get_dependencies() );
$this->assertEquals( [ 'some-dependency', 'fake1' ], $asset->get_dependencies() );
}

/**
* @test
*/
public function it_should_use_include_css_asset_file_dependencies_when_dependencies_are_set_as_callable(): void {
$asset = Asset::add( 'my-style' . uniqid(), 'fake4.css' );
$asset = Asset::add( 'my-style' . uniqid(), 'fake4.css' )->use_asset_file( true );
$asset->set_dependencies( static function() {
return [ 'fake1' ];
} );
Expand All @@ -670,17 +678,26 @@ public function it_should_use_include_css_asset_file_dependencies_when_dependenc
/**
* @test
*/
public function it_should_use_css_asset_file_version_when_no_version_is_set(): void {
public function it_should_not_use_css_asset_file_version_when_no_version_is_set(): void {
$asset = Asset::add( 'my-style' . uniqid(), 'fake4.css' );

$this->assertEquals( '1.0.0', $asset->get_version() );
}

/**
* @test
*/
public function it_should_use_css_asset_file_version_when_no_version_is_set(): void {
$asset = Asset::add( 'my-style' . uniqid(), 'fake4.css' )->use_asset_file( true );

$this->assertEquals( '12345', $asset->get_version() );
}

/**
* @test
*/
public function it_should_use_css_asset_file_version_when_version_is_set(): void {
$asset = Asset::add( 'my-style' . uniqid(), 'fake4.css', '1.0' );
$asset = Asset::add( 'my-style' . uniqid(), 'fake4.css', '1.0' )->use_asset_file( true );

$this->assertEquals( '12345', $asset->get_version() );
}
Expand Down

0 comments on commit fdcb23b

Please sign in to comment.