mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -6,31 +6,122 @@
|
||||
*/
|
||||
class Tests_Admin_includesScreen extends WP_UnitTestCase {
|
||||
var $core_screens = array(
|
||||
'index.php' => array( 'base' => 'dashboard', 'id' => 'dashboard' ),
|
||||
'edit.php' => array( 'base' => 'edit', 'id' => 'edit-post', 'post_type' => 'post' ),
|
||||
'post-new.php'=> array( 'action' => 'add', 'base' => 'post', 'id' => 'post', 'post_type' => 'post' ),
|
||||
'edit-tags.php' => array( 'base' => 'edit-tags', 'id' => 'edit-post_tag', 'post_type' => 'post', 'taxonomy' => 'post_tag' ),
|
||||
'edit-tags.php?taxonomy=post_tag' => array( 'base' => 'edit-tags', 'id' => 'edit-post_tag', 'post_type' => 'post', 'taxonomy' => 'post_tag' ),
|
||||
'edit-tags.php?taxonomy=category' => array( 'base' => 'edit-tags', 'id' => 'edit-category', 'post_type' => 'post', 'taxonomy' => 'category' ),
|
||||
'upload.php' => array( 'base' => 'upload', 'id' => 'upload', 'post_type' => 'attachment' ),
|
||||
'media-new.php' => array( 'action' => 'add', 'base' => 'media', 'id' => 'media' ),
|
||||
'edit.php?post_type=page' => array( 'base' => 'edit', 'id' => 'edit-page', 'post_type' => 'page' ),
|
||||
'link-manager.php' => array( 'base' => 'link-manager', 'id' => 'link-manager' ),
|
||||
'link-add.php' => array( 'action' => 'add', 'base' => 'link', 'id' => 'link' ),
|
||||
'edit-tags.php?taxonomy=link_category' => array( 'base' => 'edit-tags', 'id' => 'edit-link_category', 'taxonomy' => 'link_category', 'post_type' => '' ),
|
||||
'edit-comments.php' => array( 'base' => 'edit-comments', 'id' => 'edit-comments' ),
|
||||
'themes.php' => array( 'base' => 'themes', 'id' => 'themes' ),
|
||||
'widgets.php' => array( 'base' => 'widgets', 'id' => 'widgets' ),
|
||||
'nav-menus.php' => array( 'base' => 'nav-menus', 'id' => 'nav-menus' ),
|
||||
'plugins.php' => array( 'base' => 'plugins', 'id' => 'plugins' ),
|
||||
'users.php' => array( 'base' => 'users', 'id' => 'users' ),
|
||||
'user-new.php' => array( 'action' => 'add', 'base' => 'user', 'id' => 'user' ),
|
||||
'profile.php' => array( 'base' => 'profile', 'id' => 'profile' ),
|
||||
'tools.php' => array( 'base' => 'tools', 'id' => 'tools' ),
|
||||
'import.php' => array( 'base' => 'import', 'id' => 'import' ),
|
||||
'export.php' => array( 'base' => 'export', 'id' => 'export' ),
|
||||
'options-general.php' => array( 'base' => 'options-general', 'id' => 'options-general' ),
|
||||
'options-writing.php' => array( 'base' => 'options-writing', 'id' => 'options-writing' ),
|
||||
'index.php' => array(
|
||||
'base' => 'dashboard',
|
||||
'id' => 'dashboard',
|
||||
),
|
||||
'edit.php' => array(
|
||||
'base' => 'edit',
|
||||
'id' => 'edit-post',
|
||||
'post_type' => 'post',
|
||||
),
|
||||
'post-new.php' => array(
|
||||
'action' => 'add',
|
||||
'base' => 'post',
|
||||
'id' => 'post',
|
||||
'post_type' => 'post',
|
||||
),
|
||||
'edit-tags.php' => array(
|
||||
'base' => 'edit-tags',
|
||||
'id' => 'edit-post_tag',
|
||||
'post_type' => 'post',
|
||||
'taxonomy' => 'post_tag',
|
||||
),
|
||||
'edit-tags.php?taxonomy=post_tag' => array(
|
||||
'base' => 'edit-tags',
|
||||
'id' => 'edit-post_tag',
|
||||
'post_type' => 'post',
|
||||
'taxonomy' => 'post_tag',
|
||||
),
|
||||
'edit-tags.php?taxonomy=category' => array(
|
||||
'base' => 'edit-tags',
|
||||
'id' => 'edit-category',
|
||||
'post_type' => 'post',
|
||||
'taxonomy' => 'category',
|
||||
),
|
||||
'upload.php' => array(
|
||||
'base' => 'upload',
|
||||
'id' => 'upload',
|
||||
'post_type' => 'attachment',
|
||||
),
|
||||
'media-new.php' => array(
|
||||
'action' => 'add',
|
||||
'base' => 'media',
|
||||
'id' => 'media',
|
||||
),
|
||||
'edit.php?post_type=page' => array(
|
||||
'base' => 'edit',
|
||||
'id' => 'edit-page',
|
||||
'post_type' => 'page',
|
||||
),
|
||||
'link-manager.php' => array(
|
||||
'base' => 'link-manager',
|
||||
'id' => 'link-manager',
|
||||
),
|
||||
'link-add.php' => array(
|
||||
'action' => 'add',
|
||||
'base' => 'link',
|
||||
'id' => 'link',
|
||||
),
|
||||
'edit-tags.php?taxonomy=link_category' => array(
|
||||
'base' => 'edit-tags',
|
||||
'id' => 'edit-link_category',
|
||||
'taxonomy' => 'link_category',
|
||||
'post_type' => '',
|
||||
),
|
||||
'edit-comments.php' => array(
|
||||
'base' => 'edit-comments',
|
||||
'id' => 'edit-comments',
|
||||
),
|
||||
'themes.php' => array(
|
||||
'base' => 'themes',
|
||||
'id' => 'themes',
|
||||
),
|
||||
'widgets.php' => array(
|
||||
'base' => 'widgets',
|
||||
'id' => 'widgets',
|
||||
),
|
||||
'nav-menus.php' => array(
|
||||
'base' => 'nav-menus',
|
||||
'id' => 'nav-menus',
|
||||
),
|
||||
'plugins.php' => array(
|
||||
'base' => 'plugins',
|
||||
'id' => 'plugins',
|
||||
),
|
||||
'users.php' => array(
|
||||
'base' => 'users',
|
||||
'id' => 'users',
|
||||
),
|
||||
'user-new.php' => array(
|
||||
'action' => 'add',
|
||||
'base' => 'user',
|
||||
'id' => 'user',
|
||||
),
|
||||
'profile.php' => array(
|
||||
'base' => 'profile',
|
||||
'id' => 'profile',
|
||||
),
|
||||
'tools.php' => array(
|
||||
'base' => 'tools',
|
||||
'id' => 'tools',
|
||||
),
|
||||
'import.php' => array(
|
||||
'base' => 'import',
|
||||
'id' => 'import',
|
||||
),
|
||||
'export.php' => array(
|
||||
'base' => 'export',
|
||||
'id' => 'export',
|
||||
),
|
||||
'options-general.php' => array(
|
||||
'base' => 'options-general',
|
||||
'id' => 'options-general',
|
||||
),
|
||||
'options-writing.php' => array(
|
||||
'base' => 'options-writing',
|
||||
'id' => 'options-writing',
|
||||
),
|
||||
);
|
||||
|
||||
function setUp() {
|
||||
@@ -47,19 +138,21 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
|
||||
global $current_screen;
|
||||
|
||||
foreach ( $this->core_screens as $hook_name => $screen ) {
|
||||
$_GET = $_POST = $_REQUEST = array();
|
||||
$_GET = $_POST = $_REQUEST = array();
|
||||
$GLOBALS['taxnow'] = $GLOBALS['typenow'] = '';
|
||||
$screen = (object) $screen;
|
||||
$hook = parse_url( $hook_name );
|
||||
$screen = (object) $screen;
|
||||
$hook = parse_url( $hook_name );
|
||||
|
||||
if ( ! empty( $hook['query'] ) ) {
|
||||
$args = wp_parse_args( $hook['query'] );
|
||||
if ( isset( $args['taxonomy'] ) )
|
||||
if ( isset( $args['taxonomy'] ) ) {
|
||||
$GLOBALS['taxnow'] = $_GET['taxonomy'] = $_POST['taxonomy'] = $_REQUEST['taxonomy'] = $args['taxonomy'];
|
||||
if ( isset( $args['post_type'] ) )
|
||||
}
|
||||
if ( isset( $args['post_type'] ) ) {
|
||||
$GLOBALS['typenow'] = $_GET['post_type'] = $_POST['post_type'] = $_REQUEST['post_type'] = $args['post_type'];
|
||||
else if ( isset( $screen->post_type ) )
|
||||
} elseif ( isset( $screen->post_type ) ) {
|
||||
$GLOBALS['typenow'] = $_GET['post_type'] = $_POST['post_type'] = $_REQUEST['post_type'] = $screen->post_type;
|
||||
}
|
||||
}
|
||||
|
||||
$GLOBALS['hook_suffix'] = $hook['path'];
|
||||
@@ -67,14 +160,17 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
|
||||
|
||||
$this->assertEquals( $screen->id, $current_screen->id, $hook_name );
|
||||
$this->assertEquals( $screen->base, $current_screen->base, $hook_name );
|
||||
if ( isset( $screen->action ) )
|
||||
if ( isset( $screen->action ) ) {
|
||||
$this->assertEquals( $screen->action, $current_screen->action, $hook_name );
|
||||
if ( isset( $screen->post_type ) )
|
||||
}
|
||||
if ( isset( $screen->post_type ) ) {
|
||||
$this->assertEquals( $screen->post_type, $current_screen->post_type, $hook_name );
|
||||
else
|
||||
} else {
|
||||
$this->assertEmpty( $current_screen->post_type, $hook_name );
|
||||
if ( isset( $screen->taxonomy ) )
|
||||
}
|
||||
if ( isset( $screen->taxonomy ) ) {
|
||||
$this->assertEquals( $screen->taxonomy, $current_screen->taxonomy, $hook_name );
|
||||
}
|
||||
|
||||
$this->assertTrue( $current_screen->in_admin() );
|
||||
$this->assertTrue( $current_screen->in_admin( 'site' ) );
|
||||
@@ -87,8 +183,9 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
|
||||
|
||||
// With convert_to_screen(), the hook_suffix should return the exact $current_screen.
|
||||
// But, convert_to_screen() cannot figure out ?taxonomy and ?post_type.
|
||||
if ( empty( $hook['query'] ) )
|
||||
if ( empty( $hook['query'] ) ) {
|
||||
$this->assertSame( $current_screen, convert_to_screen( $GLOBALS['hook_suffix'] ), $hook_name );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,23 +251,25 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
|
||||
}
|
||||
|
||||
function test_help_tabs() {
|
||||
$tab = __FUNCTION__;
|
||||
$tab = __FUNCTION__;
|
||||
$tab_args = array(
|
||||
'id' => $tab,
|
||||
'title' => 'Help!',
|
||||
'content' => 'Some content',
|
||||
'id' => $tab,
|
||||
'title' => 'Help!',
|
||||
'content' => 'Some content',
|
||||
'callback' => false,
|
||||
);
|
||||
|
||||
$screen = get_current_screen();
|
||||
$screen->add_help_tab( $tab_args );
|
||||
$this->assertEquals( $screen->get_help_tab( $tab ), array(
|
||||
'id' => $tab,
|
||||
'title' => 'Help!',
|
||||
'content' => 'Some content',
|
||||
'callback' => false,
|
||||
'priority' => 10,
|
||||
) );
|
||||
$this->assertEquals(
|
||||
$screen->get_help_tab( $tab ), array(
|
||||
'id' => $tab,
|
||||
'title' => 'Help!',
|
||||
'content' => 'Some content',
|
||||
'callback' => false,
|
||||
'priority' => 10,
|
||||
)
|
||||
);
|
||||
|
||||
$tabs = $screen->get_help_tabs();
|
||||
$this->assertArrayHasKey( $tab, $tabs );
|
||||
@@ -235,7 +334,7 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
|
||||
|
||||
$screen->add_help_tab( $tab_4_args );
|
||||
// Priority is added with the default for future calls
|
||||
$tab_4_args[ 'priority' ] = 10;
|
||||
$tab_4_args['priority'] = 10;
|
||||
$this->assertEquals( $screen->get_help_tab( $tab_4 ), $tab_4_args );
|
||||
|
||||
$tabs = $screen->get_help_tabs();
|
||||
@@ -247,12 +346,14 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
|
||||
|
||||
// Test priority order.
|
||||
|
||||
$this->assertSame( array(
|
||||
$tab_2 => $tab_2_args,
|
||||
$tab_1 => $tab_1_args,
|
||||
$tab_4 => $tab_4_args,
|
||||
$tab_3 => $tab_3_args,
|
||||
), $tabs );
|
||||
$this->assertSame(
|
||||
array(
|
||||
$tab_2 => $tab_2_args,
|
||||
$tab_1 => $tab_1_args,
|
||||
$tab_4 => $tab_4_args,
|
||||
$tab_3 => $tab_3_args,
|
||||
), $tabs
|
||||
);
|
||||
|
||||
$screen->remove_help_tab( $tab_1 );
|
||||
$this->assertNull( $screen->get_help_tab( $tab_1 ) );
|
||||
@@ -278,11 +379,11 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase {
|
||||
* @ticket 25799
|
||||
*/
|
||||
function test_options() {
|
||||
$option = __FUNCTION__;
|
||||
$option = __FUNCTION__;
|
||||
$option_args = array(
|
||||
'label' => 'Option',
|
||||
'default' => 10,
|
||||
'option' => $option
|
||||
'option' => $option,
|
||||
);
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
Reference in New Issue
Block a user