Make WordPress Core


Ignore:
Timestamp:
08/27/2020 02:46:22 AM (3 years ago)
Author:
SergeyBiryukov
Message:

Taxonomy: Make sure wp_terms_checklist() and Walker_Category_Checklist::start_el() properly handle an array of strings as selected_cats or popular_cats values.

Even with these values documented as an array of integers, they can technically also accept an array of strings, e.g. as form results.

Add a unit test.

Props brianhogg, TimothyBlynJacobs, SergeyBiryukov.
Fixes #51137.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesTemplate.php

    r48858 r48880  
    44 */
    55class Tests_Admin_includesTemplate extends WP_UnitTestCase {
     6
    67    function test_equal() {
    78        $this->assertEquals( ' selected=\'selected\'', selected( 'foo', 'foo', false ) );
     
    4546        $this->assertEquals( '', selected( 0, false, false ) );
    4647        $this->assertEquals( '', checked( 0, false, false ) );
     48    }
     49
     50    /**
     51     * @ticket 51147
     52     * @dataProvider data_wp_terms_checklist_with_selected_cats
     53     */
     54    public function test_wp_terms_checklist_with_selected_cats( $term_id ) {
     55        $output = wp_terms_checklist(
     56            0,
     57            array(
     58                'selected_cats' => array( $term_id ),
     59                'echo'          => false,
     60            )
     61        );
     62
     63        $this->assertContains( "checked='checked'", $output );
     64    }
     65
     66    /**
     67     * @ticket 51147
     68     * @dataProvider data_wp_terms_checklist_with_selected_cats
     69     */
     70    public function test_wp_terms_checklist_with_popular_cats( $term_id ) {
     71        $output = wp_terms_checklist(
     72            0,
     73            array(
     74                'popular_cats' => array( $term_id ),
     75                'echo'         => false,
     76            )
     77        );
     78
     79        $this->assertContains( 'class="popular-category"', $output );
     80    }
     81
     82    public function data_wp_terms_checklist_with_selected_cats() {
     83        return array(
     84            array( '1' ),
     85            array( 1 ),
     86        );
    4787    }
    4888
Note: See TracChangeset for help on using the changeset viewer.