Make WordPress Core

Changeset 36104


Ignore:
Timestamp:
12/27/2015 02:13:20 AM (8 years ago)
Author:
dd32
Message:

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.

Merges [36089] to the 4.4 branch.
Props meitar, swissspidy, jorbin
Fixes #35215. See #33941.

Location:
branches/4.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.4

  • branches/4.4/src/wp-admin/includes/class-wp-screen.php

    r35461 r36104  
    531531        }
    532532
    533         sort( $priorities );
     533        ksort( $priorities );
    534534
    535535        $sorted = array();
  • branches/4.4/tests/phpunit/tests/admin/includesScreen.php

    r34370 r36104  
    33/**
    44 * @group admin
     5 * @group adminScreen
    56 */
    67class Tests_Admin_includesScreen extends WP_UnitTestCase {
     
    188189        $tab_1      = rand_str();
    189190        $tab_1_args = array(
     191            'title'    => 'Help!',
    190192            'id'       => $tab_1,
    191             'title'    => 'Help!',
    192193            'content'  => 'Some content',
    193194            'callback' => false,
    194             'priority' => 11,
     195            'priority' => 10,
    195196        );
    196197
    197198        $tab_2      = rand_str();
    198199        $tab_2_args = array(
     200            'title'    => 'Help!',
    199201            'id'       => $tab_2,
    200             'title'    => 'Help!',
    201202            'content'  => 'Some content',
    202203            'callback' => false,
    203             'priority' => 9,
     204            'priority' => 2,
     205        );
     206        $tab_3      = rand_str();
     207        $tab_3_args = array(
     208            'title'    => 'help!',
     209            'id'       => $tab_3,
     210            'content'  => 'some content',
     211            'callback' => false,
     212            'priority' => 40,
     213        );
     214        $tab_4      = rand_str();
     215        $tab_4_args = array(
     216            'title'    => 'help!',
     217            'id'       => $tab_4,
     218            'content'  => 'some content',
     219            'callback' => false,
     220            // Don't include a priority
    204221        );
    205222
    206223        $screen = get_current_screen();
    207224
    208         // Add help tabs.
     225        // add help tabs.
    209226
    210227        $screen->add_help_tab( $tab_1_args );
    211         $this->assertEquals( $screen->get_help_tab( $tab_1 ), $tab_1_args );
     228        $this->assertequals( $screen->get_help_tab( $tab_1 ), $tab_1_args );
    212229
    213230        $screen->add_help_tab( $tab_2_args );
    214231        $this->assertEquals( $screen->get_help_tab( $tab_2 ), $tab_2_args );
    215232
     233        $screen->add_help_tab( $tab_3_args );
     234        $this->assertEquals( $screen->get_help_tab( $tab_3 ), $tab_3_args );
     235
     236        $screen->add_help_tab( $tab_4_args );
     237        // Priority is added with the default for future calls
     238        $tab_4_args[ 'priority' ] = 10;
     239        $this->assertEquals( $screen->get_help_tab( $tab_4 ), $tab_4_args );
     240
    216241        $tabs = $screen->get_help_tabs();
    217         $this->assertEquals( 2, count( $tabs ) );
     242        $this->assertEquals( 4, count( $tabs ) );
    218243        $this->assertArrayHasKey( $tab_1, $tabs );
    219244        $this->assertArrayHasKey( $tab_2, $tabs );
     245        $this->assertArrayHasKey( $tab_3, $tabs );
     246        $this->assertArrayHasKey( $tab_4, $tabs );
    220247
    221248        // Test priority order.
    222249
    223         $this->assertEquals( $tabs, array(
     250        $this->assertSame( array(
    224251            $tab_2 => $tab_2_args,
    225252            $tab_1 => $tab_1_args,
    226         ) );
     253            $tab_4 => $tab_4_args,
     254            $tab_3 => $tab_3_args,
     255        ), $tabs );
    227256
    228257        $screen->remove_help_tab( $tab_1 );
    229258        $this->assertNull( $screen->get_help_tab( $tab_1 ) );
    230         $this->assertEquals( 1, count( $screen->get_help_tabs() ) );
     259        $this->assertSame( 3, count( $screen->get_help_tabs() ) );
    231260
    232261        $screen->remove_help_tab( $tab_2 );
    233262        $this->assertNull( $screen->get_help_tab( $tab_2 ) );
    234         $this->assertEquals( 0, count( $screen->get_help_tabs() ) );
     263        $this->assertSame( 2, count( $screen->get_help_tabs() ) );
     264
     265        $screen->remove_help_tab( $tab_3 );
     266        $this->assertNull( $screen->get_help_tab( $tab_3 ) );
     267        $this->assertSame( 1, count( $screen->get_help_tabs() ) );
     268
     269        $screen->remove_help_tab( $tab_4 );
     270        $this->assertNull( $screen->get_help_tab( $tab_4 ) );
     271        $this->assertSame( 0, count( $screen->get_help_tabs() ) );
    235272
    236273        $screen->remove_help_tabs();
    237         $this->assertEquals( $screen->get_help_tabs(), array() );
     274        $this->assertEquals( array(), $screen->get_help_tabs() );
    238275    }
    239276
Note: See TracChangeset for help on using the changeset viewer.