forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwpOembed.php
More file actions
72 lines (54 loc) · 2.39 KB
/
wpOembed.php
File metadata and controls
72 lines (54 loc) · 2.39 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
<?php
/**
* @group oembed
*/
class Tests_WP_oEmbed extends WP_UnitTestCase {
/**
* @var WP_oEmbed
*/
protected $oembed;
public $pre_oembed_result_filtered = false;
public function setUp() {
parent::setUp();
require_once ABSPATH . WPINC . '/class-oembed.php';
$this->oembed = _wp_oembed_get_object();
$this->pre_oembed_result_filtered = false;
}
public function _filter_pre_oembed_result( $result ) {
// If this is not null, the oEmbed result has been filtered before any HTTP requests were made.
$this->pre_oembed_result_filtered = $result;
// Return false to prevent HTTP requests during tests.
return $result ? $result : false;
}
public function test_wp_filter_pre_oembed_result_prevents_http_request_for_internal_permalinks() {
$post_id = self::factory()->post->create();
$permalink = get_permalink( $post_id );
add_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
$actual = $this->oembed->get_html( $permalink );
remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
$this->assertTrue( false !== $this->pre_oembed_result_filtered );
$this->assertEquals( $this->pre_oembed_result_filtered, $actual );
}
public function test_wp_filter_pre_oembed_result_prevents_http_request_when_viewing_the_post() {
$post_id = self::factory()->post->create();
$permalink = get_permalink( $post_id );
$this->go_to( $permalink );
$this->assertQueryTrue( 'is_single', 'is_singular' );
add_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
$actual = $this->oembed->get_html( $permalink );
remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
$this->assertTrue( false !== $this->pre_oembed_result_filtered );
$this->assertEquals( $this->pre_oembed_result_filtered, $actual );
}
public function test_wp_filter_pre_oembed_result_non_existent_post() {
$post_id = self::factory()->post->create();
$permalink = get_permalink( $post_id );
$this->go_to( $permalink );
$this->assertQueryTrue( 'is_single', 'is_singular' );
add_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
$actual = $this->oembed->get_html( 'https://example.com/' );
remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
$this->assertTrue( false !== $this->pre_oembed_result_filtered );
$this->assertFalse( $actual );
}
}