Make WordPress Core


Ignore:
Timestamp:
10/07/2015 01:06:58 AM (9 years ago)
Author:
wonderboymusic
Message:

Rewrite/Permalinks/Canonical: in url_to_postid(), call set_url_scheme() on the URL to combat mixed content issues and find posts cross-scheme.

Adds unit tests.

Props swissspidy.
Fixes #34144.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rewrite.php

    r34810 r34890  
    9393    }
    9494
     95    function test_url_to_postid_set_url_scheme_https_to_http() {
     96        $post_id = $this->factory->post->create();
     97        $permalink = get_permalink( $post_id );
     98        $this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'https' ) ) );
     99
     100        $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
     101        $permalink = get_permalink( $post_id );
     102        $this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'https' ) ) );
     103    }
     104
     105    function test_url_to_postid_set_url_scheme_http_to_https() {
     106        // Save server data for cleanup
     107        $is_ssl = is_ssl();
     108        $http_host = $_SERVER['HTTP_HOST'];
     109
     110        $_SERVER['HTTPS'] = 'on';
     111
     112        $post_id = $this->factory->post->create();
     113        $permalink = get_permalink( $post_id );
     114        $this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'http' ) ) );
     115
     116        $post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
     117        $permalink = get_permalink( $post_id );
     118        $this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'http' ) ) );
     119
     120        // Cleanup.
     121        $_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off';
     122        $_SERVER['HTTP_HOST'] = $http_host;
     123    }
     124
    95125    function test_url_to_postid_custom_post_type() {
    96126        delete_option( 'rewrite_rules' );
Note: See TracChangeset for help on using the changeset viewer.