Make WordPress Core


Ignore:
Timestamp:
09/10/2015 01:26:26 AM (10 years ago)
Author:
wonderboymusic
Message:

Implement a priority system for Help Tabs to add them at specific positions.

Adds unit tests.

Props swissspidy.
Fixes #19828.

File:
1 edited

Legend:

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

    r31622 r33985  
    164164        $screen = get_current_screen();
    165165        $screen->add_help_tab( $tab_args );
    166         $this->assertEquals( $screen->get_help_tab( $tab ), $tab_args );
     166        $this->assertEquals( $screen->get_help_tab( $tab ), array(
     167            'id' => $tab,
     168            'title' => 'Help!',
     169            'content' => 'Some content',
     170            'callback' => false,
     171            'priority' => 10,
     172        ) );
    167173
    168174        $tabs = $screen->get_help_tabs();
     
    171177        $screen->remove_help_tab( $tab );
    172178        $this->assertNull( $screen->get_help_tab( $tab ) );
     179
     180        $screen->remove_help_tabs();
     181        $this->assertEquals( $screen->get_help_tabs(), array() );
     182    }
     183
     184    /**
     185     * @ticket 19828
     186     */
     187    function test_help_tabs_priority() {
     188        $tab_1      = rand_str();
     189        $tab_1_args = array(
     190            'id'       => $tab_1,
     191            'title'    => 'Help!',
     192            'content'  => 'Some content',
     193            'callback' => false,
     194            'priority' => 11,
     195        );
     196
     197        $tab_2      = rand_str();
     198        $tab_2_args = array(
     199            'id'       => $tab_2,
     200            'title'    => 'Help!',
     201            'content'  => 'Some content',
     202            'callback' => false,
     203            'priority' => 9,
     204        );
     205
     206        $screen = get_current_screen();
     207
     208        // Add help tabs.
     209
     210        $screen->add_help_tab( $tab_1_args );
     211        $this->assertEquals( $screen->get_help_tab( $tab_1 ), $tab_1_args );
     212
     213        $screen->add_help_tab( $tab_2_args );
     214        $this->assertEquals( $screen->get_help_tab( $tab_2 ), $tab_2_args );
     215
     216        $tabs = $screen->get_help_tabs();
     217        $this->assertEquals( 2, count( $tabs ) );
     218        $this->assertArrayHasKey( $tab_1, $tabs );
     219        $this->assertArrayHasKey( $tab_2, $tabs );
     220
     221        // Test priority order.
     222
     223        $this->assertEquals( $tabs, array(
     224            $tab_2 => $tab_2_args,
     225            $tab_1 => $tab_1_args,
     226        ) );
     227
     228        $screen->remove_help_tab( $tab_1 );
     229        $this->assertNull( $screen->get_help_tab( $tab_1 ) );
     230        $this->assertEquals( 1, count( $screen->get_help_tabs() ) );
     231
     232        $screen->remove_help_tab( $tab_2 );
     233        $this->assertNull( $screen->get_help_tab( $tab_2 ) );
     234        $this->assertEquals( 0, count( $screen->get_help_tabs() ) );
    173235
    174236        $screen->remove_help_tabs();
Note: See TracChangeset for help on using the changeset viewer.