forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetPageUri.php
More file actions
73 lines (60 loc) · 2.27 KB
/
getPageUri.php
File metadata and controls
73 lines (60 loc) · 2.27 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
<?php
/**
* @group post
*/
class Tests_Post_getPageUri extends WP_UnitTestCase {
/**
* @ticket 22883
*/
function test_get_page_uri_with_stdclass_post_object() {
$post_id = self::factory()->post->create( array( 'post_name' => 'get-page-uri-post-name' ) );
// Mimick an old stdClass post object, missing the ancestors field.
$post_array = (object) get_post( $post_id, ARRAY_A );
unset( $post_array->ancestors );
// Dummy assertion. If this test fails, it will actually error out on an E_WARNING.
$this->assertEquals( 'get-page-uri-post-name', get_page_uri( $post_array ) );
}
/**
* @ticket 24491
*/
function test_get_page_uri_with_nonexistent_post() {
global $wpdb;
$post_id = $wpdb->get_var( "SELECT MAX(ID) FROM $wpdb->posts" ) + 1;
$this->assertFalse( get_page_uri( $post_id ) );
}
/**
* @ticket 15963
*/
function test_get_post_uri_check_orphan() {
$parent_id = self::factory()->post->create( array( 'post_name' => 'parent' ) );
$child_id = self::factory()->post->create( array( 'post_name' => 'child', 'post_parent' => $parent_id ) );
// check the parent for good measure
$this->assertEquals( 'parent', get_page_uri( $parent_id ) );
// try the child normally
$this->assertEquals( 'parent/child', get_page_uri( $child_id ) );
// now delete the parent from the database and check
wp_delete_post( $parent_id, true );
$this->assertEquals( 'child', get_page_uri( $child_id ) );
}
/**
* @ticket 36174
*/
function test_get_page_uri_with_a_draft_parent_with_empty_slug() {
$parent_id = self::factory()->post->create( array( 'post_name' => 'parent' ) );
$child_id = self::factory()->post->create( array( 'post_name' => 'child', 'post_parent' => $parent_id ) );
wp_update_post( array( 'ID' => $parent_id, 'post_name' => '', 'post_status' => 'draft' ) );
$this->assertEquals( 'child', get_page_uri( $child_id ) );
}
/**
* @ticket 26284
*/
function test_get_page_uri_without_argument() {
$post_id = self::factory()->post->create(array(
'post_title' => 'Blood Orange announces summer tour dates',
'post_name' => 'blood-orange-announces-summer-tour-dates',
));
$post = get_post( $post_id );
$this->go_to( get_permalink( $post_id ) );
$this->assertEquals( 'blood-orange-announces-summer-tour-dates', get_page_uri() );
}
}