do
'./t/test.pl'
;
my
(
$id
,
$port
) = init();
write_text(
"test-$id/rss2sample.opml"
,
<<"EOT");
<opml version="2.0">
<body>
<outline title="العربيّة"
</body>
</opml>
EOT
my
$rss
=
<<'EOT';
<?xml version="1.0" encoding='UTF-8'?>
<rss version="2.0">
<channel>
<title>Foo & Bar</title>
<pubDate>Mon, 13 Jan 2020 23:16:01 +0100</pubDate>
<item>
<title>السّلام عليك</title>
<description><style>some CSS, I guess</style><em>D&D</em> is not bad!<br>You'll like <span class='p-name'>Foo & Bar</span>.</description>
<author><span class='p-author h-card'>Alex Schroeder</span></author>
<pubDate>Mon, 13 Jan 2020 23:16:01 +0100</pubDate>
</item>
<item>
<title>CDATA</title>
<description><![CDATA[1<2]]></description>
<pubDate>Tue, 14 Jan 2020 23:16:01 +0100</pubDate>
</item>
</channel>
</rss>
EOT
start_daemon(encode_utf8
$rss
);
Jupiter::update_cache(
"test-$id/rss2sample.opml"
);
stop_daemon();
Jupiter::make_html(
"test-$id/rss2sample.html"
,
"test-$id/rss2sample.xml"
,
"test-$id/rss2sample.opml"
);
ok(-f
"test-$id/rss2sample.html"
,
"HTML was generated"
);
my
$doc
= XML::LibXML->load_html(
location
=>
"test-$id/rss2sample.html"
);
is(
$doc
->findvalue(
'//li/a[position()=2]'
),
"Foo & Bar"
,
"Encoded feed title matches"
);
is(
$doc
->findvalue(
'//div[@class="post"][position()=2]/h3/a[position()=2]'
),
"السّلام عليك"
,
"Encoded item title matches"
);
is(
$doc
->findvalue(
'//div[@class="post"][position()=2]/h3/a[position()=1]'
),
"Foo & Bar"
,
"Encoded feed title matches again"
);
is(
$doc
->findnodes(
'//div[@class="content"]'
)->get_node(2)->toString(),
q(<div class="content">D&D is not bad!<span class="paragraph">¶ </span>You'll like Foo & Bar.</div>)
,
"Content HTML matches"
);
like(
$doc
->findnodes(
'//div[@class="permalink"]'
)->get_node(2)->toString(),
qr(by Alex Schroeder)
,
"Author HTML matches"
);
unlike(
$doc
->findvalue(
'//div[@class="content"]'
),
qr/CSS/
,
"Style is stripped"
);
is(
$doc
->findnodes(
'//div[@class="content"]'
)->get_node(1)->toString(),
q(<div class="content">1<2</div>)
,
"CDATA matches"
);
ok(-f
"test-$id/rss2sample.xml"
,
"RSS was generated"
);
$doc
= XML::LibXML->load_xml(
location
=>
"test-$id/rss2sample.xml"
);
like((
$doc
->findnodes(
'/rss/channel/item/description'
))[0]->toString,
qr/<!\[CDATA\[1<2\]\]>/
,
"Encoded content matches"
);
like((
$doc
->findnodes(
'/rss/channel/item/description'
))[1]->toString,
qr/<em>D&D<\/
em
>
; is not bad!
<
;br
>
;You
'll like <span class='
p-name'
>
;Foo
&
; Bar
<
;\/span
>
;\./,
"Encoded content matches"
);
done_testing;