mirror of
git://develop.git.wordpress.org/
synced 2025-04-23 05:32:41 +02:00
Widgets: Add tests for dynamic_sidebar()
where sidebars were registered with 1) no supplied ID, 2) a numeric ID, 3) a string ID.
See #17078. git-svn-id: https://develop.svn.wordpress.org/trunk@34816 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
1c44c6011e
commit
572fd0a45b
@ -92,6 +92,62 @@ class Tests_Widgets extends WP_UnitTestCase {
|
||||
$this->assertArrayNotHasKey( 'wp-unit-test', $wp_registered_sidebars );
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility hook callback used to store a sidebar ID mid-function.
|
||||
*/
|
||||
function retrieve_sidebar_id( $index ) {
|
||||
$this->sidebar_index = $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group sidebar
|
||||
*/
|
||||
function test_dynamic_sidebar_using_sidebar_registered_with_no_id() {
|
||||
global $wp_registered_sidebars;
|
||||
|
||||
$this->setExpectedIncorrectUsage( 'register_sidebar' );
|
||||
|
||||
// Register a couple of sidebars for fun.
|
||||
register_sidebar();
|
||||
register_sidebar();
|
||||
|
||||
$derived_sidebar_id = "sidebar-3"; // Number of sidebars in the global + 1.
|
||||
|
||||
add_action( 'dynamic_sidebar_before', array( $this, 'retrieve_sidebar_id' ) );
|
||||
|
||||
dynamic_sidebar( 3 );
|
||||
|
||||
$this->assertSame( $derived_sidebar_id, $this->sidebar_index );
|
||||
}
|
||||
|
||||
/**
|
||||
* @group sidebar
|
||||
*/
|
||||
function test_dynamic_sidebar_numeric_id() {
|
||||
$sidebar_id = 2;
|
||||
register_sidebar( array( 'id' => $sidebar_id ) );
|
||||
|
||||
add_action( 'dynamic_sidebar_before', array( $this, 'retrieve_sidebar_id' ) );
|
||||
|
||||
dynamic_sidebar( $sidebar_id );
|
||||
|
||||
$this->assertSame( "sidebar-{$sidebar_id}", $this->sidebar_index );
|
||||
}
|
||||
|
||||
/**
|
||||
* @group sidebar
|
||||
*/
|
||||
function test_dynamic_sidebar_string_id() {
|
||||
$sidebar_id = 'wp-unit-tests';
|
||||
register_sidebar( array( 'id' => $sidebar_id ) );
|
||||
|
||||
add_action( 'dynamic_sidebar_before', array( $this, 'retrieve_sidebar_id' ) );
|
||||
|
||||
dynamic_sidebar( $sidebar_id );
|
||||
|
||||
$this->assertSame( $sidebar_id, $this->sidebar_index );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see WP_Widget_Search::form()
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user