| 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 | } |