Skip to content

Commit

Permalink
Include tests for Diff URL and Dir
Browse files Browse the repository at this point in the history
  • Loading branch information
bordoni committed Jun 13, 2024
1 parent 43da522 commit c53618d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Assets/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,6 @@ public function get_url( bool $use_min_if_available = true ): string {
$this->url = $this->build_asset_url();
}
}

if ( $this->min_url === null ) {
$this->min_url = $this->maybe_get_min_file( $this->url );
}
Expand Down
35 changes: 35 additions & 0 deletions tests/wpunit/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,41 @@ public function it_should_locate_minified_versions_of_external_assets() {
}
}

/**
* @test
*/
public function it_should_get_the_correct_url_when_wp_content_dir_and_wp_content_url_are_diff() {

$this->set_const_value( 'WP_CONTENT_DIR', '/var/www/html/wp-content' );
$this->set_const_value( 'WP_CONTENT_URL', 'http://wordpress.test/foo' );
$this->set_const_value( 'WP_PLUGIN_DIR', '/var/www/html/wp-content/plugins' );
$this->set_const_value( 'WP_PLUGIN_URL', 'http://wordpress.test/foo/plugins' );
$this->set_const_value( 'SCRIPT_DEBUG', false );

Config::reset();
Config::set_hook_prefix( 'bork' );
Config::set_version( '1.1.0' );
Config::set_path( dirname( dirname( __DIR__ ) ) );
Config::set_relative_asset_path( 'tests/_data/' );

Asset::add( 'fake1-script', 'fake1.js' )->register();
Asset::add( 'fake2-script', 'fake2.js' )->register();
Asset::add( 'fake3-script', 'fake3.js' )->register();

$this->assertEquals(
Assets::init()->get( 'fake1-script' )->get_url(),
'http://wordpress.test/foo/plugins/assets/tests/_data/js/fake1.min.js'
);
$this->assertEquals(
Assets::init()->get( 'fake2-script' )->get_url(),
'http://wordpress.test/foo/plugins/assets/tests/_data/js/fake2.js'
);
$this->assertEquals(
Assets::init()->get( 'fake3-script' )->get_url(),
'http://wordpress.test/foo/plugins/assets/tests/_data/js/fake3.min.js'
);
}

/**
* @test
*/
Expand Down

0 comments on commit c53618d

Please sign in to comment.