mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Eliminate use of extract() in wp_dropdown_pages().
Adds unit tests to: `tests/post/template.php`. There was previously only one wimpy assertion for `wp_dropdown_pages()`. See #22400. git-svn-id: https://develop.svn.wordpress.org/trunk@28399 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -164,7 +164,7 @@ class Tests_Post_getPages extends WP_UnitTestCase {
|
||||
* @ticket 22389
|
||||
*/
|
||||
function test_wp_dropdown_pages() {
|
||||
$posts = $this->factory->post->create_many( 5, array( 'post_type' => 'page' ) );
|
||||
$this->factory->post->create_many( 5, array( 'post_type' => 'page' ) );
|
||||
|
||||
preg_match_all( '#<option#', wp_dropdown_pages( 'echo=0' ), $matches );
|
||||
|
||||
|
||||
@@ -72,4 +72,63 @@ class Tests_Post_Template extends WP_UnitTestCase {
|
||||
|
||||
$this->assertEquals( $pagelink, $output );
|
||||
}
|
||||
|
||||
function test_wp_dropdown_pages() {
|
||||
$none = wp_dropdown_pages( array( 'echo' => 0 ) );
|
||||
$this->assertEmpty( $none );
|
||||
|
||||
$bump = ' ';
|
||||
$page_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
|
||||
$child_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id ) );
|
||||
$grandchild_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $child_id ) );
|
||||
|
||||
$lineage =<<<LINEAGE
|
||||
<select name='page_id' id='page_id'>
|
||||
<option class="level-0" value="$page_id">Post title 1</option>
|
||||
<option class="level-1" value="$child_id">{$bump}Post title 2</option>
|
||||
<option class="level-2" value="$grandchild_id">{$bump}{$bump}Post title 3</option>
|
||||
</select>
|
||||
|
||||
LINEAGE;
|
||||
|
||||
$output = wp_dropdown_pages( array( 'echo' => 0 ) );
|
||||
$this->assertEquals( $lineage, $output );
|
||||
|
||||
$depth =<<<DEPTH
|
||||
<select name='page_id' id='page_id'>
|
||||
<option class="level-0" value="$page_id">Post title 1</option>
|
||||
</select>
|
||||
|
||||
DEPTH;
|
||||
|
||||
$output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1 ) );
|
||||
$this->assertEquals( $depth, $output );
|
||||
|
||||
$option_none =<<<NONE
|
||||
<select name='page_id' id='page_id'>
|
||||
<option value="Woo">Hoo</option>
|
||||
<option class="level-0" value="$page_id">Post title 1</option>
|
||||
</select>
|
||||
|
||||
NONE;
|
||||
|
||||
$output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1,
|
||||
'show_option_none' => 'Hoo', 'option_none_value' => 'Woo'
|
||||
) );
|
||||
$this->assertEquals( $option_none, $output );
|
||||
|
||||
$option_no_change =<<<NO
|
||||
<select name='page_id' id='page_id'>
|
||||
<option value="-1">Burrito</option>
|
||||
<option value="Woo">Hoo</option>
|
||||
<option class="level-0" value="$page_id">Post title 1</option>
|
||||
</select>
|
||||
|
||||
NO;
|
||||
$output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1,
|
||||
'show_option_none' => 'Hoo', 'option_none_value' => 'Woo',
|
||||
'show_option_no_change' => 'Burrito'
|
||||
) );
|
||||
$this->assertEquals( $option_no_change, $output );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user