| 1 | <?php |
| 2 | |
| 3 | class WPTestScreen extends WPTestCase { |
| 4 | var $core_screens = array( |
| 5 | 'index.php' => array( 'base' => 'dashboard', 'id' => 'dashboard' ), |
| 6 | 'edit.php' => array( 'base' => 'edit', 'id' => 'edit-post', 'post_type' => 'post' ), |
| 7 | 'post-new.php'=> array( 'action' => 'add', 'base' => 'post', 'id' => 'post', 'post_type' => 'post' ), |
| 8 | 'edit-tags.php?taxonomy=category' => array( 'base' => 'edit-tags', 'id' => 'edit-category', 'post_type' => 'post', 'taxonomy' => 'category' ), |
| 9 | 'edit-tags.php?taxonomy=post_tag' => array( 'base' => 'edit-tags', 'id' => 'edit-post_tag', 'post_type' => 'post', 'taxonomy' => 'post_tag' ), |
| 10 | 'upload.php' => array( 'base' => 'upload', 'id' => 'upload' ), |
| 11 | 'media-new.php' => array( 'action' => 'add', 'base' => 'media', 'id' => 'media' ), |
| 12 | 'edit.php?post_type=page' => array( 'base' => 'edit', 'id' => 'edit-page', 'post_type' => 'page' ), |
| 13 | 'link-manager.php' => array( 'base' => 'link-manager', 'id' => 'link-manager' ), |
| 14 | 'link-add.php' => array( 'action' => 'add', 'base' => 'link', 'id' => 'link' ), |
| 15 | 'edit-comments.php' => array( 'base' => 'edit-comments', 'id' => 'edit-comments' ), |
| 16 | 'themes.php' => array( 'base' => 'themes', 'id' => 'themes' ), |
| 17 | 'widgets.php' => array( 'base' => 'widgets', 'id' => 'widgets' ), |
| 18 | 'nav-menus.php' => array( 'base' => 'nav-menus', 'id' => 'nav-menus' ), |
| 19 | 'plugins.php' => array( 'base' => 'plugins', 'id' => 'plugins' ), |
| 20 | 'users.php' => array( 'base' => 'users', 'id' => 'users' ), |
| 21 | 'user-new.php' => array( 'action' => 'add', 'base' => 'user', 'id' => 'user' ), |
| 22 | 'profile.php' => array( 'base' => 'profile', 'id' => 'profile' ), |
| 23 | 'tools.php' => array( 'base' => 'tools', 'id' => 'tools' ), |
| 24 | 'import.php' => array( 'base' => 'import', 'id' => 'import' ), |
| 25 | 'export.php' => array( 'base' => 'export', 'id' => 'export' ), |
| 26 | 'options-general.php' => array( 'base' => 'options-general', 'id' => 'options-general' ), |
| 27 | 'options-writing.php' => array( 'base' => 'options-writing', 'id' => 'options-writing' ) |
| 28 | ); |
| 29 | |
| 30 | var $old_GET; |
| 31 | var $old_POST; |
| 32 | var $old_REQUEST; |
| 33 | |
| 34 | function setUp() { |
| 35 | parent::setUp(); |
| 36 | |
| 37 | $this->old_GET = $_GET; |
| 38 | $this->old_POST = $_POST; |
| 39 | $this->old_REQUEST = $_REQUEST; |
| 40 | } |
| 41 | |
| 42 | function tearDown() { |
| 43 | parent::tearDown(); |
| 44 | |
| 45 | $_GET = $this->old_GET; |
| 46 | $_POST = $this->old_POST; |
| 47 | $_REQUEST = $this->old_REQUEST; |
| 48 | } |
| 49 | |
| 50 | function test_set_current_screen_with_hook_suffix() { |
| 51 | global $current_screen; |
| 52 | |
| 53 | foreach ( $this->core_screens as $hook_name => $screen ) { |
| 54 | $_GET = array(); |
| 55 | $GLOBALS[ 'taxnow' ] = $GLOBALS[ 'typenow' ] = ''; |
| 56 | $screen = (object) $screen; |
| 57 | $hook = parse_url( $hook_name ); |
| 58 | if ( $hook[ 'query' ] ) { |
| 59 | $args = wp_parse_args( $hook[ 'query' ] ); |
| 60 | debug_log( $args ); |
| 61 | if ( isset( $args[ 'taxonomy' ] ) ) |
| 62 | $GLOBALS[ 'taxnow' ] = $_GET[ 'taxonomy' ] = $_POST[ 'taxonomy' ] = $_REQUEST['taxonomy'] = $args[ 'taxonomy' ]; |
| 63 | if ( isset( $args[ 'post_type' ] ) ) |
| 64 | $GLOBALS[ 'typenow' ] = $_GET[ 'post_type' ] = $_POST[ 'post_type' ] = $_REQUEST[ 'post_type' ] = $args[ 'post_type' ]; |
| 65 | else if ( isset( $screen->post_type ) ) |
| 66 | $GLOBALS[ 'typenow' ] = $_GET[ 'post_type' ] = $_POST[ 'post_type' ] = $_REQUEST[ 'post_type' ] = $screen->post_type; |
| 67 | } |
| 68 | debug_log( $hook ); |
| 69 | $GLOBALS[ 'hook_suffix' ] = $hook['path']; |
| 70 | set_current_screen(); |
| 71 | $this->assertEquals( $screen->id, $current_screen->id ); |
| 72 | $this->assertEquals( $screen->base, $current_screen->base ); |
| 73 | if ( isset( $screen->action ) ) |
| 74 | $this->assertEquals( $screen->action, $current_screen->action, $hook_name ); |
| 75 | if ( isset( $screen->post_type ) && ! isset( $screen->taxonomy) ) // Remove !isset once 18785.6.diff is applied |
| 76 | $this->assertEquals( $screen->post_type, $current_screen->post_type, $hook_name ); |
| 77 | if ( isset( $screen->taxonomy ) ) |
| 78 | $this->assertEquals( $screen->taxonomy, $current_screen->taxonomy, $hook_name ); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | No newline at end of file |