WordPress.org

Make WordPress Core

Ticket #21871: 21871-guid-ut.3.diff

File 21871-guid-ut.3.diff, 9.3 KB (added by ryan, 6 years ago)
  • tests/admin/includesScreen.php

     
    55 */
    66class Tests_Admin_includesScreen extends WP_UnitTestCase {
    77        var $core_screens = array(
    8                 'index.php' => array( 'base' => 'dashboard', 'id' => 'dashboard' ),
    9                 'edit.php' => array( 'base' => 'edit', 'id' => 'edit-post', 'post_type' => 'post' ),
    10                 'post-new.php'=> array( 'action' => 'add', 'base' => 'post', 'id' => 'post', 'post_type' => 'post' ),
    11                 'edit-tags.php' => array( 'base' => 'edit-tags', 'id' => 'edit-post_tag', 'post_type' => 'post', 'taxonomy' => 'post_tag' ),
    12                 'edit-tags.php?taxonomy=post_tag' => array( 'base' => 'edit-tags', 'id' => 'edit-post_tag', 'post_type' => 'post', 'taxonomy' => 'post_tag' ),
    13                 'edit-tags.php?taxonomy=category' => array( 'base' => 'edit-tags', 'id' => 'edit-category', 'post_type' => 'post', 'taxonomy' => 'category' ),
    14                 'upload.php' => array( 'base' => 'upload', 'id' => 'upload' ),
    15                 'media-new.php' => array( 'action' => 'add', 'base' => 'media', 'id' => 'media' ),
    16                 'edit.php?post_type=page' => array( 'base' => 'edit', 'id' => 'edit-page', 'post_type' => 'page' ),
    17                 'link-manager.php' => array( 'base' => 'link-manager', 'id' => 'link-manager' ),
    18                 'link-add.php' => array( 'action' => 'add', 'base' => 'link', 'id' => 'link' ),
    19                 'edit-tags.php?taxonomy=link_category' => array( 'base' => 'edit-tags', 'id' => 'edit-link_category', 'taxonomy' => 'link_category' ),
    20                 'edit-comments.php' => array( 'base' => 'edit-comments', 'id' => 'edit-comments' ),
    21                 'themes.php' => array( 'base' => 'themes', 'id' => 'themes' ),
    22                 'widgets.php' => array( 'base' => 'widgets', 'id' => 'widgets' ),
    23                 'nav-menus.php' => array( 'base' => 'nav-menus', 'id' => 'nav-menus' ),
    24                 'plugins.php' => array( 'base' => 'plugins', 'id' => 'plugins' ),
    25                 'users.php' => array( 'base' => 'users', 'id' => 'users' ),
    26                 'user-new.php' => array( 'action' => 'add', 'base' => 'user', 'id' => 'user' ),
    27                 'profile.php' => array( 'base' => 'profile', 'id' => 'profile' ),
    28                 'tools.php' => array( 'base' => 'tools', 'id' => 'tools' ),
    29                 'import.php' => array( 'base' => 'import', 'id' => 'import' ),
    30                 'export.php' => array( 'base' => 'export', 'id' => 'export' ),
    31                 'options-general.php' => array( 'base' => 'options-general', 'id' => 'options-general' ),
    32                 'options-writing.php' => array( 'base' => 'options-writing', 'id' => 'options-writing' ),
     8                'index.php' => array( 'base' => 'dashboard', 'id' => 'dashboard', 'guid' => 'site:dashboard' ),
     9                'edit.php' => array( 'base' => 'edit', 'id' => 'edit-post', 'post_type' => 'post', 'guid' => 'site:edit:post' ),
     10                'post-new.php'=> array( 'action' => 'add', 'base' => 'post', 'id' => 'post', 'post_type' => 'post', 'guid' => 'site:post:post' ),
     11                'edit-tags.php' => array( 'base' => 'edit-tags', 'id' => 'edit-post_tag', 'post_type' => 'post', 'taxonomy' => 'post_tag', 'guid' => 'site:edit-tags:post_tag:post' ),
     12                'edit-tags.php?taxonomy=post_tag' => array( 'base' => 'edit-tags', 'id' => 'edit-post_tag', 'post_type' => 'post', 'taxonomy' => 'post_tag', 'guid' => 'site:edit-tags:post_tag:post' ),
     13                'edit-tags.php?taxonomy=category' => array( 'base' => 'edit-tags', 'id' => 'edit-category', 'post_type' => 'post', 'taxonomy' => 'category', 'guid' => 'site:edit-tags:category:post' ),
     14                'upload.php' => array( 'base' => 'upload', 'id' => 'upload', 'guid' => 'site:upload' ),
     15                'media-new.php' => array( 'action' => 'add', 'base' => 'media', 'id' => 'media', 'guid' => 'site:media' ),
     16                'edit.php?post_type=page' => array( 'base' => 'edit', 'id' => 'edit-page', 'post_type' => 'page', 'guid' => 'site:edit:page' ),
     17                'link-manager.php' => array( 'base' => 'link-manager', 'id' => 'link-manager', 'guid' => 'site:link-manager' ),
     18                'link-add.php' => array( 'action' => 'add', 'base' => 'link', 'id' => 'link', 'guid' => 'site:link' ),
     19                'edit-tags.php?taxonomy=link_category' => array( 'base' => 'edit-tags', 'id' => 'edit-link_category', 'taxonomy' => 'link_category', 'guid' => 'site:edit-tags:link_category' ),
     20                'edit-comments.php' => array( 'base' => 'edit-comments', 'id' => 'edit-comments', 'guid' => 'site:edit-comments' ),
     21                'themes.php' => array( 'base' => 'themes', 'id' => 'themes', 'guid' => 'site:themes' ),
     22                'widgets.php' => array( 'base' => 'widgets', 'id' => 'widgets', 'guid' => 'site:widgets' ),
     23                'nav-menus.php' => array( 'base' => 'nav-menus', 'id' => 'nav-menus', 'guid' => 'site:nav-menus' ),
     24                'plugins.php' => array( 'base' => 'plugins', 'id' => 'plugins', 'guid' => 'site:plugins' ),
     25                'users.php' => array( 'base' => 'users', 'id' => 'users', 'guid' => 'site:users' ),
     26                'user-new.php' => array( 'action' => 'add', 'base' => 'user', 'id' => 'user', 'guid' => 'site:user' ),
     27                'profile.php' => array( 'base' => 'profile', 'id' => 'profile', 'guid' => 'site:profile' ),
     28                'tools.php' => array( 'base' => 'tools', 'id' => 'tools', 'guid' => 'site:tools' ),
     29                'import.php' => array( 'base' => 'import', 'id' => 'import', 'guid' => 'site:import' ),
     30                'export.php' => array( 'base' => 'export', 'id' => 'export', 'guid' => 'site:export' ),
     31                'options-general.php' => array( 'base' => 'options-general', 'id' => 'options-general', 'guid' => 'site:options-general' ),
     32                'options-writing.php' => array( 'base' => 'options-writing', 'id' => 'options-writing', 'guid' => 'site:options-writing' ),
    3333        );
    3434
     35        var $core_screens_guid = array(
     36                'site:dashboard' => array( 'base' => 'dashboard', 'id' => 'dashboard' ),
     37                'site:edit:post' => array( 'base' => 'edit', 'id' => 'edit-post', 'post_type' => 'post' ),
     38                'site:post:post'=> array( 'action' => 'add', 'base' => 'post', 'id' => 'post', 'post_type' => 'post' ),
     39                'site:edit-tags:post_tag:post' => array( 'base' => 'edit-tags', 'id' => 'edit-post_tag', 'post_type' => 'post', 'taxonomy' => 'post_tag' ),
     40                'site:edit-tags:category:post' => array( 'base' => 'edit-tags', 'id' => 'edit-category', 'post_type' => 'post', 'taxonomy' => 'category' ),
     41                'site:upload' => array( 'base' => 'upload', 'id' => 'upload' ),
     42                'site:media' => array( 'action' => 'add', 'base' => 'media', 'id' => 'media' ),
     43                'site:edit:page' => array( 'base' => 'edit', 'id' => 'edit-page', 'post_type' => 'page' ),
     44                'site:link-manager' => array( 'base' => 'link-manager', 'id' => 'link-manager' ),
     45                'site:link' => array( 'action' => 'add', 'base' => 'link', 'id' => 'link' ),
     46                'site:edit-tags:link_category' => array( 'base' => 'edit-tags', 'id' => 'edit-link_category', 'taxonomy' => 'link_category' ),
     47                'site:edit-comments' => array( 'base' => 'edit-comments', 'id' => 'edit-comments' ),
     48                'site:themes' => array( 'base' => 'themes', 'id' => 'themes' ),
     49                'site:widgets' => array( 'base' => 'widgets', 'id' => 'widgets' ),
     50                'site:nav-menus' => array( 'base' => 'nav-menus', 'id' => 'nav-menus' ),
     51                'site:plugins' => array( 'base' => 'plugins', 'id' => 'plugins' ),
     52                'site:users' => array( 'base' => 'users', 'id' => 'users' ),
     53                'site:user' => array( 'action' => 'add', 'base' => 'user', 'id' => 'user' ),
     54                'site:profile' => array( 'base' => 'profile', 'id' => 'profile' ),
     55                'site:tools' => array( 'base' => 'tools', 'id' => 'tools' ),
     56                'site:import' => array( 'base' => 'import', 'id' => 'import' ),
     57                'site:export' => array( 'base' => 'export', 'id' => 'export' ),
     58                'site:options-general' => array( 'base' => 'options-general', 'id' => 'options-general' ),
     59                'site:options-writing' => array( 'base' => 'options-writing', 'id' => 'options-writing' ),
     60                'network:dashboard' => array( 'base' => 'dashboard-network', 'id' => 'dashboard-network', 'in_admin' => 'network' ),
     61                'network:sites' => array( 'base' => 'sites-network', 'id' => 'sites-network', 'in_admin' => 'network' ),
     62                'user:dashboard' => array( 'base' => 'dashboard-user', 'id' => 'dashboard-user', 'in_admin' => 'user' ),
     63        );
     64
    3565        function setUp() {
    3666                set_current_screen( 'front' );
    3767        }
     
    74104                                $this->assertEmpty( $current_screen->post_type, $hook_name );
    75105                        if ( isset( $screen->taxonomy ) )
    76106                                $this->assertEquals( $screen->taxonomy, $current_screen->taxonomy, $hook_name );
     107                        if ( isset( $screen->guid ) )
     108                                $this->assertEquals( $screen->guid, $current_screen->guid, $hook_name );
    77109
    78110                        $this->assertTrue( $current_screen->in_admin() );
    79111                        $this->assertTrue( $current_screen->in_admin( 'site' ) );
     
    91123                }
    92124        }
    93125
     126        function test_set_current_screen_with_guid() {
     127                global $current_screen;
     128
     129                foreach ( $this->core_screens_guid as $guid => $screen ) {
     130                        $screen = (object) $screen;
     131                        set_current_screen( $guid );
     132                        $this->assertEquals( $screen->id, $current_screen->id, $guid );
     133                        $this->assertEquals( $screen->base, $current_screen->base, $guid );
     134                        if ( isset( $screen->action ) )
     135                                $this->assertEquals( $screen->action, $current_screen->action, $guid );
     136                        if ( isset( $screen->post_type ) )
     137                                $this->assertEquals( $screen->post_type, $current_screen->post_type, $guid );
     138                        else
     139                                $this->assertEmpty( $current_screen->post_type, $guid );
     140                        if ( isset( $screen->taxonomy ) )
     141                                $this->assertEquals( $screen->taxonomy, $current_screen->taxonomy, $guid );
     142
     143                        // With convert_to_screen(), the same ID should return the exact $current_screen.
     144                        $this->assertSame( $current_screen, convert_to_screen( $screen->id ), $guid );
     145                }
     146        }
     147
    94148        function test_post_type_as_hookname() {
    95149                $screen = convert_to_screen( 'page' );
    96150                $this->assertEquals( $screen->post_type, 'page' );