diff --git a/src/wp-admin/includes/class-wp-screen.php b/src/wp-admin/includes/class-wp-screen.php index 25373191ba..c7b35a49ad 100644 --- a/src/wp-admin/includes/class-wp-screen.php +++ b/src/wp-admin/includes/class-wp-screen.php @@ -530,7 +530,7 @@ final class WP_Screen { } } - sort( $priorities ); + ksort( $priorities ); $sorted = array(); foreach ( $priorities as $list ) { diff --git a/tests/phpunit/tests/admin/includesScreen.php b/tests/phpunit/tests/admin/includesScreen.php index 65603e315d..1805d2db03 100644 --- a/tests/phpunit/tests/admin/includesScreen.php +++ b/tests/phpunit/tests/admin/includesScreen.php @@ -2,6 +2,7 @@ /** * @group admin + * @group adminScreen */ class Tests_Admin_includesScreen extends WP_UnitTestCase { var $core_screens = array( @@ -187,54 +188,90 @@ class Tests_Admin_includesScreen extends WP_UnitTestCase { function test_help_tabs_priority() { $tab_1 = rand_str(); $tab_1_args = array( - 'id' => $tab_1, 'title' => 'Help!', + 'id' => $tab_1, 'content' => 'Some content', 'callback' => false, - 'priority' => 11, + 'priority' => 10, ); $tab_2 = rand_str(); $tab_2_args = array( - 'id' => $tab_2, 'title' => 'Help!', + 'id' => $tab_2, 'content' => 'Some content', 'callback' => false, - 'priority' => 9, + 'priority' => 2, + ); + $tab_3 = rand_str(); + $tab_3_args = array( + 'title' => 'help!', + 'id' => $tab_3, + 'content' => 'some content', + 'callback' => false, + 'priority' => 40, + ); + $tab_4 = rand_str(); + $tab_4_args = array( + 'title' => 'help!', + 'id' => $tab_4, + 'content' => 'some content', + 'callback' => false, + // Don't include a priority ); $screen = get_current_screen(); - // Add help tabs. + // add help tabs. $screen->add_help_tab( $tab_1_args ); - $this->assertEquals( $screen->get_help_tab( $tab_1 ), $tab_1_args ); + $this->assertequals( $screen->get_help_tab( $tab_1 ), $tab_1_args ); $screen->add_help_tab( $tab_2_args ); $this->assertEquals( $screen->get_help_tab( $tab_2 ), $tab_2_args ); + $screen->add_help_tab( $tab_3_args ); + $this->assertEquals( $screen->get_help_tab( $tab_3 ), $tab_3_args ); + + $screen->add_help_tab( $tab_4_args ); + // Priority is added with the default for future calls + $tab_4_args[ 'priority' ] = 10; + $this->assertEquals( $screen->get_help_tab( $tab_4 ), $tab_4_args ); + $tabs = $screen->get_help_tabs(); - $this->assertEquals( 2, count( $tabs ) ); + $this->assertEquals( 4, count( $tabs ) ); $this->assertArrayHasKey( $tab_1, $tabs ); $this->assertArrayHasKey( $tab_2, $tabs ); + $this->assertArrayHasKey( $tab_3, $tabs ); + $this->assertArrayHasKey( $tab_4, $tabs ); // Test priority order. - $this->assertEquals( $tabs, array( + $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 ) ); - $this->assertEquals( 1, count( $screen->get_help_tabs() ) ); + $this->assertSame( 3, count( $screen->get_help_tabs() ) ); $screen->remove_help_tab( $tab_2 ); $this->assertNull( $screen->get_help_tab( $tab_2 ) ); - $this->assertEquals( 0, count( $screen->get_help_tabs() ) ); + $this->assertSame( 2, count( $screen->get_help_tabs() ) ); + + $screen->remove_help_tab( $tab_3 ); + $this->assertNull( $screen->get_help_tab( $tab_3 ) ); + $this->assertSame( 1, count( $screen->get_help_tabs() ) ); + + $screen->remove_help_tab( $tab_4 ); + $this->assertNull( $screen->get_help_tab( $tab_4 ) ); + $this->assertSame( 0, count( $screen->get_help_tabs() ) ); $screen->remove_help_tabs(); - $this->assertEquals( $screen->get_help_tabs(), array() ); + $this->assertEquals( array(), $screen->get_help_tabs() ); } /**