change the User Agent string
[catagits/XML-Feed.git] / t / 02-create.t
CommitLineData
973e1f9e 1use strict;
fe6cfa83 2use Test::More;
973e1f9e 3use XML::Feed;
4use XML::Feed::Entry;
5use XML::Feed::Content;
6use DateTime;
7
8for my $format (qw( Atom RSS )) {
9 my $feed = XML::Feed->new($format);
4e7b539f 10 isa_ok($feed, 'XML::Feed::Format::' . $format);
973e1f9e 11 like($feed->format, qr/^$format/, 'Format is correct');
12 $feed->title('My Feed');
13 is($feed->title, 'My Feed', 'feed title is correct');
14 $feed->link('http://www.example.com/');
15 is($feed->link, 'http://www.example.com/', 'feed link is correct');
16 $feed->description('Wow!');
17 is($feed->description, 'Wow!', 'feed description is correct');
18 is($feed->tagline, 'Wow!', 'tagline works as alias');
19 $feed->tagline('Again');
20 is($feed->tagline, 'Again', 'setting via tagline works');
21 $feed->language('en_US');
22 is($feed->language, 'en_US', 'feed language is correct');
23 $feed->author('Ben');
24 is($feed->author, 'Ben', 'feed author is correct');
25 $feed->copyright('Copyright 2005 Me');
26 is($feed->copyright, 'Copyright 2005 Me', 'feed copyright is correct');
27 my $now = DateTime->now;
28 $feed->modified($now);
29 isa_ok($feed->modified, 'DateTime', 'modified returns a DateTime');
30 is($feed->modified->iso8601, $now->iso8601, 'feed modified is correct');
31 $feed->generator('Movable Type');
32 is($feed->generator, 'Movable Type', 'feed generator is correct');
33 ok($feed->as_xml, 'as_xml returns something');
34
35 my $entry = XML::Feed::Entry->new($format);
4e7b539f 36 isa_ok($entry, 'XML::Feed::Entry::Format::' . $format);
973e1f9e 37 $entry->title('Foo Bar');
38 is($entry->title, 'Foo Bar', 'entry title is correct');
39 $entry->link('http://www.example.com/foo/bar.html');
40 is($entry->link, 'http://www.example.com/foo/bar.html', 'entry link is correct');
41 $entry->summary('This is a summary.');
42 isa_ok($entry->summary, 'XML::Feed::Content');
43 is($entry->summary->body, 'This is a summary.', 'entry summary is correct');
44 $entry->content('This is the content.');
45 isa_ok($entry->content, 'XML::Feed::Content');
46 is($entry->content->type, 'text/html', 'entry content type is correct');
47 is($entry->content->body, 'This is the content.', 'entry content body is correct');
48 $entry->content(XML::Feed::Content->new({
49 body => 'This is the content (again).',
50 type => 'text/plain',
51 }));
52 isa_ok($entry->content, 'XML::Feed::Content');
53 is($entry->content->body, 'This is the content (again).', 'setting with XML::Feed::Content works');
54 $entry->category('Television');
55 is($entry->category, 'Television', 'entry category is correct');
56 $entry->author('Foo Baz');
57 is($entry->author, 'Foo Baz', 'entry author is correct');
58 $entry->id('foo:bar-15132');
59 is($entry->id, 'foo:bar-15132', 'entry id is correct');
60 my $dt = DateTime->now;
61 $entry->issued($dt);
62 isa_ok($entry->issued, 'DateTime');
63 is($entry->issued->iso8601, $dt->iso8601, 'entry issued is correct');
64 $entry->modified($dt);
65 isa_ok($entry->modified, 'DateTime');
66 is($entry->modified->iso8601, $dt->iso8601, 'entry modified is correct');
67
68 $feed->add_entry($entry);
69 my @e = $feed->entries;
70 is(scalar @e, 1, 'One post in the feed');
71 is($e[0]->title, 'Foo Bar', 'Correct post');
fe3b3201 72 is($e[0]->content->body, 'This is the content (again).', 'content is still correct');
73
74 if ($format eq 'Atom') {
75 like $feed->as_xml, qr/This is the content/;
76 }
9a36f82c 77 if ($format eq 'RSS') {
78 like $feed->as_xml, qr{xmlns:dcterms="http://purl.org/dc/terms/"};
79 }
80
81 $feed->self_link("http://tor.tld/my-feed.rss");
82
83 if ($format eq "RSS")
84 {
85 like ($feed->as_xml(), qr{\Q<atom:link href="http://tor.tld/my-feed.rss" rel="self" type="application/rss+xml"/>\E},
86 "Feed contains the atom:link");
87 }
88 elsif ($format eq "Atom")
89 {
90 like ($feed->as_xml(), qr{\Q<link rel="self" href="http://tor.tld/my-feed.rss" type="application/atom+xml"/>\E},
91 "Feed contains the atom:link");
02de1790 92
93 my %rfc5005 = (
94 first_link => "http://tor.tld/my-feed.xml?page=1",
95 next_link => "http://tor.tld/my-feed.xml?page=4",
96 previous_link => "http://tor.tld/my-feed.xml?page=2",
97 last_link => "http://tor.tld/my-feed.xml?page=99",
98 current_link => "http://tor.tld/archive/2.xml",
99 prev_archive_link => "http://tor.tld/archive/1.xml",
100 next_archive_link => "http://tor.tld/archive/3.xml",
101 );
102
103 while ( my($name,$url) = each(%rfc5005) ) {
104 $feed->$name($url);
105 $name =~ s/_link$//;
106 $name =~ s/_/-/g;
107 like ($feed->as_xml(), qr{\Q<link rel="$name" href="$url" type="application/atom+xml"/>\E},
108 "Feed contains an RFC 5005 rel=\"$name\" link");
109 }
9a36f82c 110 }
111
973e1f9e 112}
fe6cfa83 113
114done_testing;