diff --git a/src/Assets/Asset.php b/src/Assets/Asset.php index db5bdc8..175e0bf 100644 --- a/src/Assets/Asset.php +++ b/src/Assets/Asset.php @@ -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 @@ -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 ); } } diff --git a/tests/wpunit/AssetsTest.php b/tests/wpunit/AssetsTest.php index d9ce479..86af111 100644 --- a/tests/wpunit/AssetsTest.php +++ b/tests/wpunit/AssetsTest.php @@ -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' ]; } ); @@ -670,9 +678,18 @@ 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() ); } @@ -680,7 +697,7 @@ public function it_should_use_css_asset_file_version_when_no_version_is_set(): v * @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() ); }