Debian Codegraph @

t/02-create.t

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