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