Make WordPress Core


Ignore:
Timestamp:
10/10/2020 08:38:49 PM (6 years ago)
Author:
johnbillion
Message:

Administration: Allow context and priority to be specified when adding dashboard widgets.

Props davidjlaietta, soulseekah, johnbillion

Fixes #42791

File:
1 edited

Legend:

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

    r48939 r49123  
    202202        }
    203203
     204        /**
     205         * @ticket 42791
     206         */
     207        public function test_wp_add_dashboard_widget() {
     208                global $wp_meta_boxes;
     209
     210                set_current_screen( 'dashboard' );
     211
     212                if ( ! function_exists( 'wp_add_dashboard_widget' ) ) {
     213                        require_once ABSPATH . 'wp-admin/includes/dashboard.php';
     214                }
     215
     216                // Some hardcoded defaults for core widgets
     217                wp_add_dashboard_widget( 'dashboard_quick_press', 'Quick', '__return_false' );
     218                wp_add_dashboard_widget( 'dashboard_browser_nag', 'Nag', '__return_false' );
     219
     220                $this->assertArrayHasKey( 'dashboard_quick_press', $wp_meta_boxes['dashboard']['side']['core'] );
     221                $this->assertArrayHasKey( 'dashboard_browser_nag', $wp_meta_boxes['dashboard']['normal']['high'] );
     222
     223                // Location and priority defaults
     224                wp_add_dashboard_widget( 'dashboard1', 'Widget 1', '__return_false', null, null, 'foo' );
     225                wp_add_dashboard_widget( 'dashboard2', 'Widget 2', '__return_false', null, null, null, 'bar' );
     226
     227                $this->assertArrayHasKey( 'dashboard1', $wp_meta_boxes['dashboard']['foo']['core'] );
     228                $this->assertArrayHasKey( 'dashboard2', $wp_meta_boxes['dashboard']['normal']['bar'] );
     229
     230                // Cleanup
     231                remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
     232                remove_meta_box( 'dashboard_browser_nag', 'dashboard', 'normal' );
     233                remove_meta_box( 'dashboard1', 'dashboard', 'foo' );
     234
     235                // This doesn't actually get removed due to the invalid priority
     236                remove_meta_box( 'dashboard2', 'dashboard', 'normal' );
     237
     238                set_current_screen( 'front' );
     239        }
     240
    204241}
Note: See TracChangeset for help on using the changeset viewer.