Make WordPress Core

Ticket #27888: 27888.4.patch

File 27888.4.patch, 3.7 KB (added by lucatume, 8 years ago)

27888.4.patch (tests)

  • tests/phpunit/tests/admin/includesMisc.php

     
    77        function test_shorten_url() {
    88                $tests = array(
    99                        'wordpress\.org/about/philosophy'
    10                                 => 'wordpress\.org/about/philosophy', // no longer strips slashes
     10                        => 'wordpress\.org/about/philosophy', // no longer strips slashes
    1111                        'wordpress.org/about/philosophy'
    12                                 => 'wordpress.org/about/philosophy',
     12                        => 'wordpress.org/about/philosophy',
    1313                        'http://wordpress.org/about/philosophy/'
    14                                 => 'wordpress.org/about/philosophy', // remove http, trailing slash
     14                        => 'wordpress.org/about/philosophy', // remove http, trailing slash
    1515                        'http://www.wordpress.org/about/philosophy/'
    16                                 => 'wordpress.org/about/philosophy', // remove http, www
     16                        => 'wordpress.org/about/philosophy', // remove http, www
    1717                        'http://wordpress.org/about/philosophy/#box'
    18                                 => 'wordpress.org/about/philosophy/#box', // don't shorten 35 characters
     18                        => 'wordpress.org/about/philosophy/#box', // don't shorten 35 characters
    1919                        'http://wordpress.org/about/philosophy/#decisions'
    20                                 => 'wordpress.org/about/philosophy/#…', // shorten to 32 if > 35 after cleaning
     20                        => 'wordpress.org/about/philosophy/#…', // shorten to 32 if > 35 after cleaning
    2121                );
    22                 foreach ( $tests as $k => $v )
     22                foreach ( $tests as $k => $v ) {
    2323                        $this->assertEquals( $v, url_shorten( $k ) );
     24                }
    2425        }
     26
     27        public function test_get_current_admin_page_url_returns_false_in_non_admin() {
     28                set_current_screen( 'front' );
     29
     30                $this->assertFalse( is_admin() );
     31
     32                $this->assertFalse( get_current_admin_page_url() );
     33        }
     34
     35        public function test_get_current_admin_page_url_returns_empty_string_for_empty_pagenow_or_SERVER_values() {
     36                global $pagenow;
     37                $pagenow                 = '';
     38                $_SERVER['QUERY_STRING'] = '';
     39
     40                // any admin screen will do for the purpose of testing
     41                set_current_screen( 'edit.php' );
     42
     43                $this->assertTrue( is_admin() );
     44
     45                $this->assertEquals( '', get_current_admin_page_url() );
     46        }
     47
     48        public function pagenow_and_SERVER_QUERY_STRING() {
     49                return array(
     50                        array( 'some-admin-page.php', 'some-admin-page.php', '' ),
     51                        array( 'some-admin-page.php?foo=bar', 'some-admin-page.php', 'foo=bar' ),
     52                        array( 'some-admin-page.php?foo=bar&baz=bar', 'some-admin-page.php', 'foo=bar&baz=bar' ),
     53                );
     54        }
     55
     56        /**
     57         * @dataProvider pagenow_and_SERVER_QUERY_STRING
     58         */
     59        public function test_get_current_admin_page_url( $expected, $mock_pagenow, $server_query_string ) {
     60                global $pagenow;
     61                $pagenow                 = $mock_pagenow;
     62                $_SERVER['QUERY_STRING'] = $server_query_string;
     63
     64                // any admin screen will do for the purpose of testing
     65                set_current_screen( 'edit.php' );
     66
     67                $this->assertTrue( is_admin() );
     68
     69                $this->assertEquals( $expected, get_current_admin_page_url() );
     70        }
     71
     72        public function test_get_current_admin_hook_will_return_false_in_not_admin() {
     73                set_current_screen( 'front' );
     74
     75                $this->assertFalse( get_current_admin_hook() );
     76        }
     77
     78        public function current_filters() {
     79                return array(
     80                        array( '', array( '' ) ),
     81                        array( 'some_hook', array( 'some_hook' ) ),
     82                        array( 'another_hook', array( 'some_hook', 'another_hook' ) ),
     83                );
     84        }
     85
     86        /**
     87         * @dataProvider current_filters
     88         */
     89        public function test_get_current_admin_hook( $expected, $mock_current_filter ) {
     90                // any admin screen will do for the purpose of testing
     91                set_current_screen( 'edit.php' );
     92
     93                global $wp_current_filter;
     94                $wp_current_filter = $mock_current_filter;
     95
     96                $this->assertEquals( $expected, get_current_admin_hook() );
     97        }
    2598}