forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpEditors.php
More file actions
108 lines (96 loc) · 2.53 KB
/
wpEditors.php
File metadata and controls
108 lines (96 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
if ( ! class_exists( '_WP_Editors', false ) ) {
require_once ABSPATH . WPINC . '/class-wp-editor.php';
}
/**
* @group editor
*
* @coversDefaultClass _WP_Editors
*/
class Tests_Editor_wpEditors extends WP_UnitTestCase {
/**
* @covers ::wp_link_query
*/
public function test_wp_link_query_returns_false_when_nothing_found() {
$actual = _WP_Editors::wp_link_query( array( 's' => 'foobarbaz' ) );
$this->assertFalse( $actual );
}
/**
* @covers ::wp_link_query
*/
public function test_wp_link_query_returns_search_results() {
$post = self::factory()->post->create_and_get( array( 'post_status' => 'publish' ) );
$actual = _WP_Editors::wp_link_query( array( 's' => $post->post_title ) );
$this->assertSameSets(
array(
array(
'ID' => $post->ID,
'title' => $post->post_title,
'permalink' => get_permalink( $post->ID ),
'info' => mysql2date( __( 'Y/m/d' ), $post->post_date ),
),
),
$actual
);
}
/**
* @ticket 41825
*
* @covers ::wp_link_query
*/
public function test_wp_link_query_returns_filtered_result_when_nothing_found() {
add_filter( 'wp_link_query', array( $this, 'wp_link_query_callback' ) );
$actual = _WP_Editors::wp_link_query( array( 's' => 'foobarbaz' ) );
remove_filter( 'wp_link_query', array( $this, 'wp_link_query_callback' ) );
$this->assertSameSets(
array(
array(
'ID' => 123,
'title' => 'foo',
'permalink' => 'bar',
'info' => 'baz',
),
),
$actual
);
}
/**
* @covers ::wp_link_query
*/
public function test_wp_link_query_returns_filtered_search_results() {
$post = self::factory()->post->create_and_get( array( 'post_status' => 'publish' ) );
add_filter( 'wp_link_query', array( $this, 'wp_link_query_callback' ) );
$actual = _WP_Editors::wp_link_query( array( 's' => $post->post_title ) );
remove_filter( 'wp_link_query', array( $this, 'wp_link_query_callback' ) );
$this->assertSameSets(
array(
array(
'ID' => $post->ID,
'title' => $post->post_title,
'permalink' => get_permalink( $post->ID ),
'info' => mysql2date( __( 'Y/m/d' ), $post->post_date ),
),
array(
'ID' => 123,
'title' => 'foo',
'permalink' => 'bar',
'info' => 'baz',
),
),
$actual
);
}
public function wp_link_query_callback( $results ) {
return array_merge(
$results,
array(
array(
'ID' => 123,
'title' => 'foo',
'permalink' => 'bar',
'info' => 'baz',
),
)
);
}
}