Make WordPress Core

Changeset 33851


Ignore:
Timestamp:
09/02/2015 02:19:21 PM (11 years ago)
Author:
johnbillion
Message:

Add some more passing unit tests for esc_url() in preparation for upcoming changes.

See #23605, #20771, #16859

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/formatting/EscUrl.php

    r33064 r33851  
    3131        }
    3232
     33        function test_bare() {
     34                $this->assertEquals( 'http://example.com', esc_url( 'example.com' ) );
     35                $this->assertEquals( 'http://localhost', esc_url( 'localhost' ) );
     36                $this->assertEquals( 'http://example.com/foo', esc_url( 'example.com/foo' ) );
     37                $this->assertEquals( 'http://баба.org/баба', esc_url( 'баба.org/баба' ) );
     38        }
     39
     40        function test_encoding() {
     41                $this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );
     42                $this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );
     43                $this->assertEquals( 'http://example.com?foo=1&bar=2', esc_url( 'http://example.com?foo=1&bar=2' ) );
     44        }
     45
    3346        function test_protocol() {
    3447                $this->assertEquals('http://example.com', esc_url('http://example.com'));
    3548                $this->assertEquals('', esc_url('nasty://example.com/'));
     49                $this->assertEquals( '', esc_url( 'example.com', array(
     50                        'https',
     51                ) ) );
     52                $this->assertEquals( '', esc_url( 'http://example.com', array(
     53                        'https',
     54                ) ) );
     55                $this->assertEquals( 'https://example.com', esc_url( 'https://example.com', array(
     56                        'http', 'https',
     57                ) ) );
     58
     59                foreach ( wp_allowed_protocols() as $scheme ) {
     60                        $this->assertEquals( "{$scheme}://example.com", esc_url( "{$scheme}://example.com" ), $scheme );
     61                        $this->assertEquals( "{$scheme}://example.com", esc_url( "{$scheme}://example.com", array(
     62                                $scheme,
     63                        ) ), $scheme );
     64                }
     65
     66                $this->assertTrue( ! in_array( 'data', wp_allowed_protocols(), true ) );
     67                $this->assertEquals( '', esc_url( 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D' ) );
     68
     69                $this->assertTrue( ! in_array( 'foo', wp_allowed_protocols(), true ) );
     70                $this->assertEquals( 'foo://example.com', esc_url( 'foo://example.com', array(
     71                        'foo',
     72                ) ) );
     73
    3674        }
    3775
Note: See TracChangeset for help on using the changeset viewer.