search_available_items_query() public method

Based on WP_Editor::wp_link_query().
Since: 4.3.0
public search_available_items_query ( array $args = [] ) : array
$args array Optional. Accepts 'pagenum' and 's' (search) arguments.
return array Menu items.
Example #1
0
 /**
  * Test the search_available_items_query method.
  *
  * @see WP_Customize_Nav_Menus::search_available_items_query()
  */
 function test_search_available_items_query()
 {
     $menus = new WP_Customize_Nav_Menus($this->wp_customize);
     // Create posts
     $post_ids = array();
     $post_ids[] = $this->factory->post->create(array('post_title' => 'Search & Test'));
     $post_ids[] = $this->factory->post->create(array('post_title' => 'Some Other Title'));
     // Create terms
     $term_ids = array();
     $term_ids[] = $this->factory->category->create(array('name' => 'Dogs Are Cool'));
     $term_ids[] = $this->factory->category->create(array('name' => 'Cats Drool'));
     // Test empty results
     $expected = array();
     $results = $menus->search_available_items_query(array('pagenum' => 1, 's' => 'This Does NOT Exist'));
     $this->assertEquals($expected, $results);
     // Test posts
     foreach ($post_ids as $post_id) {
         $expected = array('id' => 'post-' . $post_id, 'title' => html_entity_decode(get_the_title($post_id)), 'type' => 'post_type', 'type_label' => get_post_type_object('post')->labels->singular_name, 'object' => 'post', 'object_id' => intval($post_id), 'url' => get_permalink(intval($post_id)));
         wp_set_object_terms($post_id, $term_ids, 'category');
         $search = $post_id === $post_ids[0] ? 'test & search' : 'other title';
         $s = sanitize_text_field(wp_unslash($search));
         $results = $menus->search_available_items_query(array('pagenum' => 1, 's' => $s));
         $this->assertEquals($expected, $results[0]);
     }
     // Test terms
     foreach ($term_ids as $term_id) {
         $term = get_term_by('id', $term_id, 'category');
         $expected = array('id' => 'term-' . $term_id, 'title' => $term->name, 'type' => 'taxonomy', 'type_label' => get_taxonomy('category')->labels->singular_name, 'object' => 'category', 'object_id' => intval($term_id), 'url' => get_term_link(intval($term_id), 'category'));
         $s = sanitize_text_field(wp_unslash($term->name));
         $results = $menus->search_available_items_query(array('pagenum' => 1, 's' => $s));
         $this->assertEquals($expected, $results[0]);
     }
 }