Add some more passing unit tests for esc_url()
in preparation for upcoming changes.
See #23605, #20771, #16859 git-svn-id: https://develop.svn.wordpress.org/trunk@33851 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7232be7dcd
commit
4720c6e482
@ -30,9 +30,47 @@ class Tests_Formatting_EscUrl extends WP_UnitTestCase {
|
||||
$this->assertEquals('?foo=bar', esc_url('?foo=bar'));
|
||||
}
|
||||
|
||||
function test_bare() {
|
||||
$this->assertEquals( 'http://example.com', esc_url( 'example.com' ) );
|
||||
$this->assertEquals( 'http://localhost', esc_url( 'localhost' ) );
|
||||
$this->assertEquals( 'http://example.com/foo', esc_url( 'example.com/foo' ) );
|
||||
$this->assertEquals( 'http://баба.org/баба', esc_url( 'баба.org/баба' ) );
|
||||
}
|
||||
|
||||
function test_encoding() {
|
||||
$this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );
|
||||
$this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );
|
||||
$this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );
|
||||
}
|
||||
|
||||
function test_protocol() {
|
||||
$this->assertEquals('http://example.com', esc_url('http://example.com'));
|
||||
$this->assertEquals('', esc_url('nasty://example.com/'));
|
||||
$this->assertEquals( '', esc_url( 'example.com', array(
|
||||
'https',
|
||||
) ) );
|
||||
$this->assertEquals( '', esc_url( 'http://example.com', array(
|
||||
'https',
|
||||
) ) );
|
||||
$this->assertEquals( 'https://example.com', esc_url( 'https://example.com', array(
|
||||
'http', 'https',
|
||||
) ) );
|
||||
|
||||
foreach ( wp_allowed_protocols() as $scheme ) {
|
||||
$this->assertEquals( "{$scheme}://example.com", esc_url( "{$scheme}://example.com" ), $scheme );
|
||||
$this->assertEquals( "{$scheme}://example.com", esc_url( "{$scheme}://example.com", array(
|
||||
$scheme,
|
||||
) ), $scheme );
|
||||
}
|
||||
|
||||
$this->assertTrue( ! in_array( 'data', wp_allowed_protocols(), true ) );
|
||||
$this->assertEquals( '', esc_url( 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D' ) );
|
||||
|
||||
$this->assertTrue( ! in_array( 'foo', wp_allowed_protocols(), true ) );
|
||||
$this->assertEquals( 'foo://example.com', esc_url( 'foo://example.com', array(
|
||||
'foo',
|
||||
) ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user