forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostEmbedUrl.php
More file actions
110 lines (83 loc) · 3.26 KB
/
postEmbedUrl.php
File metadata and controls
110 lines (83 loc) · 3.26 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
109
110
<?php
/**
* @group oembed
*/
class Tests_Post_Embed_URL extends WP_UnitTestCase {
function test_non_existent_post() {
$embed_url = get_post_embed_url( 0 );
$this->assertFalse( $embed_url );
}
function test_with_pretty_permalinks() {
$this->set_permalink_structure( '/%postname%' );
$post_id = self::factory()->post->create();
$permalink = get_permalink( $post_id );
$embed_url = get_post_embed_url( $post_id );
$this->assertEquals( $permalink . '/embed', $embed_url );
}
function test_with_ugly_permalinks() {
$post_id = self::factory()->post->create();
$permalink = get_permalink( $post_id );
$embed_url = get_post_embed_url( $post_id );
$this->assertEquals( $permalink . '&embed=true', $embed_url );
}
/**
* @ticket 34971
*/
function test_static_front_page() {
$this->set_permalink_structure( '/%postname%/' );
$post_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $post_id );
$embed_url = get_post_embed_url( $post_id );
$this->assertSame( user_trailingslashit( trailingslashit( home_url() ) . 'embed' ), $embed_url );
update_option( 'show_on_front', 'posts' );
}
/**
* @ticket 34971
*/
function test_static_front_page_with_ugly_permalinks() {
$post_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $post_id );
$embed_url = get_post_embed_url( $post_id );
$this->assertSame( trailingslashit( home_url() ) . '?embed=true', $embed_url );
update_option( 'show_on_front', 'posts' );
}
/**
* @ticket 34971
*/
function test_page_conflicts_with_embed_slug() {
$this->set_permalink_structure( '/%postname%/' );
$parent_page = self::factory()->post->create( array( 'post_type' => 'page' ) );
add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
$child_page = self::factory()->post->create(
array(
'post_type' => 'page',
'post_parent' => $parent_page,
'post_name' => 'embed',
)
);
remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
$this->assertSame( get_permalink( $parent_page ) . '?embed=true', get_post_embed_url( $parent_page ) );
$this->assertSame( get_permalink( $child_page ) . 'embed/', get_post_embed_url( $child_page ) );
}
/**
* @ticket 34971
*/
function test_static_front_page_conflicts_with_embed_slug() {
$this->set_permalink_structure( '/%postname%/' );
// Create a post with the 'embed' post_name
add_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
$post_embed_slug = self::factory()->post->create( array( 'post_name' => 'embed' ) );
remove_filter( 'wp_unique_post_slug', array( $this, 'filter_unique_post_slug' ) );
$page_front = self::factory()->post->create( array( 'post_type' => 'page' ) );
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $page_front );
$this->assertSame( home_url() . '/embed/embed/', get_post_embed_url( $post_embed_slug ) );
$this->assertSame( home_url() . '/?embed=true', get_post_embed_url( $page_front ) );
update_option( 'show_on_front', 'posts' );
}
public function filter_unique_post_slug() {
return 'embed';
}
}