2ed1b3537ab0214a0456573482b3709628f0ec35
[catagits/XML-Feed.git] / t / 01-parse.t
1 # $Id: 01-parse.t,v 1.2 2004/05/30 09:39:52 btrott Exp $
2
3 use strict;
4 use Test;
5 use XML::Feed;
6 use URI;
7
8 BEGIN { plan tests => 68 }
9
10 my %Feeds = (
11     't/samples/atom.xml' => 'Atom',
12     't/samples/rss10.xml' => 'RSS 1.0',
13     't/samples/rss20.xml' => 'RSS 2.0',
14 );
15
16 ## First, test all of the various ways of calling parse.
17 my $feed;
18 my $file = 't/samples/atom.xml';
19 ok($feed = XML::Feed->parse($file));
20 ok($feed->title, 'First Weblog');
21 open my $fh, $file or die "Can't open $file: $!";
22 ok($feed = XML::Feed->parse($fh));
23 ok($feed->title, 'First Weblog');
24 seek $fh, 0, 0;
25 my $xml = do { local $/; <$fh> };
26 ok($feed = XML::Feed->parse(\$xml));
27 ok($feed->title, 'First Weblog');
28 ok($feed = XML::Feed->parse(URI->new("file:$file")));
29 ok($feed->title, 'First Weblog');
30
31 ## Then try calling all of the unified API methods.
32 for my $file (sort keys %Feeds) {
33     my $feed = XML::Feed->parse($file) or die XML::Feed->errstr;
34     ok($feed);
35     ok($feed->format, $Feeds{$file});
36     ok($feed->language, 'en-us');
37     ok($feed->title, 'First Weblog');
38     ok($feed->link, 'http://localhost/weblog/');
39     ok($feed->tagline, 'This is a test weblog.');
40     ok($feed->description, 'This is a test weblog.');
41     my $dt = $feed->modified;
42     ok(ref($dt), 'DateTime');
43     $dt->set_time_zone('UTC');
44     ok($dt->iso8601, '2004-05-30T07:39:57');
45     ok($feed->author, 'Melody');
46
47     my @entries = $feed->entries;
48     ok(scalar @entries, 2);
49     my $entry = $entries[0];
50     ok($entry->title, 'Entry Two');
51     ok($entry->link, 'http://localhost/weblog/2004/05/entry_two.html');
52     $dt = $entry->issued;
53     ok(ref($dt), 'DateTime');
54     $dt->set_time_zone('UTC');
55     ok($dt->iso8601, '2004-05-30T07:39:25');
56     ok($entry->content =~ /<p>Hello!<\/p>/);
57     ok($entry->summary, 'Hello!...');
58     ok($entry->category, 'Travel');
59     ok($entry->author, 'Melody');
60     ok($entry->id);
61 }