4 use Test::More tests => 75;
9 't/samples/atom.xml' => 'Atom',
10 't/samples/rss10.xml' => 'RSS 1.0',
11 't/samples/rss20.xml' => 'RSS 2.0',
14 ## First, test all of the various ways of calling parse.
16 my $file = 't/samples/atom.xml';
17 $feed = XML::Feed->parse($file);
18 isa_ok($feed, 'XML::Feed::Format::Atom');
19 is($feed->title, 'First Weblog');
20 open my $fh, $file or die "Can't open $file: $!";
21 $feed = XML::Feed->parse($fh);
22 isa_ok($feed, 'XML::Feed::Format::Atom');
23 is($feed->title, 'First Weblog');
25 my $xml = do { local $/; <$fh> };
26 $feed = XML::Feed->parse(\$xml);
27 isa_ok($feed, 'XML::Feed::Format::Atom');
28 is($feed->title, 'First Weblog');
29 $feed = XML::Feed->parse(URI->new("file:$file"));
30 isa_ok($feed, 'XML::Feed::Format::Atom');
31 is($feed->title, 'First Weblog');
33 ## Then try calling all of the unified API methods.
34 for my $file (sort keys %Feeds) {
35 my $feed = XML::Feed->parse($file) or die XML::Feed->errstr;
36 my($subclass) = $Feeds{$file} =~ /^(\w+)/;
37 isa_ok($feed, 'XML::Feed::Format::' . $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.');
44 my $dt = $feed->modified;
45 isa_ok($dt, 'DateTime');
46 $dt->set_time_zone('UTC');
47 is($dt->iso8601, '2004-05-30T07:39:57');
48 is($feed->author, 'Melody');
50 my @entries = $feed->entries;
51 is(scalar @entries, 2);
52 my $entry = $entries[0];
53 is($entry->title, 'Entry Two');
54 is($entry->link, 'http://localhost/weblog/2004/05/entry_two.html');
56 isa_ok($dt, 'DateTime');
57 $dt->set_time_zone('UTC');
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)[0], 'Travel');
62 is($entry->category, 'Travel');
63 is($entry->author, 'Melody');
67 $feed = XML::Feed->parse('t/samples/rss20-no-summary.xml')
68 or die XML::Feed->errstr;
69 my $entry = ($feed->entries)[0];
70 ok(!$entry->summary->body);
71 like($entry->content->body, qr/<p>This is a test.<\/p>/);
73 $feed = XML::Feed->parse('t/samples/rss10-invalid-date.xml')
74 or die XML::Feed->errstr;
75 $entry = ($feed->entries)[0];
76 ok(!$entry->issued); ## Should return undef, but not die.
77 ok(!$entry->modified); ## Same.