From f34a3869169211a5fe6ad51ca3436b5701ab10ee Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 2 Sep 2015 16:50:02 +0000 Subject: [PATCH] More unit tests for `esc_url()` and `esc_url_raw()`. See #23605, #20771, #16859 git-svn-id: https://develop.svn.wordpress.org/trunk@33855 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/formatting/EscUrl.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/phpunit/tests/formatting/EscUrl.php b/tests/phpunit/tests/formatting/EscUrl.php index 2a31cc0195..be7d99527a 100644 --- a/tests/phpunit/tests/formatting/EscUrl.php +++ b/tests/phpunit/tests/formatting/EscUrl.php @@ -30,6 +30,15 @@ class Tests_Formatting_EscUrl extends WP_UnitTestCase { $this->assertEquals('?foo=bar', esc_url('?foo=bar')); } + function test_all_url_parts() { + $url = 'https://user:password@host.example.com:1234/path;p=1?q=2&r=3#fragment'; + $this->assertEquals( $url, esc_url_raw( $url ) ); + + $this->assertEquals( 'https://user:password@host.example.com:1234/path;p=1?q=2&r=3#fragment', esc_url( $url ) ); + + $this->assertEquals( 'http://example.com?foo', esc_url( 'http://example.com?foo' ) ); + } + function test_bare() { $this->assertEquals( 'http://example.com', esc_url( 'example.com' ) ); $this->assertEquals( 'http://localhost', esc_url( 'localhost' ) ); @@ -38,9 +47,16 @@ class Tests_Formatting_EscUrl extends WP_UnitTestCase { } function test_encoding() { + $this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) ); + $this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url_raw( 'http://example.com?foo=1&bar=2' ) ); + $this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url_raw( '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' ) ); $this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) ); + + $param = urlencode( 'http://example.com/?one=1&two=2' ); + $this->assertEquals( "http://example.com?url={$param}", esc_url( "http://example.com?url={$param}" ) ); } function test_protocol() {