From 13f51e844f6dd1174a319e4abcee52ca871c8bc1 Mon Sep 17 00:00:00 2001 From: SirLouen Date: Wed, 19 Mar 2025 11:48:10 +0100 Subject: [PATCH 1/5] Adding GMT Offset for RSS Block --- src/wp-includes/blocks/rss.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/blocks/rss.php b/src/wp-includes/blocks/rss.php index 85e4e63c9dbf7..80caf18ad8a36 100644 --- a/src/wp-includes/blocks/rss.php +++ b/src/wp-includes/blocks/rss.php @@ -43,15 +43,20 @@ function render_block_core_rss( $attributes ) { } $title = "
{$title}
"; - $date = ''; - if ( $attributes['displayDate'] ) { - $date = $item->get_date( 'U' ); + $date_markup = ''; + if ( ! empty( $attributes['displayDate'] ) ) { + $timestamp = $item->get_date( 'U' ); + + if ( $timestamp ) { + $gmt_offset = get_option( 'gmt_offset' ); + if ( is_numeric( $gmt_offset ) ) { + $timestamp += (int) ( (float) $gmt_offset * HOUR_IN_SECONDS ); + } - if ( $date ) { - $date = sprintf( + $date_markup = sprintf( ' ', - esc_attr( date_i18n( 'c', $date ) ), - esc_attr( date_i18n( get_option( 'date_format' ), $date ) ) + esc_attr( date_i18n( 'c', $timestamp ) ), + esc_html( date_i18n( get_option( 'date_format' ), $timestamp ) ) ); } } @@ -85,7 +90,7 @@ function render_block_core_rss( $attributes ) { $excerpt = '
' . esc_html( $excerpt ) . '
'; } - $list_items .= "
  • {$title}{$date}{$author}{$excerpt}
  • "; + $list_items .= "
  • {$title}{$date_markup}{$author}{$excerpt}
  • "; } $classnames = array(); From 073c80043ff33544a3d7e9ded605cf08663c4809 Mon Sep 17 00:00:00 2001 From: SirLouen Date: Wed, 19 Mar 2025 15:44:34 +0100 Subject: [PATCH 2/5] Unit Tests for RSS Block --- tests/phpunit/tests/blocks/renderRssBlock.php | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 tests/phpunit/tests/blocks/renderRssBlock.php diff --git a/tests/phpunit/tests/blocks/renderRssBlock.php b/tests/phpunit/tests/blocks/renderRssBlock.php new file mode 100644 index 0000000000000..b44e8d93af323 --- /dev/null +++ b/tests/phpunit/tests/blocks/renderRssBlock.php @@ -0,0 +1,179 @@ + + + +Test RSS Feed +https://www.example.com + +This is a test RSS feed for unit testing. +en-us +Wed, 19 Mar 2025 00:00:01 -0700 +Wed, 19 Mar 2025 03:58:04 -0700 +Test + +Test Article 1 +https://www.example.com/article1 +https://www.example.com/article1 +Test Author +This is a test article description. +Thu, 10 Mar 2025 04:00:00 -0700 +Test Source + + +Test Article 2 +https://www.example.com/article2 +https://www.example.com/article2 +Test Author 2 +This is another test article description. +Wed, 18 Mar 2025 10:30:00 -0700 +Test Source + + + +XML; + + return array( + 'headers' => array( + 'content-type' => 'application/rss+xml; charset=UTF-8', + ), + 'body' => $mock_rss, + 'response' => array( + 'code' => 200, + 'message' => 'OK', + ), + 'cookies' => array(), + 'filename' => null, + ); + } + + /** + * Sets up the "core/rss" block context for testing. + * This is needed to avoid null access in WP_Block_Supports::apply_block_supports(). + * + * @ticket 62400 + */ + private function setup_block_context() { + $block = array( + 'blockName' => 'core/rss', + 'attrs' => array(), + ); + + $wp_block_supports = WP_Block_Supports::get_instance(); + $reflection = new ReflectionClass( $wp_block_supports ); + $property = $reflection->getProperty( 'block_to_render' ); + $property->setAccessible( true ); + $property->setValue( $wp_block_supports, $block ); + } + + /** + * Test that the date in the RSS feed is correctly rendered in the HTML. + * + * @ticket 62400 + * + * @covers ::render_block_core_rss + */ + public function test_rss_date_rendering() { + + $original_date_format = get_option( 'date_format' ); + $original_gmt_offset = get_option( 'gmt_offset' ); + + update_option( 'date_format', 'F j, Y' ); + // We set to UTC+9 to test timezone conversion. + update_option( 'gmt_offset', 9 ); + + $this->setup_block_context(); + + // Mock RSS Attributes. + $attributes = array( + 'feedURL' => 'https://example.com/testrss.xml', + 'itemsToShow' => 2, + 'displayExcerpt' => false, + 'displayAuthor' => false, + 'displayDate' => true, + 'blockLayout' => 'list', + ); + + $rendered_html = render_block_core_rss( $attributes ); + + $this->assertStringContainsString( '