File: 10hcard.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 (91 lines) | stat: -rw-r--r-- 2,178 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
82
83
84
85
86
87
88
89
90
91
use Test::More tests => 10;
use HTML::Microformats;

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

  <div class="vcard">
    <h1 class="fn org">My Org</h1>
    <p>
      <b>General Enquiries:</b>
      <span class="tel">+44 1234 567 890</span>
    </p>
    <p class="tel">
      <b><span class="type">Fax</span>:</b>
      <span class="value">+44 1234 567 891</span>
    </p>
    <p class="agent vcard">
      <span class="org">
        <abbr class="organization-name" title="My Org"></abbr>
        <b class="organization-unit fn">Help Desk</b>
      </span>
      <span class="tel">+44 1234 567 899</span>
    </p>
  </div>

HTML

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

my @cards = sort { $a->data->{fn} cmp $b->data->{fn} }
	$document->objects('hCard');

is($cards[0]->get_kind,
	'group',
	'Auto-detect group kind.');

is($cards[1]->get_kind,
	'org',
	'Auto-detect organisation kind.');

is($cards[0]->element->tagName,
	'p',
	'Can get links back to elements.');

is($cards[1]->get_tel->[0]->get_value,
	'tel:+441234567890',
	'Parsed tel without type+value');

is($cards[1]->get_tel->[1]->get_value,
	'tel:+441234567891',
	'Parsed tel with type+value');

is($cards[1]->get_agent->[0],
	$cards[0],
	'Agent works OK');
	
my $model = $document->model;

ok($model->count_statements(
		$cards[1]->id(1),
		RDF::Trine::Node::Resource->new('http://www.w3.org/2006/vcard/ns#agent'),
		$cards[0]->id(1),
		),
	"Agent works OK (RDF)"
	);

ok($model->count_statements(
		$cards[1]->id(1),
		RDF::Trine::Node::Resource->new('http://www.w3.org/2006/vcard/ns#fn'),
		RDF::Trine::Node::Literal->new('My Org', 'en'),
		),
	"Languages work OK (RDF)"
	);

ok($model->count_statements(
		$cards[1]->id(1, 'holder'),
		RDF::Trine::Node::Resource->new('http://purl.org/uF/hCard/terms/hasCard'),
		$cards[1]->id(1),
		),
	"Differentiates between vcards and their holders (RDF)"
	);

ok($model->count_statements(
		$cards[1]->id(1, 'holder'),
		RDF::Trine::Node::Resource->new('http://xmlns.com/foaf/0.1/name'),
		RDF::Trine::Node::Literal->new('My Org', 'en'),
		),
	"Infers information about vcard holder from the vcard (RDF)"
	);