Fix double encoding bug?
[catagits/XML-Feed.git] / t / 07-atom10-create.t
1 use strict;
2 use Test::More;
3
4 plan tests => 17;
5
6 use XML::Feed;
7 use DateTime;
8
9 my $now = DateTime->now();
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/");
15 $feed->id("tag:cpan.org;xml-feed-atom");
16 $feed->updated($now);
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>");
23 $entry->id("tag:cpan.org;xml-feed-atom-entry");
24 $entry->updated($now);
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/";
39 is $feed->id, "tag:cpan.org;xml-feed-atom";
40 is "".$feed->updated, "".$now;
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
52 is $entry->id, "tag:cpan.org;xml-feed-atom-entry";
53 is "".$entry->updated, "".$now;
54
55