WordPress.org

Make WordPress Core

Ticket #28145: 28145.3.diff

File 28145.3.diff, 4.9 KB (added by MikeHansenMe, 6 years ago)
  • src/wp-admin/includes/template.php

     
    134134                ) );
    135135        }
    136136        if ( $descendants_and_self ) {
    137                 $categories = (array) get_terms( $taxonomy, array(
    138                         'child_of' => $descendants_and_self,
    139                         'hierarchical' => 0,
    140                         'hide_empty' => 0
    141                 ) );
     137                if( is_taxonomy_hierarchical( $taxonomy ) ) {
     138                        $categories = (array) get_terms( $taxonomy, array( 'child_of' => $descendants_and_self, 'hierarchical' => 0, 'hide_empty' => 0 ) );
     139                } else {
     140                        $categories = array();
     141                }
    142142                $self = get_term( $descendants_and_self, $taxonomy );
    143143                array_unshift( $categories, $self );
    144144        } 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));
     
    108125                $this->assertFalse( $wp_meta_boxes['attachment']['advanced']['default']['testbox1'] );
    109126        }
    110127
     128        function test_wp_terms_checklist_decendants_and_self() {
     129                ob_start();
     130                wp_terms_checklist( 0, array( 'decendants_and_self' => 1 ) );
     131                $actual = ob_get_clean();
     132                $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";
     133                $this->assertSame( $actual, $expected );
     134        }
     135
     136        function test_wp_terms_checklist_decendants_and_self_non_hierarchal() {
     137                ob_start();
     138                wp_terms_checklist( 0, array( 'decendants_and_self' => $this->non_id, 'taxonomy' => 'testing-non-slug' ) );
     139                $actual = ob_get_clean();
     140                $expected = "\n" . '<li id=\'testing-non-slug-62\'><label class="selectit"><input value="62" type="checkbox" name="tax_input[testing-non-slug][]" id="in-testing-non-slug-62" disabled=\'disabled\' /> testnon1</label></li>
     141
     142<li id=\'testing-non-slug-63\'><label class="selectit"><input value="63" type="checkbox" name="tax_input[testing-non-slug][]" id="in-testing-non-slug-63" disabled=\'disabled\' /> testnon2</label></li>
     143
     144<li id=\'testing-non-slug-64\'><label class="selectit"><input value="64" type="checkbox" name="tax_input[testing-non-slug][]" id="in-testing-non-slug-64" disabled=\'disabled\' /> testnon3</label></li>
     145
     146<li id=\'testing-non-slug-65\'><label class="selectit"><input value="65" type="checkbox" name="tax_input[testing-non-slug][]" id="in-testing-non-slug-65" disabled=\'disabled\' /> testnon4</label></li>' . "\n";
     147                $this->assertSame( $actual, $expected );
     148        }
     149
     150        function test_wp_terms_checklist_decendants_and_self_hierarchal() {
     151                ob_start();
     152                wp_terms_checklist( 0, array( 'decendants_and_self' => $this->parent_id['term_id'], 'taxonomy' => 'testing-h-slug' ) );
     153                $actual = ob_get_clean();
     154                $expected = "\n" . '<li id=\'testing-h-slug-74\'><label class="selectit"><input value="74" type="checkbox" name="tax_input[testing-h-slug][]" id="in-testing-h-slug-74" disabled=\'disabled\' /> testh1</label><ul class=\'children\'>
     155
     156<li id=\'testing-h-slug-75\'><label class="selectit"><input value="75" type="checkbox" name="tax_input[testing-h-slug][]" id="in-testing-h-slug-75" disabled=\'disabled\' /> testh2</label></li>
     157
     158<li id=\'testing-h-slug-76\'><label class="selectit"><input value="76" type="checkbox" name="tax_input[testing-h-slug][]" id="in-testing-h-slug-76" disabled=\'disabled\' /> testh3</label></li>
     159
     160<li id=\'testing-h-slug-77\'><label class="selectit"><input value="77" type="checkbox" name="tax_input[testing-h-slug][]" id="in-testing-h-slug-77" disabled=\'disabled\' /> testh4</label></li>
     161</ul>
     162</li>' . "\n";
     163                $this->assertSame( $actual, $expected );
     164        }
     165
    111166}