forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformats.php
More file actions
159 lines (126 loc) · 5.65 KB
/
formats.php
File metadata and controls
159 lines (126 loc) · 5.65 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* @group post
*/
class Tests_Post_Formats extends WP_UnitTestCase {
function setUp() {
parent::setUp();
}
function test_set_get_post_format_for_post() {
$post_id = self::factory()->post->create();
$format = get_post_format( $post_id );
$this->assertFalse( $format );
$result = set_post_format( $post_id, 'aside' );
$this->assertNotWPError( $result );
$this->assertInternalType( 'array', $result );
$this->assertSame( 1, count( $result ) );
$format = get_post_format( $post_id );
$this->assertSame( 'aside', $format );
$result = set_post_format( $post_id, 'standard' );
$this->assertNotWPError( $result );
$this->assertInternalType( 'array', $result );
$this->assertSame( 0, count( $result ) );
$result = set_post_format( $post_id, '' );
$this->assertNotWPError( $result );
$this->assertInternalType( 'array', $result );
$this->assertSame( 0, count( $result ) );
}
/**
* @ticket 22473
*/
function test_set_get_post_format_for_page() {
$post_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
$format = get_post_format( $post_id );
$this->assertFalse( $format );
$result = set_post_format( $post_id, 'aside' );
$this->assertNotWPError( $result );
$this->assertInternalType( 'array', $result );
$this->assertSame( 1, count( $result ) );
// The format can be set but not retrieved until it is registered.
$format = get_post_format( $post_id );
$this->assertFalse( $format );
// Register format support for the page post type.
add_post_type_support( 'page', 'post-formats' );
// The previous set can now be retrieved.
$format = get_post_format( $post_id );
$this->assertSame( 'aside', $format );
$result = set_post_format( $post_id, 'standard' );
$this->assertNotWPError( $result );
$this->assertInternalType( 'array', $result );
$this->assertSame( 0, count( $result ) );
$result = set_post_format( $post_id, '' );
$this->assertNotWPError( $result );
$this->assertInternalType( 'array', $result );
$this->assertSame( 0, count( $result ) );
remove_post_type_support( 'page', 'post-formats' );
}
function test_has_format() {
$post_id = self::factory()->post->create();
$this->assertFalse( has_post_format( 'standard', $post_id ) );
$this->assertFalse( has_post_format( '', $post_id ) );
$result = set_post_format( $post_id, 'aside' );
$this->assertNotWPError( $result );
$this->assertInternalType( 'array', $result );
$this->assertSame( 1, count( $result ) );
$this->assertTrue( has_post_format( 'aside', $post_id ) );
$result = set_post_format( $post_id, 'standard' );
$this->assertNotWPError( $result );
$this->assertInternalType( 'array', $result );
$this->assertSame( 0, count( $result ) );
// Standard is a special case. It shows as false when set.
$this->assertFalse( has_post_format( 'standard', $post_id ) );
// Dummy format type.
$this->assertFalse( has_post_format( 'dummy', $post_id ) );
// Dummy post ID.
$this->assertFalse( has_post_format( 'aside', 12345 ) );
}
/**
* @ticket 23570
*/
function test_get_url_in_content() {
$link = 'http://nytimes.com';
$commentary = 'This is my favorite link';
$link_with_commentary = <<<DATA
$link
$commentary
DATA;
$href = '<a href="http://nytimes.com">NYT</a>';
$href_with_commentary = <<<DATA
$href
$commentary
DATA;
$link_post_id = self::factory()->post->create( array( 'post_content' => $link ) );
$content_link = get_url_in_content( get_post_field( 'post_content', $link_post_id ) );
$this->assertFalse( $content_link );
$link_with_post_id = self::factory()->post->create( array( 'post_content' => $link_with_commentary ) );
$content_link = get_url_in_content( get_post_field( 'post_content', $link_with_post_id ) );
$this->assertFalse( $content_link );
$content_link = get_url_in_content( get_post_field( 'post_content', $link_post_id ) );
$this->assertFalse( $content_link );
$content_link = get_url_in_content( get_post_field( 'post_content', $link_with_post_id ) );
$this->assertFalse( $content_link );
$empty_post_id = self::factory()->post->create( array( 'post_content' => '' ) );
$content_link = get_url_in_content( get_post_field( 'post_content', $empty_post_id ) );
$this->assertFalse( $content_link );
$comm_post_id = self::factory()->post->create( array( 'post_content' => $commentary ) );
$content_link = get_url_in_content( get_post_field( 'post_content', $comm_post_id ) );
$this->assertFalse( $content_link );
// Now with an href.
$href_post_id = self::factory()->post->create( array( 'post_content' => $href ) );
$content_link = get_url_in_content( get_post_field( 'post_content', $href_post_id ) );
$this->assertSame( $link, $content_link );
$href_with_post_id = self::factory()->post->create( array( 'post_content' => $href_with_commentary ) );
$content_link = get_url_in_content( get_post_field( 'post_content', $href_with_post_id ) );
$this->assertSame( $link, $content_link );
$content_link = get_url_in_content( get_post_field( 'post_content', $href_post_id ) );
$this->assertSame( $link, $content_link );
$content_link = get_url_in_content( get_post_field( 'post_content', $href_with_post_id ) );
$this->assertSame( $link, $content_link );
$empty_post_id = self::factory()->post->create( array( 'post_content' => '' ) );
$content_link = get_url_in_content( get_post_field( 'post_content', $empty_post_id ) );
$this->assertFalse( $content_link );
$comm_post_id = self::factory()->post->create( array( 'post_content' => $commentary ) );
$content_link = get_url_in_content( get_post_field( 'post_content', $comm_post_id ) );
$this->assertFalse( $content_link );
}
}