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