Make WordPress Core


Ignore:
Timestamp:
08/27/2020 03:06:22 AM (6 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.
Merges [48880] to the 5.5 branch.
Fixes #51137.

Location:
branches/5.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.5

  • branches/5.5/tests/phpunit/tests/admin/includesTemplate.php

    r47777 r48882  
    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.