WordPress.org

Make WordPress Core

Ticket #28145: 28145.2.diff

File 28145.2.diff, 4.9 KB (added by MikeHansenMe, 7 years ago)

more tests

  • src/wp-admin/includes/template.php

     
    202202                ) );
    203203        }
    204204        if ( $descendants_and_self ) {
    205                 $categories = (array) get_terms( $taxonomy, array(
    206                         'child_of' => $descendants_and_self,
    207                         'hierarchical' => 0,
    208                         'hide_empty' => 0
    209                 ) );
     205               
     206                if( is_taxonomy_hierarchical( $taxonomy ) ) {
     207                        $categories = (array) get_terms( $taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
     208                } else {
     209                        $categories = array();
     210                }
     211               
    210212                $self = get_term( $descendants_and_self, $taxonomy );
    211213                array_unshift( $categories, $self );
    212214        } else {
  • tests/phpunit/tests/admin/includesTemplate.php

     
    33 * @group admin
    44 */
    55class Tests_Admin_includesTemplate extends WP_UnitTestCase {
     6
     7        function setUp() {
     8                parent::setUp();
     9
     10                register_taxonomy( 'testing-non-slug', array( 'post' ), array( 'labels' => array( 'name' => 'testing-non' ) ) );
     11                $this->non_id = wp_insert_term( 'testnon1', 'testing-non-slug' );
     12                wp_insert_term( 'testnon2', 'testing-non-slug' );
     13                wp_insert_term( 'testnon3', 'testing-non-slug' );
     14                wp_insert_term( 'testnon4', 'testing-non-slug' );
     15
     16                register_taxonomy( 'testing-h-slug', array( 'post' ), array( 'labels' => array( 'name' => 'testing-h', 'hierarchal' => true ) ) );
     17                $this->parent_id = wp_insert_term( 'testh1', 'testing-h-slug' );
     18                wp_insert_term( 'testh2', 'testing-h-slug', array( 'parent' => $this->parent_id['term_id'] ) );
     19                wp_insert_term( 'testh3', 'testing-h-slug', array( 'parent' => $this->parent_id['term_id'] ) );
     20                wp_insert_term( 'testh4', 'testing-h-slug', array( 'parent' => $this->parent_id['term_id'] ) );
     21        }
     22
    623        function test_equal() {
    724                $this->assertEquals(' selected=\'selected\'', selected('foo','foo',false));
    825                $this->assertEquals(' checked=\'checked\'', checked('foo','foo',false));
     
    4562                $this->assertEquals('', selected(0,false,false));
    4663                $this->assertEquals('', checked(0,false,false));
    4764        }
     65
     66        function test_wp_terms_checklist_decendants_and_self() {
     67                ob_start();
     68                wp_terms_checklist( 0, array( 'decendants_and_self' => 1 ) );
     69                $actual = ob_get_clean();
     70                $expected = "\n<li id='category-1'><label class=\"selectit\"><input value=\"1\" type=\"checkbox\" name=\"post_category[]\" id=\"in-category-1\" disabled='disabled' /> Uncategorized</label></li>\n";
     71                $this->assertSame( $actual, $expected );
     72        }
     73
     74        function test_wp_terms_checklist_decendants_and_self_non_hierarchal() {
     75                ob_start();
     76                wp_terms_checklist( 0, array( 'decendants_and_self' => $this->non_id, 'taxonomy' => 'testing-non-slug' ) );
     77                $actual = ob_get_clean();
     78                $expected = "\n" . '<li id=\'testing-non-slug-26\'><label class="selectit"><input value="26" type="checkbox" name="tax_input[testing-non-slug][]" id="in-testing-non-slug-26" disabled=\'disabled\' /> testnon1</label></li>
     79
     80<li id=\'testing-non-slug-27\'><label class="selectit"><input value="27" type="checkbox" name="tax_input[testing-non-slug][]" id="in-testing-non-slug-27" disabled=\'disabled\' /> testnon2</label></li>
     81
     82<li id=\'testing-non-slug-28\'><label class="selectit"><input value="28" type="checkbox" name="tax_input[testing-non-slug][]" id="in-testing-non-slug-28" disabled=\'disabled\' /> testnon3</label></li>
     83
     84<li id=\'testing-non-slug-29\'><label class="selectit"><input value="29" type="checkbox" name="tax_input[testing-non-slug][]" id="in-testing-non-slug-29" disabled=\'disabled\' /> testnon4</label></li>' . "\n";
     85                $this->assertSame( $actual, $expected );
     86        }
     87
     88        function test_wp_terms_checklist_decendants_and_self_hierarchal() {
     89                ob_start();
     90                wp_terms_checklist( 0, array( 'decendants_and_self' => $this->parent_id['term_id'], 'taxonomy' => 'testing-h-slug' ) );
     91                $actual = ob_get_clean();
     92                $expected = "\n" . '<li id=\'testing-h-slug-38\'><label class="selectit"><input value="38" type="checkbox" name="tax_input[testing-h-slug][]" id="in-testing-h-slug-38" disabled=\'disabled\' /> testh1</label><ul class=\'children\'>
     93
     94<li id=\'testing-h-slug-39\'><label class="selectit"><input value="39" type="checkbox" name="tax_input[testing-h-slug][]" id="in-testing-h-slug-39" disabled=\'disabled\' /> testh2</label></li>
     95
     96<li id=\'testing-h-slug-40\'><label class="selectit"><input value="40" type="checkbox" name="tax_input[testing-h-slug][]" id="in-testing-h-slug-40" disabled=\'disabled\' /> testh3</label></li>
     97
     98<li id=\'testing-h-slug-41\'><label class="selectit"><input value="41" type="checkbox" name="tax_input[testing-h-slug][]" id="in-testing-h-slug-41" disabled=\'disabled\' /> testh4</label></li>
     99</ul>
     100</li>' . "\n";
     101                $this->assertSame( $actual, $expected );
     102        }
    48103}