Make WordPress Core

Ticket #42670: 42670.2.diff

File 42670.2.diff, 1.8 KB (added by ironprogrammer, 2 years ago)

Refresh of 42670.diff

  • src/wp-includes/plugin.php

    diff --git src/wp-includes/plugin.php src/wp-includes/plugin.php
    index e445dd8ea5..4083b99695 100644
    function plugin_basename( $file ) { 
    772772        foreach ( $wp_plugin_paths as $dir => $realdir ) {
    773773                if ( strpos( $file, $realdir ) === 0 ) {
    774774                        $file = $dir . substr( $file, strlen( $realdir ) );
     775                        break;
    775776                }
    776777        }
    777778
  • tests/phpunit/tests/functions/pluginBasename.php

    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 { 
    6262                $basename = plugin_basename( '/Users/me/Dropbox/Development/Repositories/plugin/trunk/plugin.php' );
    6363                $this->assertSame( 'trunk/plugin.php', $basename );
    6464        }
     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        }
    6587}