Help Tab Order should be based on the Priority Argument

[34370] made the order that tabs are returned respect the order they are added, however it broke the respect of priority. By using a ksort instead of a sort, we can restore that default behavior. This adjusts the unit tests so that both order added and priority are tested.

Props meitar,  swissspidy, jorbin
Fixes #35215. See #33941.


git-svn-id: https://develop.svn.wordpress.org/trunk@36089 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Aaron Jorbin 2015-12-25 22:43:41 +00:00
parent 2ce0bfa8f4
commit bc01ead655
2 changed files with 50 additions and 13 deletions

View File

@ -530,7 +530,7 @@ final class WP_Screen {
}
}
sort( $priorities );
ksort( $priorities );
$sorted = array();
foreach ( $priorities as $list ) {

View File

@ -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() );
}
/**