Commit | Line | Data |
fe71566d |
1 | # $Id: 01-parse.t 933 2004-07-29 16:43:33Z btrott $ |
0d5e38d1 |
2 | |
3 | use strict; |
4 | use Test; |
5 | use XML::Feed; |
6 | use URI; |
7 | |
a749d9b9 |
8 | BEGIN { plan tests => 70 } |
0d5e38d1 |
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'); |
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; |
65 | my $entry = ($feed->entries)[0]; |
66 | ok(!$entry->summary->body); |
67 | ok($entry->content->body =~ m!<p>This is a test.</p>!); |