forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpingback.php
More file actions
91 lines (71 loc) · 2.13 KB
/
pingback.php
File metadata and controls
91 lines (71 loc) · 2.13 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
<?php
/**
* @group comment
* @covers ::pingback
*/
class Tests_Comment_Pingback extends WP_UnitTestCase {
protected static $post_id;
protected $response = array();
public function set_up() {
parent::set_up();
add_filter( 'pre_http_request', array( $this, 'request_response' ) );
}
public function tear_down() {
remove_filter( 'pre_http_request', array( $this, 'request_response' ) );
parent::tear_down();
}
public function test_pingback() {
$content = <<<HTML
<a href="http://example.org">test</a>
<a href="http://example1.org/test">test</a>
<a href="http://example3.org/">test</a>
HTML;
$body = <<<BODY
<a rel="pingback" href="https://example1.org/test/pingback">test</a>
BODY;
$this->response = array(
'body' => $body,
'response' => array( 'code' => 200 ),
);
self::$post_id = self::factory()->post->create(
array( 'post_content' => $content )
);
$post = get_post( self::$post_id );
$this->assertEquals( array( 'http://example1.org/test' => false ), pingback( $post->post_content, self::$post_id ) );
}
public function test_pingback_no_ping_back() {
$content = <<<HTML
<a href="http://example.org">test</a>
<a href="http://example1.org/test">test</a>
<a href="http://example3.org/">test</a>
HTML;
$body = <<<BODY
<a href="https://example1.org/test">test</a>
BODY;
$this->response = array(
'body' => $body,
'response' => array( 'code' => 200 ),
);
self::$post_id = self::factory()->post->create(
array( 'post_content' => $content )
);
$post = get_post( self::$post_id );
$this->assertEquals( array(), pingback( $post->post_content, self::$post_id ) );
}
public function test_pingback_error_response() {
$content = <<<HTML
<a href="http://example.org">test</a>
<a href="http://example1.org/test">test</a>
<a href="http://example3.org/">test</a>
HTML;
$this->response = new WP_Error();
self::$post_id = self::factory()->post->create(
array( 'post_content' => $content )
);
$post = get_post( self::$post_id );
$this->assertEquals( array(), pingback( $post->post_content, self::$post_id ) );
}
public function request_response() {
return $this->response;
}
}