forked from WordPress/wordpress-develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrssEnclosure.php
More file actions
134 lines (116 loc) · 3.79 KB
/
rssEnclosure.php
File metadata and controls
134 lines (116 loc) · 3.79 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
<?php
/**
* Tests for the rss_enclosure() function.
*
* @group feed
*
* @covers ::rss_enclosure
*/
class Tests_Feed_RssEnclosure extends WP_UnitTestCase {
/**
* @ticket 58798
*/
public function test_rss_enclosure_filter() {
$post_id = self::factory()->post->create();
$GLOBALS['post'] = $post_id;
$valid_enclosure_string = "http://example.com/sound2.mp3\n12345\naudio/mpeg\n";
update_post_meta( $post_id, 'enclosure', $valid_enclosure_string );
add_filter(
'rss_enclosure',
static function () {
return 'filtered_html_link_tag';
}
);
$this->assertSame( 'filtered_html_link_tag', get_echo( 'rss_enclosure' ), 'The `rss_enclosure` filter could not be applied.' );
}
/**
* @ticket 58798
*/
public function test_rss_enclosure_when_global_post_is_empty() {
$this->assertEmpty( get_echo( 'rss_enclosure' ), 'The output should be empty when the global post is not set.' );
}
/**
* @ticket 58798
*/
public function test_rss_enclosure_when_enclosure_meta_field_is_empty() {
$post_id = self::factory()->post->create();
$GLOBALS['post'] = $post_id;
$this->assertEmpty( get_echo( 'rss_enclosure' ), 'The output should be empty when the global post does not have the `enclosure` meta field.' );
}
/**
* @ticket 58798
*
* @dataProvider data_rss_enclosure_with_multiline_enclosure_string
*/
public function test_rss_enclosure_with_multiline_enclosure_string( $enclosure_data, $enclosure_string ) {
$post_id = self::factory()->post->create();
$GLOBALS['post'] = $post_id;
update_post_meta( $post_id, 'enclosure', $enclosure_string );
$expected = '<enclosure url="' . $enclosure_data['url'] . '" length="' . $enclosure_data['length'] . '" type="' . $enclosure_data['type'] . '" />' . "\n";
$this->assertSame( $expected, get_echo( 'rss_enclosure' ), 'The output should be a valid enclosure tag.' );
}
/**
* Data provider for valid enclosure string.
*
* @return array[]
*/
public function data_rss_enclosure_with_multiline_enclosure_string() {
return array(
'two-break-lines' => array(
array(
'url' => 'http://example.com/sound2.mp3',
'length' => 12345,
'type' => 'audio/mpeg',
),
"http://example.com/sound2.mp3\n12345\naudio/mpeg",
),
'three-break-lines' => array(
array(
'url' => 'http://example.com/sound2.mp3',
'length' => 12345,
'type' => 'audio/mpeg',
),
"http://example.com/sound2.mp3\n12345\naudio/mpeg\n",
),
'extra-break-line-at-end' => array(
array(
'url' => 'http://example.com/sound2.mp3',
'length' => 12345,
'type' => 'audio/mpeg',
),
"http://example.com/sound2.mp3\n12345\naudio/mpeg\n\n",
),
'extra-type-elements' => array(
array(
'url' => 'http://example.com/sound2.mp3',
'length' => 12345,
'type' => 'audio/mpeg',
),
"http://example.com/sound2.mp3\n12345\naudio/mpeg mpga mp2 mp3\n",
),
);
}
/**
* @ticket 58798
*
* @dataProvider data_rss_enclosure_with_non_valid_enclosure_string
*/
public function test_rss_enclosure_with_non_valid_enclosure_string( $enclosure_string ) {
$post_id = self::factory()->post->create();
$GLOBALS['post'] = $post_id;
update_post_meta( $post_id, 'enclosure', $enclosure_string );
$this->assertEmpty( get_echo( 'rss_enclosure' ), 'The output should be empty when the `enclosure` meta field is not saved in a multiline string.' );
}
/**
* Data provider for non-valid enclosure string.
*
* @return array[]
*/
public function data_rss_enclosure_with_non_valid_enclosure_string() {
return array(
'empty' => array( '' ),
'no-break-lines' => array( 'http://example.com/sound2.mp3 12345 audio/mpeg' ),
'one-break-line' => array( "http://example.com/sound2.mp3\n12345 audio/mpeg" ),
);
}
}