Ticket #41825: 41825.3.diff
File 41825.3.diff, 5.0 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-editor.php
diff --git src/wp-includes/class-wp-editor.php src/wp-includes/class-wp-editor.php index a61f239788..775042e86c 100644
final class _WP_Editors { 1623 1623 // Do main query. 1624 1624 $get_posts = new WP_Query; 1625 1625 $posts = $get_posts->query( $query ); 1626 // Check if any posts were found.1627 if ( ! $get_posts->post_count )1628 return false;1629 1626 1630 1627 // Build results. 1631 1628 $results = array(); 1629 1630 // Check if any posts were found. 1631 if ( ! $get_posts->post_count ) { 1632 /** 1633 * Filters the link query results. 1634 * 1635 * Allows modification of the returned link query results. 1636 * 1637 * @since 3.7.0 1638 * 1639 * @see 'wp_link_query_args' filter 1640 * 1641 * @param array $results { 1642 * An associative array of query results. 1643 * 1644 * @type array { 1645 * @type int $ID Post ID. 1646 * @type string $title The trimmed, escaped post title. 1647 * @type string $permalink Post permalink. 1648 * @type string $info A 'Y/m/d'-formatted date for 'post' post type, 1649 * the 'singular_name' post type label otherwise. 1650 * } 1651 * } 1652 * @param array $query An array of WP_Query arguments. 1653 */ 1654 $results = apply_filters( 'wp_link_query', $results, $query ); 1655 1656 return ! empty( $results ) ? $results : false; 1657 } 1658 1632 1659 foreach ( $posts as $post ) { 1633 1660 if ( 'post' == $post->post_type ) 1634 1661 $info = mysql2date( __( 'Y/m/d' ), $post->post_date ); … … final class _WP_Editors { 1643 1670 ); 1644 1671 } 1645 1672 1646 /** 1647 * Filters the link query results. 1648 * 1649 * Allows modification of the returned link query results. 1650 * 1651 * @since 3.7.0 1652 * 1653 * @see 'wp_link_query_args' filter 1654 * 1655 * @param array $results { 1656 * An associative array of query results. 1657 * 1658 * @type array { 1659 * @type int $ID Post ID. 1660 * @type string $title The trimmed, escaped post title. 1661 * @type string $permalink Post permalink. 1662 * @type string $info A 'Y/m/d'-formatted date for 'post' post type, 1663 * the 'singular_name' post type label otherwise. 1664 * } 1665 * } 1666 * @param array $query An array of WP_Query arguments. 1667 */ 1673 /** This filter is documented in wp-includes/class-wp-editor.php */ 1668 1674 return apply_filters( 'wp_link_query', $results, $query ); 1669 1675 } 1670 1676 -
new file tests/phpunit/tests/editor/wpEditors.php
diff --git tests/phpunit/tests/editor/wpEditors.php tests/phpunit/tests/editor/wpEditors.php new file mode 100644 index 0000000000..edaf698466
- + 1 <?php 2 3 if ( ! class_exists( '_WP_Editors', false ) ) { 4 require_once ABSPATH . WPINC . '/class-wp-editor.php'; 5 } 6 7 /** 8 * @group editor 9 */ 10 class Tests_WP_Editors extends WP_UnitTestCase { 11 public function wp_link_query_callback( $results ) { 12 return array_merge( $results, array( 13 array( 14 'ID' => 123, 15 'title' => 'foo', 16 'permalink' => 'bar', 17 'info' => 'baz', 18 ), 19 ) ); 20 } 21 22 public function test_wp_link_query_returns_false_when_nothing_found() { 23 $actual = _WP_Editors::wp_link_query( array( 's' => 'foobarbaz' ) ); 24 25 $this->assertFalse( $actual ); 26 } 27 28 public function test_wp_link_query_returns_search_results() { 29 $post = self::factory()->post->create_and_get( array( 'post_status' => 'publish' ) ); 30 $actual = _WP_Editors::wp_link_query( array( 's' => $post->post_title ) ); 31 32 $this->assertEqualSets( array( 33 array( 34 'ID' => $post->ID, 35 'title' => $post->post_title, 36 'permalink' => get_permalink( $post->ID ), 37 'info' => mysql2date( __( 'Y/m/d' ), $post->post_date ), 38 ), 39 ), $actual ); 40 } 41 42 /** 43 * @ticket 41825 44 */ 45 public function test_wp_link_query_returns_filtered_result_when_nothing_found() { 46 add_filter( 'wp_link_query', array( $this, 'wp_link_query_callback' ) ); 47 $actual = _WP_Editors::wp_link_query( array( 's' => 'foobarbaz' ) ); 48 remove_filter( 'wp_link_query', array( $this, 'wp_link_query_callback' ) ); 49 50 $this->assertEqualSets( array( 51 array( 52 'ID' => 123, 53 'title' => 'foo', 54 'permalink' => 'bar', 55 'info' => 'baz', 56 ), 57 ), $actual ); 58 } 59 60 public function test_wp_link_query_returns_filtered_search_results() { 61 $post = self::factory()->post->create_and_get( array( 'post_status' => 'publish' ) ); 62 63 add_filter( 'wp_link_query', array( $this, 'wp_link_query_callback' ) ); 64 $actual = _WP_Editors::wp_link_query( array( 's' => $post->post_title ) ); 65 remove_filter( 'wp_link_query', array( $this, 'wp_link_query_callback' ) ); 66 67 $this->assertEqualSets( array( 68 array( 69 'ID' => $post->ID, 70 'title' => $post->post_title, 71 'permalink' => get_permalink( $post->ID ), 72 'info' => mysql2date( __( 'Y/m/d' ), $post->post_date ), 73 ), 74 array( 75 'ID' => 123, 76 'title' => 'foo', 77 'permalink' => 'bar', 78 'info' => 'baz', 79 ), 80 ), $actual ); 81 } 82 }