Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/phpunit/tests/functions/wpMaybeLoadWidgets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Tests for wp_maybe_load_widgets function.
*
* @group functions.php
*
* @covers ::wp_maybe_load_widgets
*/
class Tests_Functions_WpMaybeLoadWidgets extends WP_UnitTestCase {

/**
* @ticket 57201
*/
public function test_wp_maybe_load_widgets() {
// If the class already exists, we can't test the initial "not loaded" state.
if ( ! class_exists( 'WP_Nav_Menu_Widget' ) ) {
$this->assertFalse( class_exists( 'WP_Nav_Menu_Widget' ), 'WP_Nav_Menu_Widget class should not be loaded initially.' );
$this->assertFalse( has_action( '_admin_menu', 'wp_widgets_add_menu' ), 'wp_widgets_add_menu should not be hooked to _admin_menu initially.' );

add_filter( 'load_default_widgets', '__return_false' );
wp_maybe_load_widgets();
remove_filter( 'load_default_widgets', '__return_false' );

$this->assertFalse( class_exists( 'WP_Nav_Menu_Widget' ), 'WP_Nav_Menu_Widget class should not be loaded when load_default_widgets filter returns false.' );
$this->assertFalse( has_action( '_admin_menu', 'wp_widgets_add_menu' ), 'wp_widgets_add_menu should not be hooked to _admin_menu when load_default_widgets filter returns false.' );
}

wp_maybe_load_widgets();

$this->assertTrue( class_exists( 'WP_Nav_Menu_Widget' ), 'WP_Nav_Menu_Widget class should be loaded.' );
$this->assertNotFalse( has_action( '_admin_menu', 'wp_widgets_add_menu' ), 'wp_widgets_add_menu should be hooked to _admin_menu.' );
}
}
Loading