Skip to content
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

Initial pass at tests for Core-62354 #7758

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wp-includes/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ function fetch_feed( $url ) {
do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );

$feed->init();
$feed->set_output_encoding( get_option( 'blog_charset' ) );
$feed->set_output_encoding( get_bloginfo( 'charset' ) );

if ( $feed->error() ) {
return new WP_Error( 'simplepie-error', $feed->error() );
Expand Down
51 changes: 51 additions & 0 deletions tests/phpunit/tests/feed/fetchFeed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Tests the `fetch_feed` function.
*
* @package WordPress
* @subpackage UnitTests
* @since 6.7.0
*
* @group feed
*/
class Tests_Feed_fetchFeed extends WP_UnitTestCase {

public function set_up() {
parent::set_up();

add_filter( 'pre_http_request', array( $this, 'mocked_rss_response' ) );
}

/**
* @ticket 62354
*/
public function test_empty_charset_does_not_trigger_fatal_error() {
add_filter( 'pre_option_blog_charset', '__return_empty_string', 20 );

$feed = fetch_feed( 'https://wordpress.org/news/feed/' );

foreach( $feed->get_items( 0, 1 ) as $item ) {

Check failure on line 27 in tests/phpunit/tests/feed/fetchFeed.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Space after opening control structure is required

Check failure on line 27 in tests/phpunit/tests/feed/fetchFeed.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

No space before opening parenthesis is prohibited

Check failure on line 27 in tests/phpunit/tests/feed/fetchFeed.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Expected 1 space after FOREACH keyword; 0 found
$content = $item->get_content();
}

$this->assertStringContainsString( '<a href="https://learn.wordpress.org/">Learn WordPress</a> is a learning resource providing workshops, quizzes, courses, lesson plans, and discussion groups so that anyone, from beginners to advanced users, can learn to do more with WordPress.', $content );
}

public function mocked_rss_response() {
$single_value_headers = array(
'Content-Type' => 'application/rss+xml; charset=UTF-8',
'link' => '<https://wordpress.org/news/wp-json/>; rel="https://api.w.org/"',
);

return array(
'headers' => new WpOrg\Requests\Utility\CaseInsensitiveDictionary( $single_value_headers ),
'body' => file_get_contents( DIR_TESTDATA . '/feed/wordpress-org-news.xml' ),
'response' => array(
'code' => 200,
'message' => 'OK',
),
'cookies' => array(),
'filename' => null,
);
}
}
Loading