Bump version for release
[catagits/XML-Feed.git] / t / 07-atom10-create.t
1 use strict;
2 use Test::More;
3
4 use XML::Feed;
5 use DateTime;
6
7 my $now = DateTime->now();
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/");
13 $feed->id("tag:cpan.org;xml-feed-atom");
14 $feed->modified($now);
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>");
21 $entry->id("tag:cpan.org;xml-feed-atom-entry");
22 $entry->modified($now);
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/";
37 is $feed->id, "tag:cpan.org;xml-feed-atom";
38 is $feed->modified->iso8601, $now->iso8601;
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
50 is $entry->id, "tag:cpan.org;xml-feed-atom-entry";
51 is $entry->modified->iso8601, $now->iso8601;
52
53 done_testing();