# -*-perl-*-
use strict;
use Test::More 'no_plan';
use lib "$ENV{LJHOME}/cgi-bin";
require "parsefeed.pl";
require 'ljlib.pl';
## These test cases are based roughly on Phil Ringnalda's eight
conformance tests:
##
my $testfeed = sub {
my $entrybody = shift;
my $contents = qq{
testing:atom:feedtest atom feedtesting2007-01-08T23:40:33Ztesting:atom:feed:entry2006-09-14T07:39:07Z
$entrybody
};
my ($feed, $error) = LJ::ParseFeed::parse_feed($contents);
return $feed->{'items'}->[0];
};
my $testtitle = sub {
my $titleelem = shift;
my $contents = qq{
$titleelem
content content content
};
my $item = $testfeed->($contents);
return $item->{'subject'};
};
my $testcontent = sub {
my $contentelem = shift;
my $contents = qq{
kumquats cheese blogosphere
$contentelem
};
my $item = $testfeed->($contents);
return $item->{'text'};
};
#$testtitle->("<title>");
# When type="html", the contents should be escaped HTML
# The correct result is the content with one level of escaping removed
is($testtitle->(qq{]]>}), "<title>", "Title: HTML + CDATA");
is($testtitle->(qq{<title>}), "<title>", "Title: HTML + Entities");
is($testtitle->(qq{<title>}), "<title>", "Title: HTML + Numeric character references");
# When type="text", the contents are escaped plain text
# Since LiveJournal expects HTML in the subject field, parsefeed should
# be returning the text with HTML escaping applied.
is($testtitle->(qq{]]>}), "<title>", "Title: Text + CDATA");
is($testtitle->(qq{<title>}), "<title>", "Title: Text + Entity");
is($testtitle->(qq{<title>}), "<title>", "Title: Text + Numeric character references");
# When type="xhtml" the content is interpreted as normal XML with no special
# escaping. Therefore it should be returned basically verbatim, with no
# extra escaping or de-escaping.
is($testtitle->(qq{
}, "Title: XHTML + Numeric character references");
# Now do the same eight tests but on the entry content instead
is($testcontent->(qq{]]>}), "<content>", "Content: HTML + CDATA");
is($testcontent->(qq{<content>}), "<content>", "Content: HTML + Entities");
is($testcontent->(qq{<content>}), "<content>", "Content: HTML + Numeric character references");
is($testcontent->(qq{]]>}), "<content>", "Content: Text + CDATA");
is($testcontent->(qq{<content>}), "<content>", "Content: Text + Entity");
is($testcontent->(qq{<content>}), "<content>", "Content: Text + Numeric character references");
is($testcontent->(qq{