root/XML-Atom-0.22/t/23-category.t

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

--

Line 
1 use strict;
2 use Test::More 'no_plan';
3
4 use XML::Atom::Feed;
5
6 my $feed = XML::Atom::Feed->new("t/samples/vox.xml");
7 my $entry = ($feed->entries)[0];
8
9 ok $entry;
10 is $entry->title, "Pirates of Caribbean - Dead Man's Chest";
11
12 my @category = $entry->category;
13 is @category, 4, 'returns list in a list context';
14 is $category[0]->term, 'disney';
15 is $category[0]->scheme, 'http://bulknews.vox.com/tags/disney/';
16 is $category[0]->label, 'disney';
17
18 my $cat = $entry->category;
19 isa_ok $cat, 'XML::Atom::Category', 'scalar context';
20 is $cat->term, 'disney';
21
22 my @categories = $entry->categories;
23 is @categories, 4, "moniker";
24
25 {
26     my $entry = XML::Atom::Entry->new( Version => 1.0 );
27     $entry->title("foo bar");
28     $entry->add_category({
29         term => "foo",
30         scheme => "http://example.org/foo#",
31         label => "foo bar",
32     });
33
34     my @cat = $entry->categories;
35     is @cat, 1;
36     is $cat[0]->term, "foo";
37     is $cat[0]->scheme, "http://example.org/foo#";
38     is $cat[0]->label, "foo bar";
39
40     $entry->add_category({
41         term => "bar",
42         scheme => "http://example.org/bar#",
43     });
44
45     @cat = $entry->categories;
46     is @cat, 2;
47     is $cat[1]->term, "bar";
48
49     my $xml = $entry->as_xml;
50     like $xml, qr!<category xmlns="http://www.w3.org/2005/Atom" term="foo" scheme="http://example.org/foo#" label="foo bar"/>!;
51     like $xml, qr!<category xmlns="http://www.w3.org/2005/Atom" term="bar" scheme="http://example.org/bar#"/>!;
52 }
53
Note: See TracBrowser for help on using the browser.