diff --git src/wp-includes/plugin.php src/wp-includes/plugin.php
index e445dd8ea5..4083b99695 100644
|
|
|
function plugin_basename( $file ) { |
| 772 | 772 | foreach ( $wp_plugin_paths as $dir => $realdir ) { |
| 773 | 773 | if ( strpos( $file, $realdir ) === 0 ) { |
| 774 | 774 | $file = $dir . substr( $file, strlen( $realdir ) ); |
| | 775 | break; |
| 775 | 776 | } |
| 776 | 777 | } |
| 777 | 778 | |
diff --git tests/phpunit/tests/functions/pluginBasename.php tests/phpunit/tests/functions/pluginBasename.php
index d28cf914cf..50d0bf2238 100644
|
|
|
class Tests_Functions_PluginBasename extends WP_UnitTestCase { |
| 62 | 62 | $basename = plugin_basename( '/Users/me/Dropbox/Development/Repositories/plugin/trunk/plugin.php' ); |
| 63 | 63 | $this->assertSame( 'trunk/plugin.php', $basename ); |
| 64 | 64 | } |
| | 65 | |
| | 66 | /** |
| | 67 | * Mimic a parent project directory that contains a plugin and WordPress installation. E.g. |
| | 68 | * |
| | 69 | * Project directory: ../Projects/plugin-root |
| | 70 | * WordPress install: ../Projects/plugin-root/wordpress |
| | 71 | * |
| | 72 | * @ticket 42670 |
| | 73 | */ |
| | 74 | public function test_should_return_correct_basename_for_plugin_when_wp_plugins_dir_is_subdir_of_symlinked_plugin() { |
| | 75 | global $wp_plugin_paths; |
| | 76 | |
| | 77 | $plugin_project_root_directory = dirname( $this->wp_plugin_path, 3 ); |
| | 78 | |
| | 79 | $wp_plugin_paths = array( |
| | 80 | $this->wp_plugin_path . '/plugin-root' => $plugin_project_root_directory, |
| | 81 | $this->wp_plugin_path . '/woocommerce' => $plugin_project_root_directory . '/wordpress/wp-content/plugins/woocommerce', |
| | 82 | ); |
| | 83 | |
| | 84 | $actual = plugin_basename( $plugin_project_root_directory . '/wordpress/wp-content/plugins/woocommerce/woocommerce.php' ); |
| | 85 | $this->assertSame( 'woocommerce/woocommerce.php', $actual, 'The basename returned is incorrect.' ); |
| | 86 | } |
| 65 | 87 | } |