Make WordPress Core

Ticket #36827: 36827.2.diff

File 36827.2.diff, 2.0 KB (added by costdev, 22 months ago)

This refreshes 36827.patch with PHPCS fixes, test standards updates, and a new file for the tests: tests/phpunit/tests/functions/wpGuessUrl.php.

  • src/wp-includes/functions.php

    diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
    index eb8130d5b4..7a68c6ef27 100644
    a b function wp_guess_url() { 
    60276027
    60286028                // The request is for the admin.
    60296029                if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin' ) !== false || strpos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false ) {
    6030                         $path = preg_replace( '#/(wp-admin/.*|wp-login.php)#i', '', $_SERVER['REQUEST_URI'] );
     6030                        $path = preg_replace( '#/(wp-admin/?.*|wp-login\.php.*)#i', '', $_SERVER['REQUEST_URI'] );
    60316031
    60326032                        // The request is for a file in ABSPATH.
    60336033                } elseif ( $script_filename_dir . '/' === $abspath_fix ) {
  • new file tests/phpunit/tests/functions/wpGuessUrl.php

    diff --git a/tests/phpunit/tests/functions/wpGuessUrl.php b/tests/phpunit/tests/functions/wpGuessUrl.php
    new file mode 100644
    index 0000000000..fc9f57c718
    - +  
     1<?php
     2
     3/**
     4 * Test wp_guess_url().
     5 *
     6 * @group functions.php
     7 * @covers ::wp_guess_url
     8 */
     9class Tests_Functions_wpGuessUrl extends WP_UnitTestCase {
     10
     11        /**
     12         * @ticket 36827
     13         *
     14         * @dataProvider data_guess_url_should_return_site_url
     15         *
     16         * @param string $url The URL to navigate to, relative to `site_url()`.
     17         */
     18        public function test_guess_url_should_return_site_url( $url ) {
     19                $siteurl = site_url();
     20                $this->go_to( site_url( $url ) );
     21                $this->assertSame( $siteurl, wp_guess_url() );
     22        }
     23
     24        /**
     25         * Data provider.
     26         *
     27         * @return array
     28         */
     29        function data_guess_url_should_return_site_url() {
     30                return array(
     31                        'no trailing slash'                            => array( 'url' => 'wp-admin' ),
     32                        'trailing slash'                               => array( 'url' => 'wp-admin/' ),
     33                        'trailing slash, query var'                    => array( 'url' => 'wp-admin/?foo=bar' ),
     34                        'file extension, no trailing slash'            => array( 'url' => 'wp-login.php' ),
     35                        'file extension, query var, no trailing slash' => array( 'url' => 'wp-login.php?foo=bar' ),
     36                );
     37        }
     38}