| | 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:link' => 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 | ); |
| | 61 | |
| | 121 | function test_set_current_screen_with_guid() { |
| | 122 | global $current_screen; |
| | 123 | |
| | 124 | foreach ( $this->core_screens_guid as $guid => $screen ) { |
| | 125 | $screen = (object) $screen; |
| | 126 | set_current_screen( $guid ); |
| | 127 | $this->assertEquals( $screen->id, $current_screen->id, $guid ); |
| | 128 | $this->assertEquals( $screen->base, $current_screen->base, $guid ); |
| | 129 | if ( isset( $screen->action ) ) |
| | 130 | $this->assertEquals( $screen->action, $current_screen->action, $guid ); |
| | 131 | if ( isset( $screen->post_type ) ) |
| | 132 | $this->assertEquals( $screen->post_type, $current_screen->post_type, $guid ); |
| | 133 | else |
| | 134 | $this->assertEmpty( $current_screen->post_type, $guid ); |
| | 135 | if ( isset( $screen->taxonomy ) ) |
| | 136 | $this->assertEquals( $screen->taxonomy, $current_screen->taxonomy, $guid ); |
| | 137 | |
| | 138 | $this->assertTrue( $current_screen->in_admin() ); |
| | 139 | $this->assertTrue( $current_screen->in_admin( 'site' ) ); |
| | 140 | $this->assertFalse( $current_screen->in_admin( 'network' ) ); |
| | 141 | $this->assertFalse( $current_screen->in_admin( 'user' ) ); |
| | 142 | $this->assertFalse( $current_screen->in_admin( 'garbage' ) ); |
| | 143 | |
| | 144 | // With convert_to_screen(), the same ID should return the exact $current_screen. |
| | 145 | $this->assertSame( $current_screen, convert_to_screen( $screen->id ), $guid ); |
| | 146 | } |
| | 147 | } |
| | 148 | |