mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@34890 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -92,6 +92,36 @@ class Tests_Rewrite extends WP_UnitTestCase {
|
||||
$this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) );
|
||||
}
|
||||
|
||||
function test_url_to_postid_set_url_scheme_https_to_http() {
|
||||
$post_id = $this->factory->post->create();
|
||||
$permalink = get_permalink( $post_id );
|
||||
$this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'https' ) ) );
|
||||
|
||||
$post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
|
||||
$permalink = get_permalink( $post_id );
|
||||
$this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'https' ) ) );
|
||||
}
|
||||
|
||||
function test_url_to_postid_set_url_scheme_http_to_https() {
|
||||
// Save server data for cleanup
|
||||
$is_ssl = is_ssl();
|
||||
$http_host = $_SERVER['HTTP_HOST'];
|
||||
|
||||
$_SERVER['HTTPS'] = 'on';
|
||||
|
||||
$post_id = $this->factory->post->create();
|
||||
$permalink = get_permalink( $post_id );
|
||||
$this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'http' ) ) );
|
||||
|
||||
$post_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
|
||||
$permalink = get_permalink( $post_id );
|
||||
$this->assertEquals( $post_id, url_to_postid( set_url_scheme( $permalink, 'http' ) ) );
|
||||
|
||||
// Cleanup.
|
||||
$_SERVER['HTTPS'] = $is_ssl ? 'on' : 'off';
|
||||
$_SERVER['HTTP_HOST'] = $http_host;
|
||||
}
|
||||
|
||||
function test_url_to_postid_custom_post_type() {
|
||||
delete_option( 'rewrite_rules' );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user