Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraftbj committed Feb 7, 2025
1 parent e214b8c commit 0b4a8fd
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,6 @@ public function test_news_sitemap_item_to_xml() {
),
);

$xml = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL
. '<dummy>'
. '<url><loc>http://example.com/blog-url-about-stuff</loc>'
. "<lastmod>$timestamp</lastmod>"
. '<news:news>'
. '<news:publication>'
. '<news:name>Blog about stuff</news:name>'
. '<news:language>en</news:language>'
. '</news:publication>'
. '<news:title>Stuff with stuff to escape, like less than signs: &lt; and ampersands: &amp;</news:title>'
. "<news:publication_date>$timestamp</news:publication_date>"
. '<news:genres>Blog with some already escaped stuff: &amp;amp;&amp;#321;</news:genres>'
. '</news:news>'
. '</url></dummy>' . PHP_EOL;

foreach (
array(
new Jetpack_Sitemap_Buffer_Dummy( JP_SITEMAP_MAX_ITEMS, JP_SITEMAP_MAX_BYTES, $timestamp ),
Expand All @@ -249,9 +234,24 @@ public function test_news_sitemap_item_to_xml() {
) {
$buffer->append( $array );

// Normalize the XML by removing whitespace between tags and normalizing newlines
$actual = preg_replace( '/>\s+</', '><', $buffer->contents() );
$actual = str_replace( "\r\n", "\n", $actual );

$expected = '<?xml version="1.0" encoding="UTF-8"?><dummy><url><loc>http://example.com/blog-url-about-stuff</loc>'
. "<lastmod>$timestamp</lastmod>"
. '<news:news><news:publication>'
. '<news:name>Blog about stuff</news:name>'
. '<news:language>en</news:language>'
. '</news:publication>'
. '<news:title>Stuff with stuff to escape, like less than signs: &lt; and ampersands: &amp;</news:title>'
. "<news:publication_date>$timestamp</news:publication_date>"
. '<news:genres>Blog with some already escaped stuff: &amp;amp;&amp;#321;</news:genres>'
. '</news:news></url></dummy>' . "\n";

$this->assertEquals(
$xml,
$buffer->contents(),
$expected,
$actual,
get_class( $buffer )
);
}
Expand Down

0 comments on commit 0b4a8fd

Please sign in to comment.