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