Ticket #45298: 45298.3.diff
| File 45298.3.diff, 4.4 KB (added by , 6 years ago) |
|---|
-
src/wp-admin/includes/nav-menu.php
diff --git a/src/wp-admin/includes/nav-menu.php b/src/wp-admin/includes/nav-menu.php index 64dda1db61..3cd7f53459 100644
a b function _wp_ajax_menu_quick_search( $request = array() ) { 113 113 'taxonomy' => $matches[2], 114 114 'name__like' => $query, 115 115 'number' => 10, 116 'hide_empty' => false, 116 117 ) 117 118 ); 118 119 if ( empty( $terms ) || is_wp_error( $terms ) ) { -
src/wp-includes/class-wp-customize-nav-menus.php
diff --git a/src/wp-includes/class-wp-customize-nav-menus.php b/src/wp-includes/class-wp-customize-nav-menus.php index 1b44b1453d..8abb6a9b5d 100644
a b final class WP_Customize_Nav_Menus { 369 369 'taxonomies' => $taxonomies, 370 370 'name__like' => $args['s'], 371 371 'number' => 20, 372 'hide_empty' => false, 372 373 'offset' => 20 * ( $args['pagenum'] - 1 ), 373 374 ) 374 375 ); -
tests/phpunit/tests/customize/nav-menus.php
diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php index 1de6047097..5fb6eda1bb 100644
a b class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { 371 371 's' => 'cat', 372 372 ) 373 373 ); 374 $this->assert Equals( 1, count( $results ) );374 $this->assertCount( 2, $results ); // Category terms Cats Drool and Uncategorized. 375 375 $count = $this->filter_count_customize_nav_menu_searched_items; 376 376 add_filter( 'customize_nav_menu_searched_items', array( $this, 'filter_search' ), 10, 2 ); 377 377 $results = $menus->search_available_items_query( … … class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { 382 382 ); 383 383 $this->assertEquals( $count + 1, $this->filter_count_customize_nav_menu_searched_items ); 384 384 $this->assertInternalType( 'array', $results ); 385 $this->assert Equals( 2, count( $results ));385 $this->assertCount( 3, $results ); 386 386 remove_filter( 'customize_nav_menu_searched_items', array( $this, 'filter_search' ), 10 ); 387 387 388 388 // Test home. … … class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { 398 398 $this->assertEquals( 'custom', $results[0]['type'] ); 399 399 } 400 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( 'wptests_tax', 'post', 411 array( 412 'labels' => array( 413 'name' => 'Tests Taxonomy', 414 ), 415 ) 416 ); 417 418 $term_id = $this->factory->term->create( 419 array( 420 'taxonomy' => 'wptests_tax', 421 'name' => 'foobar', 422 ) 423 ); 424 425 // Expected menu item array. 426 $expected = array( 427 'title' => 'foobar', 428 'id' => "term-{$term_id}", 429 'type' => 'taxonomy', 430 'type_label' => 'Tests Taxonomy', 431 'object' => 'wptests_tax', 432 'object_id' => intval( $term_id ), 433 'url' => get_term_link( intval( $term_id ), '' ), 434 ); 435 436 $results = $menus->search_available_items_query( 437 array( 438 'pagenum' => 1, 439 's' => 'foo', 440 ) 441 ); 442 443 $this->assertEqualSets( $expected, $results[0] ); 444 } 445 401 446 /** 402 447 * Count for number of times customize_nav_menu_searched_items filtered. 403 448 * -
tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php
diff --git a/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php b/tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php index 55febb9e8d..c8067e9d5d 100644
a b class Tests_Menu_WpAjaxMenuQuickSeach extends WP_UnitTestCase { 121 121 $this->assertCount( 1, $results ); 122 122 } 123 123 } 124 125 /** 126 * Test that search displays terms that are not assigned to any posts. 127 * 128 * @ticket 45298 129 */ 130 public function test_search_should_return_unassigned_term_items() { 131 register_taxonomy( 'wptests_tax', 'post' ); 132 133 $term_id = $this->factory->term->create( 134 array( 135 'taxonomy' => 'wptests_tax', 136 'name' => 'foobar', 137 ) 138 ); 139 140 $request = array( 141 'type' => 'quick-search-taxonomy-wptests_tax', 142 'q' => 'foobar', 143 ); 144 $output = get_echo( '_wp_ajax_menu_quick_search', array( $request ) ); 145 146 $this->assertNotEmpty( $output ); 147 $results = explode( "\n", trim( $output ) ); 148 $this->assertCount( 1, $results ); 149 }