1 |
# $Id$ |
2 |
|
3 |
use strict; |
4 |
use Test::More tests => 69; |
5 |
use XML::Feed; |
6 |
use XML::Feed::Entry; |
7 |
use XML::Feed::Content; |
8 |
use DateTime; |
9 |
|
10 |
for my $format (qw( Atom RSS )) { |
11 |
my $feed = XML::Feed->new($format); |
12 |
isa_ok($feed, 'XML::Feed::' . $format); |
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); |
38 |
isa_ok($entry, 'XML::Feed::Entry::' . $format); |
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'); |
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 |
} |
79 |
} |