Make WordPress Core

Changeset 47747


Ignore:
Timestamp:
05/02/2020 10:34:50 PM (5 years ago)
Author:
johnbillion
Message:

Menus: Allow empty taxonomy terms to be surfaced when searching for items.

This brings the behaviour inline with that of browsing terms or using the All Items tab, which correctly shows empty terms.

Props birgire, audrasjb

Fixes #45298

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/nav-menu.php

    r47557 r47747  
    114114                    'name__like' => $query,
    115115                    'number'     => 10,
     116                    'hide_empty' => false,
    116117                )
    117118            );
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r47383 r47747  
    370370                'name__like' => $args['s'],
    371371                'number'     => 20,
     372                'hide_empty' => false,
    372373                'offset'     => 20 * ( $args['pagenum'] - 1 ),
    373374            )
  • trunk/tests/phpunit/tests/customize/nav-menus.php

    r46586 r47747  
    372372            )
    373373        );
    374         $this->assertEquals( 1, count( $results ) );
     374        $this->assertCount( 2, $results ); // Category terms Cats Drool and Uncategorized.
    375375        $count = $this->filter_count_customize_nav_menu_searched_items;
    376376        add_filter( 'customize_nav_menu_searched_items', array( $this, 'filter_search' ), 10, 2 );
     
    383383        $this->assertEquals( $count + 1, $this->filter_count_customize_nav_menu_searched_items );
    384384        $this->assertInternalType( 'array', $results );
    385         $this->assertEquals( 2, count( $results ) );
     385        $this->assertCount( 3, $results );
    386386        remove_filter( 'customize_nav_menu_searched_items', array( $this, 'filter_search' ), 10 );
    387387
     
    397397        $this->assertEquals( 'home', $results[0]['id'] );
    398398        $this->assertEquals( 'custom', $results[0]['type'] );
     399    }
     400
     401    /*
     402     * Tests that the search_available_items_query method should return term items
     403     * not assigned to any posts.
     404     *
     405     * @ticket 45298
     406     */
     407    public function test_search_available_items_query_should_return_unassigned_term_items() {
     408        $menus = new WP_Customize_Nav_Menus( $this->wp_customize );
     409
     410        register_taxonomy(
     411            'wptests_tax',
     412            'post',
     413            array(
     414                'labels' => array(
     415                    'name' => 'Tests Taxonomy',
     416                ),
     417            )
     418        );
     419
     420        $term_id = $this->factory->term->create(
     421            array(
     422                'taxonomy' => 'wptests_tax',
     423                'name'     => 'foobar',
     424            )
     425        );
     426
     427        // Expected menu item array.
     428        $expected = array(
     429            'title'      => 'foobar',
     430            'id'         => "term-{$term_id}",
     431            'type'       => 'taxonomy',
     432            'type_label' => 'Tests Taxonomy',
     433            'object'     => 'wptests_tax',
     434            'object_id'  => intval( $term_id ),
     435            'url'        => get_term_link( intval( $term_id ), '' ),
     436        );
     437
     438        $results = $menus->search_available_items_query(
     439            array(
     440                'pagenum' => 1,
     441                's'       => 'foo',
     442            )
     443        );
     444
     445        $this->assertEqualSets( $expected, $results[0] );
    399446    }
    400447
  • trunk/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php

    r47200 r47747  
    121121        $this->assertCount( 1, $results );
    122122    }
     123
     124    /**
     125     * Test that search displays terms that are not assigned to any posts.
     126     *
     127     * @ticket 45298
     128     */
     129    public function test_search_should_return_unassigned_term_items() {
     130        register_taxonomy( 'wptests_tax', 'post' );
     131
     132        $this->factory->term->create(
     133            array(
     134                'taxonomy' => 'wptests_tax',
     135                'name'     => 'foobar',
     136            )
     137        );
     138
     139        $request = array(
     140            'type' => 'quick-search-taxonomy-wptests_tax',
     141            'q'    => 'foobar',
     142        );
     143        $output  = get_echo( '_wp_ajax_menu_quick_search', array( $request ) );
     144
     145        $this->assertNotEmpty( $output );
     146        $results = explode( "\n", trim( $output ) );
     147        $this->assertCount( 1, $results );
     148    }
    123149}
Note: See TracChangeset for help on using the changeset viewer.