1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
use strict;
use warnings;
use Test::More tests => 13;
use XML::RSS;
sub output_contains
{
local $Test::Builder::Level = $Test::Builder::Level + 1;
my ($rss_output, $sub_string, $msg) = @_;
my $ok = ok (index ($rss_output,
$sub_string) >= 0,
$msg
);
if (! $ok)
{
diag(
"Could not find the substring [$sub_string]"
. " in:{{{{\n$rss_output\n}}}}\n"
);
}
return $ok;
}
my $xml;
{
my $rss;
$rss = XML::RSS->new( 'xml:base' => 'http://example.com' );
# TEST
ok ($rss, "Created new rss");
# TEST
is($rss->{'xml:base'}, 'http://example.com', 'Got base');
$rss->{'xml:base'} = 'http://foo.com/';
# TEST
ok($rss->channel(
title => 'Test Feed',
link => "http://example.com",
description => "Foo",
), "Added channel");
# TEST
ok($rss->add_item(
title => 'foo',
'xml:base' => "http://foo.com/archive/",
description => {
content => "Bar",
'xml:base' => "http://foo.com/archive/1.html",
}
), "Added item");
$xml = $rss->as_rss_2_0();
# TEST
ok($xml, "Got xml");
# TEST
output_contains(
$xml,
'xml:base="http://foo.com/"',
"Found rss base"
);
# TEST
output_contains(
$xml,
'xml:base="http://foo.com/archive/"',
"Found item base"
);
# TEST
output_contains(
$xml,
'xml:base="http://foo.com/archive/1.html"',
"Found description base"
);
}
{
my $rss = XML::RSS->new;
# TEST
ok(
$rss->parse($xml, { hashrefs_instead_of_strings => 1 }),
"Reparsed xml"
);
# TEST
is(
$rss->{'xml:base'},
'http://foo.com/',
"Found parsed rss base"
);
# TEST
is(
scalar(@{$rss->{items}}),
1,
"Got 1 item"
);
my $item = $rss->{items}->[0];
# TEST
is(
$item->{'xml:base'},
'http://foo.com/archive/',
"Found parsed item base"
);
{
if (ref $item->{description} eq 'HASH') {
# TEST
is(
$item->{description}->{'xml:base'},
'http://foo.com/archive/1.html',
"Found parsed description base"
);
} else {
fail("Description is not a hash ref");
}
}
}
|