File: 12hatom.t

package info (click to toggle)
libhtml-microformats-perl 0.105-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,340 kB
  • sloc: perl: 14,121; makefile: 10; sh: 1
file content (81 lines) | stat: -rw-r--r-- 2,188 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use Test::More tests => 10;
use HTML::Microformats;

my $html = <<'HTML';
<html lang=en>

	<div class="hfeed" id="news">
		<div class="hentry hnews">
			<h1 class="entry-title">First</h1>
			<p class="entry-content"><span class="geo">World (<span class="latitude">0</span>, <span class="longitude">0</span>)</span></p>
		</div>
	</div>

	<div class="hfeed" id="blog">
		<div class="hentry">
			<h1 class="entry-title">First</h1>
			<p class="entry-summary entry-content">Hello</p>
			<p class="entry-content"><a href="foo" rev="vote-for">World</a></p>
		</div>
		<div class="hentry">
			<h1 class="entry-title">Second</h1>
			<div class="author vcard"><span class="fn">Bob</span></div>
		</div>
	</div>

	<address class="author vcard"><span class="fn">Alice</span></address>

HTML

my $document = HTML::Microformats->new_document($html, 'http://example.com/');
$document->assume_all_profiles;

my ($blog, $news)  = sort { $a->element->getAttribute('id') cmp $b->element->getAttribute('id') }
	$document->objects('hAtom');

my @blog_entries = @{ $blog->get_entry };
is( scalar @blog_entries,
	2,
	"Two entries found in blog.");

my @news_entries = @{ $news->get_entry };
is( scalar @news_entries,
	1,
	"One entry found in news.");

ok($news_entries[0]->isa('HTML::Microformats::Format::hNews'),
	'News item is a news item');
	
ok($news_entries[0]->isa('HTML::Microformats::Format::hEntry'),
	'News item is an entry');

is($news_entries[0]->data->{title},
	'First',
	'News item has correct entry-title');

is($news_entries[0]->get_author->[0]->get_fn,
	'Alice',
	'Implied author');

is($news_entries[0]->get_geo->[0]->get_latitude,
	'0',
	'News item has a geo');

my ($votelink) = $document->objects('VoteLinks');
is($votelink->get_voter->[0]->get_fn,
	'Alice',
	'hEntry propagates authors to VoteLinks');

is($blog_entries[0]->data->{content},
	'HelloWorld',
	'Multiple entry-content elements concatenated');

is($document->model->count_statements(
		undef,
		RDF::Trine::Node::Resource->new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
		RDF::Trine::Node::Resource->new('http://bblfish.net/work/atom-owl/2006-06-06/#Entry'),
		),
	3,
	'Three atom:Entry resources output (RDF)');