Make WordPress Core

Changeset 999 in tests for trunk/tests/admin/includesScreen.php


Ignore:
Timestamp:
08/31/2012 05:17:58 PM (12 years ago)
Author:
ryan
Message:

Tests for WP_Screen::in_admin(). see #WP21742

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/admin/includesScreen.php

    r909 r999  
    7171                $this->assertEquals( $screen->taxonomy, $current_screen->taxonomy, $hook_name );
    7272
     73            $this->assertTrue( $current_screen->in_admin() );
     74            $this->assertTrue( $current_screen->in_admin( 'site' ) );
     75            $this->assertFalse( $current_screen->in_admin( 'network' ) );
     76            $this->assertFalse( $current_screen->in_admin( 'user' ) );
     77            $this->assertFalse( $current_screen->in_admin( 'garbage' ) );
     78           
    7379            // With convert_to_screen(), the same ID should return the exact $current_screen.
    7480            $this->assertSame( $current_screen, convert_to_screen( $screen->id ), $hook_name );
     
    164170        $this->assertEquals( $screen->get_help_tabs(), array() );
    165171    }
     172
     173    function test_in_admin() {
     174        $screen = get_current_screen();
     175
     176        set_current_screen( 'edit.php' );
     177        $this->assertTrue( get_current_screen()->in_admin() );
     178        $this->assertTrue( get_current_screen()->in_admin( 'site' ) );
     179        $this->assertFalse( get_current_screen()->in_admin( 'network' ) );
     180        $this->assertFalse( get_current_screen()->in_admin( 'user' ) );
     181
     182        set_current_screen( 'dashboard-network' );
     183        $this->assertTrue( get_current_screen()->in_admin() );
     184        $this->assertFalse( get_current_screen()->in_admin( 'site' ) );
     185        $this->assertTrue( get_current_screen()->in_admin( 'network' ) );
     186        $this->assertFalse( get_current_screen()->in_admin( 'user' ) );
     187
     188        set_current_screen( 'dashboard-user' );
     189        $this->assertTrue( get_current_screen()->in_admin() );
     190        $this->assertFalse( get_current_screen()->in_admin( 'site' ) );
     191        $this->assertFalse( get_current_screen()->in_admin( 'network' ) );
     192        $this->assertTrue( get_current_screen()->in_admin( 'user' ) );
     193
     194        set_current_screen( 'front' );
     195        $this->assertFalse( get_current_screen()->in_admin() );
     196        $this->assertFalse( get_current_screen()->in_admin( 'site' ) );
     197        $this->assertFalse( get_current_screen()->in_admin( 'network' ) );
     198        $this->assertFalse( get_current_screen()->in_admin( 'user' ) );
     199
     200        $GLOBALS['current_screen'] = $screen;
     201    }
    166202}
Note: See TracChangeset for help on using the changeset viewer.