Load XML-Feed-0.02 into trunk.
[catagits/XML-Feed.git] / t / 01-parse.t
CommitLineData
a749d9b9 1# $Id: 01-parse.t,v 1.5 2004/07/29 16:43:33 btrott Exp $
0d5e38d1 2
3use strict;
4use Test;
5use XML::Feed;
6use URI;
7
a749d9b9 8BEGIN { plan tests => 70 }
0d5e38d1 9
10my %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.
17my $feed;
18my $file = 't/samples/atom.xml';
19ok($feed = XML::Feed->parse($file));
20ok($feed->title, 'First Weblog');
21open my $fh, $file or die "Can't open $file: $!";
22ok($feed = XML::Feed->parse($fh));
23ok($feed->title, 'First Weblog');
24seek $fh, 0, 0;
25my $xml = do { local $/; <$fh> };
26ok($feed = XML::Feed->parse(\$xml));
27ok($feed->title, 'First Weblog');
28ok($feed = XML::Feed->parse(URI->new("file:$file")));
29ok($feed->title, 'First Weblog');
30
31## Then try calling all of the unified API methods.
32for 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');
a749d9b9 56 ok($entry->content->body =~ /<p>Hello!<\/p>/);
57 ok($entry->summary->body, 'Hello!...');
0d5e38d1 58 ok($entry->category, 'Travel');
59 ok($entry->author, 'Melody');
60 ok($entry->id);
61}
a749d9b9 62
63$feed = XML::Feed->parse('t/samples/rss20-no-summary.xml')
64 or die XML::Feed->errstr;
65my $entry = ($feed->entries)[0];
66ok(!$entry->summary->body);
67ok($entry->content->body =~ m!<p>This is a test.</p>!);