Make WordPress Core


Ignore:
Timestamp:
05/15/2014 01:11:21 AM (11 years ago)
Author:
wonderboymusic
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/template.php

    r28398 r28399  
    7373        $this->assertEquals( $pagelink, $output );
    7474    }
     75
     76    function test_wp_dropdown_pages() {
     77        $none = wp_dropdown_pages( array( 'echo' => 0 ) );
     78        $this->assertEmpty( $none );
     79
     80        $bump = '   ';
     81        $page_id = $this->factory->post->create( array( 'post_type' => 'page' ) );
     82        $child_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $page_id ) );
     83        $grandchild_id = $this->factory->post->create( array( 'post_type' => 'page', 'post_parent' => $child_id ) );
     84
     85        $lineage =<<<LINEAGE
     86<select name='page_id' id='page_id'>
     87    <option class="level-0" value="$page_id">Post title 1</option>
     88    <option class="level-1" value="$child_id">{$bump}Post title 2</option>
     89    <option class="level-2" value="$grandchild_id">{$bump}{$bump}Post title 3</option>
     90</select>
     91
     92LINEAGE;
     93
     94        $output = wp_dropdown_pages( array( 'echo' => 0 ) );
     95        $this->assertEquals( $lineage, $output );
     96
     97        $depth =<<<DEPTH
     98<select name='page_id' id='page_id'>
     99    <option class="level-0" value="$page_id">Post title 1</option>
     100</select>
     101
     102DEPTH;
     103
     104        $output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1 ) );
     105        $this->assertEquals( $depth, $output );
     106
     107        $option_none =<<<NONE
     108<select name='page_id' id='page_id'>
     109    <option value="Woo">Hoo</option>
     110    <option class="level-0" value="$page_id">Post title 1</option>
     111</select>
     112
     113NONE;
     114
     115        $output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1,
     116            'show_option_none' => 'Hoo', 'option_none_value' => 'Woo'
     117        ) );
     118        $this->assertEquals( $option_none, $output );
     119
     120        $option_no_change =<<<NO
     121<select name='page_id' id='page_id'>
     122    <option value="-1">Burrito</option>
     123    <option value="Woo">Hoo</option>
     124    <option class="level-0" value="$page_id">Post title 1</option>
     125</select>
     126
     127NO;
     128        $output = wp_dropdown_pages( array( 'echo' => 0, 'depth' => 1,
     129            'show_option_none' => 'Hoo', 'option_none_value' => 'Woo',
     130            'show_option_no_change' => 'Burrito'
     131        ) );
     132        $this->assertEquals( $option_no_change, $output );
     133    }
    75134}
Note: See TracChangeset for help on using the changeset viewer.