Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Assets
* Description: Asset library with a plugin bootstrap file for automated testing.
* Version: 1.4.11
* Version: 1.5.1
* Author: StellarWP
* Author URI: https://stellarwp.com
*/
22 changes: 21 additions & 1 deletion src/Assets/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ public static function get_relative_asset_path(): string {
/**
* Gets the root path of the project.
*
* @since 1.5.1
*
* @return string
*/
public static function get_url( $path ): string {
Expand All @@ -156,7 +158,25 @@ public static function get_url( $path ): string {

if ( empty( static::$path_urls[ $key ] ) ) {
$bases = Utils::get_bases();
static::$path_urls[ $key ] = trailingslashit( str_replace( wp_list_pluck( $bases, 'base_dir' ), wp_list_pluck( $bases, 'base_url' ), $path ) );

$base_dirs = array_column( $bases, 'base_dir' );
$base_urls = array_column( $bases, 'base_url' );

uasort( $base_dirs, function( $a, $b ) {
return strlen( $b ) <=> strlen( $a );
} );

foreach ( $base_dirs as $dir_type => $dir_path ) {
if ( ! isset( $base_urls[ $dir_type ] ) ) {
continue;
}

static::$path_urls[ $key ] = str_replace( $dir_path, $base_urls[ $dir_type ], $path );

if ( static::$path_urls[ $key ] !== $path ) {
break;
}
}
}

return static::$path_urls[ $key ];
Expand Down
12 changes: 11 additions & 1 deletion tests/wpunit/AssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@ public function constantProvider() {
'WP_PLUGIN_URL' => 'http://wordpress.test/wp-content/addons',
],
],
[
'rare case',
[
'ABSPATH' => '/wordpress.test/',
'WP_CONTENT_DIR' => '/wordpress.test/wp-content',
'WP_CONTENT_URL' => 'http://wordpress.test/wp-content',
'WP_PLUGIN_DIR' => '/wordpress.test/wp-content/plugins',
'WP_PLUGIN_URL' => 'http://wordpress.test/wp-content/plugins',
],
],
];

foreach ( $data as $d ) {
Expand Down Expand Up @@ -1129,7 +1139,7 @@ protected function assert_minified_found( $slug_prefix, $is_js = true, $has_min

$plugins_path = str_replace( constant( 'WP_CONTENT_DIR' ), '', constant( 'WP_PLUGIN_DIR' ) );

if ( constant( 'WP_PLUGIN_DIR' ) !== constant( 'WP_CONTENT_DIR' ) . $plugins_path || strpos( constant( 'ABSPATH' ), 'C:') === 0 || $wont_figure_out_min_vs_unmin ) {
if ( constant( 'WP_PLUGIN_DIR' ) !== constant( 'WP_CONTENT_DIR' ) . $plugins_path || strpos( constant( 'ABSPATH' ), 'C:') === 0 || strpos( constant( 'ABSPATH' ), '/wordpress.test/') === 0 || $wont_figure_out_min_vs_unmin ) {
// If we are testing outside of the actual plugin directory, the `is_file` check will always fail.
// In installations where this set up is the actual, the file should exist.
// In this case it will always fail to locate mins.
Expand Down
Loading