| | 120 | /** |
| | 121 | * @ticket 35531 |
| | 122 | * @group multisite |
| | 123 | */ |
| | 124 | function test_url_to_postid_of_http_site_when_current_site_uses_https() { |
| | 125 | if ( ! is_multisite() ) { |
| | 126 | $this->markTestSkipped( 'This test requires multisite' ); |
| | 127 | } |
| | 128 | |
| | 129 | $_SERVER['HTTPS'] = 'on'; |
| | 130 | |
| | 131 | $network_home = home_url(); |
| | 132 | $this->blog_id_35531 = self::factory()->blog->create(); |
| | 133 | |
| | 134 | add_filter( 'home_url', array( $this, '_filter_http_home_url' ), 10, 4 ); |
| | 135 | |
| | 136 | switch_to_blog( $this->blog_id_35531 ); |
| | 137 | |
| | 138 | $post_id = self::factory()->post->create(); |
| | 139 | $permalink = get_permalink( $post_id ); |
| | 140 | $url_to_postid = url_to_postid( $permalink ); |
| | 141 | |
| | 142 | restore_current_blog(); |
| | 143 | |
| | 144 | // Cleanup. |
| | 145 | remove_filter( 'home_url', array( $this, '_filter_http_home_url' ), 10 ); |
| | 146 | |
| | 147 | // Test the tests: |
| | 148 | $this->assertSame( 'http', parse_url( $permalink, PHP_URL_SCHEME ) ); |
| | 149 | $this->assertSame( 'https', parse_url( $network_home, PHP_URL_SCHEME ) ); |
| | 150 | |
| | 151 | // Test that the url_to_postid() call matched: |
| | 152 | $this->assertEquals( $post_id, $url_to_postid ); |
| | 153 | } |
| | 154 | |
| | 155 | /** |
| | 156 | * Enforce an `http` scheme for our target site. |
| | 157 | * |
| | 158 | * @param string $url The complete home URL including scheme and path. |
| | 159 | * @param string $path Path relative to the home URL. Blank string if no path is specified. |
| | 160 | * @param string|null $orig_scheme Scheme to give the home URL context. |
| | 161 | * @param int|null $blog_id Site ID, or null for the current site. |
| | 162 | * @return string The complete home URL including scheme and path. |
| | 163 | */ |
| | 164 | function _filter_http_home_url( $url, $path, $orig_scheme, $_blog_id ) { |
| | 165 | global $blog_id; |
| | 166 | |
| | 167 | if ( $this->blog_id_35531 === $blog_id ) { |
| | 168 | return set_url_scheme( $url, 'http' ); |
| | 169 | } |
| | 170 | |
| | 171 | return $url; |
| | 172 | } |
| | 173 | |