Ticket #45298: 45298-2.diff
File 45298-2.diff, 4.3 KB (added by , 5 years ago) |
---|
-
src/wp-admin/includes/nav-menu.php
diff --git src/wp-admin/includes/nav-menu.php src/wp-admin/includes/nav-menu.php index 0539e7f..7d4e1a4 100644
function _wp_ajax_menu_quick_search( $request = array() ) { 109 109 'taxonomy' => $matches[2], 110 110 'name__like' => $query, 111 111 'number' => 10, 112 'hide_empty' => false, 112 113 ) 113 114 ); 114 115 if ( empty( $terms ) || is_wp_error( $terms ) ) { -
src/wp-includes/class-wp-customize-nav-menus.php
diff --git src/wp-includes/class-wp-customize-nav-menus.php src/wp-includes/class-wp-customize-nav-menus.php index a6bae20..e787370 100644
final class WP_Customize_Nav_Menus { 369 369 array( 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 tests/phpunit/tests/customize/nav-menus.php tests/phpunit/tests/customize/nav-menus.php index e738777..8191b1d 100644
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 { 399 399 } 400 400 401 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 446 /** 402 447 * Count for number of times customize_nav_menu_searched_items filtered. 403 448 * 404 449 * @var int -
tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php
diff --git tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php tests/phpunit/tests/menu/wpAjaxMenuQuickSearch.php index b5df3a1..9c90ee0 100644
class Tests_Menu_WpAjaxMenuQuickSeach extends WP_UnitTestCase { 120 120 $results = explode( "\n", trim( $output ) ); 121 121 $this->assertCount( 1, $results ); 122 122 } 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 $term_id = $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 } 123 149 }