-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Adding GMT Offset for RSS Block #8543
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
Open
SirLouen
wants to merge
5
commits into
WordPress:trunk
Choose a base branch
from
SirLouen:patch/62400
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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,31 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:fn="https://www.publishwithfoundation.com/rss/2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" version="2.0"> | ||
| <channel> | ||
| <title>Test RSS Feed</title> | ||
| <link>https://www.example.com</link> | ||
| <atom:link href="https://www.example.com/rss.xml" rel="self" type="application/rss+xml"/> | ||
| <description>This is a test RSS feed for unit testing.</description> | ||
| <language>en-us</language> | ||
| <pubDate>Wed, 19 Mar 2025 00:00:01 -0700</pubDate> | ||
| <lastBuildDate>Wed, 19 Mar 2025 03:58:04 -0700</lastBuildDate> | ||
| <generator>Test</generator> | ||
| <item> | ||
| <title>Test Article 1</title> | ||
| <link>https://www.example.com/article1</link> | ||
| <guid isPermaLink="true">https://www.example.com/article1</guid> | ||
| <dc:creator>Test Author</dc:creator> | ||
| <description>This is a test article description.</description> | ||
| <pubDate>Thu, 10 Mar 2025 04:00:00 -0700</pubDate> | ||
| <source url="https://www.example.com">Test Source</source> | ||
| </item> | ||
| <item> | ||
| <title>Test Article 2</title> | ||
| <link>https://www.example.com/article2</link> | ||
| <guid isPermaLink="true">https://www.example.com/article2</guid> | ||
| <dc:creator>Test Author 2</dc:creator> | ||
| <description>This is another test article description.</description> | ||
| <pubDate>Wed, 18 Mar 2025 10:30:00 -0700</pubDate> | ||
| <source url="https://www.example.com">Test Source</source> | ||
| </item> | ||
| </channel> | ||
| </rss> |
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,122 @@ | ||
| <?php | ||
| /** | ||
| * Tests for core/rss Gutenberg block. | ||
| * | ||
| * @package WordPress | ||
| * @subpackage Blocks | ||
| * @since 6.8.0 | ||
| * | ||
| * @group blocks | ||
| */ | ||
|
|
||
| /** | ||
| * Class for testing the core/rss Gutenberg block. | ||
| * | ||
| * @since 6.8.0 | ||
| */ | ||
| class Tests_Blocks_RenderRssBlock extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Set up before each test. | ||
| */ | ||
| public function set_up() { | ||
| parent::set_up(); | ||
|
|
||
| add_filter( 'wp_feed_cache_transient_lifetime', array( $this, 'return_zero_feed_cache' ) ); | ||
| add_filter( 'pre_http_request', array( $this, 'mock_http_request' ), 10, 3 ); | ||
| } | ||
|
|
||
| /** | ||
| * Set feed cache to zero to prevent caching interfering with tests. | ||
| * | ||
| * @ticket 62400 | ||
| * | ||
| * @return int Zero value. | ||
| */ | ||
| public function return_zero_feed_cache() { | ||
| return 0; | ||
| } | ||
|
|
||
|
SirLouen marked this conversation as resolved.
Outdated
|
||
| /** | ||
| * Mock HTTP request to return test feed data. | ||
| * | ||
| * @ticket 62400 | ||
| * | ||
| * @param bool|array $response The existing response or false. | ||
| * @param array $args The request arguments. | ||
| * @param string $url The request URL. | ||
| * @return array The mocked response. | ||
| */ | ||
| public function mock_http_request( $response, $args, $url ) { | ||
| if ( 'https://example.com/testrss.xml' !== $url ) { | ||
| return $response; | ||
| } | ||
|
|
||
| return array( | ||
| 'headers' => array( | ||
| 'content-type' => 'application/rss+xml; charset=UTF-8', | ||
| ), | ||
| // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents | ||
| 'body' => file_get_contents( DIR_TESTDATA . '/feed/Rss_Block_Test.xml' ), | ||
|
SirLouen marked this conversation as resolved.
Outdated
|
||
| '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() { | ||
|
|
||
| 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( '<time datetime=', $rendered_html, 'No time element found in rendered HTML' ); | ||
|
|
||
| $this->assertStringContainsString( 'March 19, 2025', $rendered_html, 'Formatted date not found in rendered HTML' ); | ||
|
|
||
| $this->assertMatchesRegularExpression( '/<time datetime="[^"]*2025-03-19[^"]*"/', $rendered_html, 'ISO datetime format missing expected date' ); | ||
| } | ||
| } | ||
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.