| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
use Test::More; |
| 4 |
|
| 5 |
use XML::Feed; |
| 6 |
use DateTime; |
| 7 |
|
| 8 |
my $now = DateTime->now(); |
| 9 |
|
| 10 |
my $feed = XML::Feed->new('Atom'); |
| 11 |
$feed->title("foo"); |
| 12 |
$feed->description("Atom 1.0 feed"); |
| 13 |
$feed->link("http://example.org/"); |
| 14 |
$feed->id("tag:cpan.org;xml-feed-atom"); |
| 15 |
$feed->modified($now); |
| 16 |
|
| 17 |
my $entry = XML::Feed::Entry->new('Atom'); |
| 18 |
$entry->title("1st Entry"); |
| 19 |
$entry->link("http://example.org/"); |
| 20 |
$entry->category("blah"); |
| 21 |
$entry->content("<p>Hello world.</p>"); |
| 22 |
$entry->id("tag:cpan.org;xml-feed-atom-entry"); |
| 23 |
$entry->modified($now); |
| 24 |
|
| 25 |
$feed->add_entry($entry); |
| 26 |
|
| 27 |
my $xml = $feed->as_xml; |
| 28 |
like $xml, qr!<feed xmlns="http://www.w3.org/2005/Atom"!; |
| 29 |
like $xml, qr!<content .*type="xhtml">!; |
| 30 |
like $xml, qr!<div xmlns="http://www.w3.org/1999/xhtml">!; |
| 31 |
|
| 32 |
# roundtrip |
| 33 |
$feed = XML::Feed->parse(\$xml); |
| 34 |
is $feed->format, 'Atom'; |
| 35 |
is $feed->title, "foo"; |
| 36 |
is $feed->description, "Atom 1.0 feed"; |
| 37 |
is $feed->link, "http://example.org/"; |
| 38 |
is $feed->id, "tag:cpan.org;xml-feed-atom"; |
| 39 |
is $feed->modified->iso8601, $now->iso8601; |
| 40 |
|
| 41 |
my @entries = $feed->entries; |
| 42 |
is @entries, 1; |
| 43 |
$entry = $entries[0]; |
| 44 |
|
| 45 |
is $entry->title, '1st Entry'; |
| 46 |
is $entry->link, 'http://example.org/'; |
| 47 |
is $entry->category, 'blah'; |
| 48 |
is $entry->content->type, 'text/html'; |
| 49 |
like $entry->content->body, qr!\s*<p>Hello world.</p>\s*!s; |
| 50 |
|
| 51 |
is $entry->id, "tag:cpan.org;xml-feed-atom-entry"; |
| 52 |
is $entry->modified->iso8601, $now->iso8601; |
| 53 |
|
| 54 |
done_testing(); |