root/XML-Atom-0.22/t/13-atom1.t

Revision 397, 2.0 kB (checked in by miya, 2 years ago)

--

Line 
1 use strict;
2 use Test::More tests => 23;
3 use XML::Atom::Feed;
4
5 sub is_deeply_method;
6
7 my $file = "t/samples/atom-1.0.xml";
8 open my $fh, $file or die "$file: $!";
9
10 my $feed = XML::Atom::Feed->new(Stream => $fh);
11 isa_ok $feed, 'XML::Atom::Feed';
12
13 is $feed->title, 'dive into mark', 'atom:title';
14 is $feed->version, '1.0', 'atom:version based on namespace';
15 is $feed->updated, "2005-07-11T12:29:29Z", 'atom:updated';
16
17 my @link = $feed->link;
18 is @link, 2, "2 links";
19 is_deeply_method $link[0], { rel => 'alternate', type => 'text/html', hreflang => 'en', href => 'http://example.org/' };
20 is_deeply_method $link[1], { rel => 'self', type => 'application/atom+xml', href => 'http://example.org/feed.atom' };
21
22 my @entry = $feed->entries;
23 is @entry, 1, "1 entry";
24 my $entry = $entry[0];
25 is $entry->title, 'Atom draft-07 snapshot';
26
27 my @entry_link = $entry->link;
28 is_deeply_method $entry_link[0], { rel => 'alternate', type => 'text/html', href => 'http://example.org/2005/04/02/atom' };
29 is_deeply_method $entry_link[1], { rel => 'enclosure', type => 'audio/mpeg', length => 1337, href => 'http://example.org/audio/ph34r_my_podcast.mp3' };
30
31 is $entry->author->name, 'Mark Pilgrim';
32 is $entry->author->uri, 'http://example.org/';
33 is $entry->author->email, 'f8dy@example.com';
34
35 my @contrib = $entry->contributor;
36 is @contrib, 2, "2 contribs";
37 is_deeply_method $contrib[0], { name => 'Sam Ruby' };
38 is_deeply_method $contrib[1], { name => 'Joe Gregorio' };
39
40 @contrib = $entry->contributors;
41 is @contrib, 2, "2 contribs (moniker)";
42 is_deeply_method $contrib[0], { name => 'Sam Ruby' };
43 is_deeply_method $contrib[1], { name => 'Joe Gregorio' };
44
45 my $contrib = $entry->contributor;
46 is $contrib->name, 'Sam Ruby', 'testing scalar context';
47
48 is_deeply_method $entry->content, { type => 'xhtml', lang => 'en', base => 'http://diveintomark.org/' };
49 like $entry->content->body, qr!<p>.*<i>\[Update: The Atom draft is finished.\]</i>.*</p>!s;
50
51 sub is_deeply_method {
52     my($thing, $hashref, $msg) = @_;
53     my %copy = map { $_ => $thing->$_ } keys %$hashref;
54     is_deeply \%copy, $hashref, $msg;
55 }
Note: See TracBrowser for help on using the browser.