Bump version for release
[catagits/XML-Feed.git] / t / 07-atom10-create.t
CommitLineData
c4d4c98e 1use strict;
2use Test::More;
3
c4d4c98e 4use XML::Feed;
e8fcbc5b 5use DateTime;
6
7my $now = DateTime->now();
c4d4c98e 8
9my $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
16my $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
26my $xml = $feed->as_xml;
27like $xml, qr!<feed xmlns="http://www.w3.org/2005/Atom"!;
28like $xml, qr!<content .*type="xhtml">!;
29like $xml, qr!<div xmlns="http://www.w3.org/1999/xhtml">!;
30
31# roundtrip
32$feed = XML::Feed->parse(\$xml);
33is $feed->format, 'Atom';
34is $feed->title, "foo";
35is $feed->description, "Atom 1.0 feed";
36is $feed->link, "http://example.org/";
e8fcbc5b 37is $feed->id, "tag:cpan.org;xml-feed-atom";
fb5c1908 38is $feed->modified->iso8601, $now->iso8601;
c4d4c98e 39
40my @entries = $feed->entries;
41is @entries, 1;
42$entry = $entries[0];
43
44is $entry->title, '1st Entry';
45is $entry->link, 'http://example.org/';
46is $entry->category, 'blah';
47is $entry->content->type, 'text/html';
48like $entry->content->body, qr!\s*<p>Hello world.</p>\s*!s;
49
e8fcbc5b 50is $entry->id, "tag:cpan.org;xml-feed-atom-entry";
fb5c1908 51is $entry->modified->iso8601, $now->iso8601;
c4d4c98e 52
fb5c1908 53done_testing();