| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
|
| 4 |
use Test::More; |
| 5 |
use XML::Feed; |
| 6 |
use FindBin '$Bin'; |
| 7 |
|
| 8 |
# https://rt.cpan.org/Public/Bug/Display.html?id=76738 |
| 9 |
|
| 10 |
my $feed = XML::Feed->parse("$Bin/samples/rss-content-encoded.xml"); |
| 11 |
|
| 12 |
my @items = $feed->items; |
| 13 |
my @labels = qw/ First Second /; |
| 14 |
|
| 15 |
# XML::RSS will set $item->{content}{encoded} from <content:encoded>, |
| 16 |
# but set $item->{content} from <content>. |
| 17 |
is(ref $items[0]->unwrap->{content}, 'HASH', |
| 18 |
"$labels[0] entry set <content:encoded> as HASH ref"); |
| 19 |
ok(!ref $items[1]->unwrap->{content}, |
| 20 |
"$labels[1] entry set <content> as string"); |
| 21 |
|
| 22 |
# Both summary() and content() access content. Neither should die |
| 23 |
# trying to use a string as a HASH ref. |
| 24 |
# |
| 25 |
# Test summary() first, since setting content() will force it to a |
| 26 |
# HASH ref. |
| 27 |
for my $item (@items) { |
| 28 |
my $label = shift @labels; |
| 29 |
my $name = "\l$label entry"; |
| 30 |
|
| 31 |
my $summary = "$label Description"; |
| 32 |
is($item->summary->body, $summary, "Get old summary from $name"); |
| 33 |
|
| 34 |
$summary = "Summary for $name"; |
| 35 |
ok($item->summary($summary), "Set new summary for $name"); |
| 36 |
is($item->summary->body, $summary, "Get new summary from $name"); |
| 37 |
|
| 38 |
my $content_re = qr/^$label Content/; |
| 39 |
like($item->content->body, $content_re, "Get old content from $name"); |
| 40 |
|
| 41 |
my $content = "Content for $name"; |
| 42 |
ok($item->content($content), "Set new content for $name"); |
| 43 |
is($item->content->body, $content, "Get new content from $name"); |
| 44 |
} |
| 45 |
|
| 46 |
done_testing(); |