1414 *
1515 * @since 6.8.0
1616 */
17- class Tests_Blocks_RssBlock extends WP_UnitTestCase {
17+ class Tests_Blocks_RenderRssBlock extends WP_UnitTestCase {
1818
1919 /**
2020 * Set up before each test.
21- *
22- * @ticket 62400
2321 */
2422 public function set_up () {
2523 parent ::set_up ();
@@ -28,17 +26,6 @@ public function set_up() {
2826 add_filter ( 'pre_http_request ' , array ( $ this , 'mock_http_request ' ), 10 , 3 );
2927 }
3028
31- /**
32- * Clean up after each test.
33- *
34- * @ticket 62400
35- */
36- public function tear_down () {
37- remove_filter ( 'wp_feed_cache_transient_lifetime ' , array ( $ this , 'return_zero_feed_cache ' ) );
38- remove_filter ( 'pre_http_request ' , array ( $ this , 'mock_http_request ' ) );
39- parent ::tear_down ();
40- }
41-
4229 /**
4330 * Set feed cache to zero to prevent caching interfering with tests.
4431 *
@@ -65,45 +52,11 @@ public function mock_http_request( $response, $args, $url ) {
6552 return $ response ;
6653 }
6754
68- $ mock_rss = <<<XML
69- <?xml version="1.0" encoding="UTF-8"?>
70- <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">
71- <channel>
72- <title>Test RSS Feed</title>
73- <link>https://www.example.com</link>
74- <atom:link href="https://www.example.com/rss.xml" rel="self" type="application/rss+xml"/>
75- <description>This is a test RSS feed for unit testing.</description>
76- <language>en-us</language>
77- <pubDate>Wed, 19 Mar 2025 00:00:01 -0700</pubDate>
78- <lastBuildDate>Wed, 19 Mar 2025 03:58:04 -0700</lastBuildDate>
79- <generator>Test</generator>
80- <item>
81- <title>Test Article 1</title>
82- <link>https://www.example.com/article1</link>
83- <guid isPermaLink="true">https://www.example.com/article1</guid>
84- <dc:creator>Test Author</dc:creator>
85- <description>This is a test article description.</description>
86- <pubDate>Thu, 10 Mar 2025 04:00:00 -0700</pubDate>
87- <source url="https://www.example.com">Test Source</source>
88- </item>
89- <item>
90- <title>Test Article 2</title>
91- <link>https://www.example.com/article2</link>
92- <guid isPermaLink="true">https://www.example.com/article2</guid>
93- <dc:creator>Test Author 2</dc:creator>
94- <description>This is another test article description.</description>
95- <pubDate>Wed, 18 Mar 2025 10:30:00 -0700</pubDate>
96- <source url="https://www.example.com">Test Source</source>
97- </item>
98- </channel>
99- </rss>
100- XML ;
101-
10255 return array (
10356 'headers ' => array (
10457 'content-type ' => 'application/rss+xml; charset=UTF-8 ' ,
10558 ),
106- 'body ' => $ mock_rss ,
59+ 'body ' => file_get_contents ( DIR_TESTDATA . ' /feed/Rss_Block_Test.xml ' ) ,
10760 'response ' => array (
10861 'code ' => 200 ,
10962 'message ' => 'OK ' ,
@@ -141,9 +94,6 @@ private function setup_block_context() {
14194 */
14295 public function test_rss_date_rendering () {
14396
144- $ original_date_format = get_option ( 'date_format ' );
145- $ original_gmt_offset = get_option ( 'gmt_offset ' );
146-
14797 update_option ( 'date_format ' , 'F j, Y ' );
14898 // We set to UTC+9 to test timezone conversion.
14999 update_option ( 'gmt_offset ' , 9 );
@@ -166,14 +116,6 @@ public function test_rss_date_rendering() {
166116
167117 $ this ->assertStringContainsString ( 'March 19, 2025 ' , $ rendered_html , 'Formatted date not found in rendered HTML ' );
168118
169- if ( preg_match ( '/<time datetime="([^"]*)"/ ' , $ rendered_html , $ matches ) ) {
170- $ datetime_attr = $ matches [1 ];
171- $ this ->assertStringContainsString ( '2025-03-19 ' , $ datetime_attr , 'ISO datetime format missing expected date ' );
172- } else {
173- $ this ->fail ( 'Could not find datetime attribute in time element ' );
174- }
175-
176- update_option ( 'date_format ' , $ original_date_format );
177- update_option ( 'gmt_offset ' , $ original_gmt_offset );
119+ $ this ->assertMatchesRegularExpression ( '/<time datetime="[^"]*2025-03-19[^"]*"/ ' , $ rendered_html , 'ISO datetime format missing expected date ' );
178120 }
179121}
0 commit comments