Make WordPress Core


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.