-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Fix possible PHP warning in rss_enclosure()
#7557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
517c6dd
add: tests to rss_enclosure()
Rahmon dda7193
fix: rss_enclosure() when saved enclosure is not in the expected format
Rahmon 7a21329
Update tests/phpunit/tests/feed/feed.php
Rahmon 46b7163
Update tests/phpunit/tests/feed/feed.php
Rahmon 054d2a2
Update src/wp-includes/feed.php
Rahmon 2b7fa3c
Update tests/phpunit/tests/feed/feed.php
Rahmon 3596b19
update to use get_echo
Rahmon 9fa0236
split tests and add data providers
Rahmon d81ea10
remove get_multiline_enclosure_string() and enclosure_data property
Rahmon 3b82489
Update tests/phpunit/tests/feed/feed.php
Rahmon 7d6d6cf
Update tests/phpunit/tests/feed/feed.php
Rahmon 9e55f8e
Update tests/phpunit/tests/feed/feed.php
Rahmon db697f2
Update tests/phpunit/tests/feed/feed.php
Rahmon 24f723f
rename from feed to rssEnclosure
Rahmon f3e0262
Merge branch 'trunk' into fix/rss_enclosure
peterwilsoncc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Test the feed. | ||
| * | ||
| * @group feed | ||
| */ | ||
| class Tests_Feed extends WP_UnitTestCase { | ||
Rahmon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| protected static $enclosure_data = array( | ||
| 'url' => 'http://example.com/sound2.mp3', | ||
| 'length' => 12345, | ||
| 'type' => 'audio/mpeg', | ||
| ); | ||
|
|
||
| /** | ||
| * Get the rss_enclosure() output. | ||
| * | ||
| * @return string | ||
| */ | ||
| protected function get_rss_enclosure() { | ||
| ob_start(); | ||
| rss_enclosure(); | ||
| return ob_get_clean(); | ||
| } | ||
|
|
||
Rahmon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /** | ||
| * Get a multiline enclosure string. | ||
| * | ||
| * This function generates a multiline string like | ||
| * wp_xmlrpc_server::add_enclosure_if_new function. | ||
| * | ||
| * @return string | ||
| */ | ||
| protected function get_multiline_enclosure_string() { | ||
| return self::$enclosure_data['url'] . "\n" . self::$enclosure_data['length'] . "\n" . self::$enclosure_data['type'] . "\n"; | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 58798 | ||
| * | ||
| * @covers rss_enclosure | ||
Rahmon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public function test_rss_enclosure_filter() { | ||
| $post_id = self::factory()->post->create(); | ||
| $GLOBALS['post'] = $post_id; | ||
|
|
||
| update_post_meta( $post_id, 'enclosure', $this->get_multiline_enclosure_string() ); | ||
|
|
||
| add_filter( | ||
| 'rss_enclosure', | ||
| function () { | ||
| return 'filtered_html_link_tag'; | ||
| } | ||
| ); | ||
|
|
||
| $this->assertSame( 'filtered_html_link_tag', $this->get_rss_enclosure(), 'The `rss_enclosure` filter could not be applied.' ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 58798 | ||
| * | ||
| * @covers rss_enclosure | ||
Rahmon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public function test_rss_enclosure() { | ||
| $this->assertEmpty( $this->get_rss_enclosure(), 'It should return empty when the global post is not set.' ); | ||
|
|
||
| $post_id = self::factory()->post->create(); | ||
| $GLOBALS['post'] = $post_id; | ||
|
|
||
| $this->assertEmpty( $this->get_rss_enclosure(), 'The global post does not have the `enclosure` meta field and should return empty. ' ); | ||
|
|
||
| update_post_meta( $post_id, 'enclosure', $this->get_multiline_enclosure_string() ); | ||
|
|
||
| $expected = '<enclosure url="' . self::$enclosure_data['url'] . '" length="' . self::$enclosure_data['length'] . '" type="' . self::$enclosure_data['type'] . '" />' . "\n"; | ||
|
|
||
| $this->assertSame( $expected, $this->get_rss_enclosure(), 'It should return a valid enclosure tag. ' ); | ||
|
|
||
| update_post_meta( $post_id, 'enclosure', self::$enclosure_data['url'] ); | ||
|
|
||
| $this->assertEmpty( $this->get_rss_enclosure(), 'It should return empty when the `enclosure` meta field is not saved in a multiline string.' ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.