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