File: 11-entry.t

package info (click to toggle)
libxml-atom-perl 0.23-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 420 kB
  • ctags: 264
  • sloc: perl: 3,357; xml: 663; makefile: 51
file content (155 lines) | stat: -rw-r--r-- 5,114 bytes parent folder | download
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# $Id$

use strict;

use Test::More tests => 71;
use XML::Atom;
use XML::Atom::Entry;
use XML::Atom::Person;

my $entry;

$entry = XML::Atom::Entry->new;
$entry->title('Foo Bar');
is $entry->title, 'Foo Bar';

$entry = XML::Atom::Entry->new('t/samples/entry-ns.xml');
isa_ok $entry, 'XML::Atom::Entry';
is $entry->title, 'Unit Test 1';

$entry = XML::Atom::Entry->new(Stream => 't/samples/entry-ns.xml');
is $entry->title, 'Unit Test 1';
my $body = $entry->content->body;
ok $body;
like $body, qr/^<img src="foo.gif" align="left"/;
like $body, qr/This is what you get when you do unit testing\./;

$entry = XML::Atom::Entry->new(Stream => 't/samples/entry-full.xml');
is $entry->title, 'Guest Author';
is $entry->id, 'tag:typepad.com:post:75207';
is $entry->issued, '2003-07-21T02:47:34-07:00';
is $entry->modified, '2003-08-22T18:36:57-07:00';
is $entry->created, '2003-07-21T02:47:34-07:00';
is $entry->summary, 'No, Ben isn\'t updating. It\'s me testing out guest author functionality....';
isa_ok $entry->author, 'XML::Atom::Person';
is $entry->author->name, 'Mena';
$entry->author->name('Ben');
is $entry->author->url, 'http://mena.typepad.com/';
my $dc = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/');
is $entry->get($dc->subject), 'Food';
my @subj = $entry->getlist($dc->subject);
is scalar(@subj), 2;
is $subj[0], 'Food';
is $subj[1], 'Cats';
isa_ok $entry->content, 'XML::Atom::Content';
is $entry->content->body, '<p>No, Ben isn\'t updating. It\'s me testing out guest author functionality.</p>';

my @link = $entry->link;
is scalar(@link), 2;
is $link[0]->rel, 'alternate';
is $link[0]->type, 'text/html';
is $link[0]->href, 'http://ben.stupidfool.org/typepad/2003/07/guest_author.html';
is $link[1]->rel, 'service.edit';
is $link[1]->type, 'application/x.atom+xml';
is $link[1]->href, 'http://www.example.com/atom/entry_id=75207';
is $link[1]->title, 'Edit';

my @links = $entry->links;
is scalar(@links), 2;
is $links[0]->rel, 'alternate';


my $link = $entry->link;
isa_ok $link, 'XML::Atom::Link';
is $link->rel, 'alternate';
is $link->type, 'text/html';
is $link->href, 'http://ben.stupidfool.org/typepad/2003/07/guest_author.html';

$link = XML::Atom::Link->new;
$link->title('Number Three');
$link->rel('service.post');
$link->href('http://www.example.com/atom');
$link->type('application/x.atom+xml');

$entry->add_link($link);
@link = $entry->link;
is scalar(@link), 3;
is $link[2]->rel, 'service.post';
is $link[2]->type, 'application/x.atom+xml';
is $link[2]->href, 'http://www.example.com/atom';
is $link[2]->title, 'Number Three';

## xxx test setting/getting different content encodings
## xxx encodings
## xxx Doc param

$entry->title('Foo Bar');
is $entry->title, 'Foo Bar';
$entry->set($dc->subject, 'Food & Drink');
is $entry->get($dc->subject), 'Food & Drink';

ok(my $xml = $entry->as_xml);

my $entry2 = XML::Atom::Entry->new(Stream => \$xml);
isa_ok $entry2, 'XML::Atom::Entry';
is $entry2->title, 'Foo Bar';
is $entry2->author->name, 'Ben';
is $entry2->get($dc->subject), 'Food & Drink';
isa_ok $entry2->content, 'XML::Atom::Content';
is $entry2->content->body, '<p>No, Ben isn\'t updating. It\'s me testing out guest author functionality.</p>';

my $entry3 = XML::Atom::Entry->new;
my $author = XML::Atom::Person->new;
$author->name('Melody');
is $author->name, 'Melody';
$author->email('melody@nelson.com');
$author->url('http://www.melodynelson.com/');
$entry3->title('Histoire');
ok !$entry3->author;
$entry3->author($author);
isa_ok $entry3->author, 'XML::Atom::Person';
is $entry3->author->name, 'Melody';

$entry = XML::Atom::Entry->new;
$entry->content('<p>Not well-formed.');
is $entry->content->mode, 'escaped';
is $entry->content->body, '<p>Not well-formed.';

$entry = XML::Atom::Entry->new( Stream => \$entry->as_xml );
is $entry->content->mode, 'escaped';
is $entry->content->body, '<p>Not well-formed.';

$entry = XML::Atom::Entry->new;
$entry->content("This is a test that should use base64\0.");
$entry->content->type('image/gif');
is $entry->content->mode, 'base64';
is $entry->content->body, "This is a test that should use base64\0.";
is $entry->content->type, 'image/gif';

$entry = XML::Atom::Entry->new( Stream => \$entry->as_xml );
is $entry->content->mode, 'base64';
is $entry->content->body, "This is a test that should use base64\0.";
is $entry->content->type, 'image/gif';

my $ns = XML::Atom::Namespace->new(list => "http://www.sixapart.com/atom/list#");
$link->set($ns, type => "Books");
$entry->add_link($link);
$xml = $entry->as_xml;
like $xml, qr/list:type="Books"/;

$entry->set($dc, "subject" => "Weblog");

like $entry->as_xml, qr/<dc:subject .*>Weblog<\/dc:subject>/;

$entry->add($dc, "subject" => "Tech");
like $entry->as_xml, qr/<dc:subject .*>Weblog<\/dc:subject>/;
like $entry->as_xml, qr/<dc:subject .*>Tech<\/dc:subject>/;

# re-set
$entry->set($dc, "subject" => "Weblog");
like $entry->as_xml, qr/<dc:subject .*>Weblog<\/dc:subject>/;

# euc-jp feed
$entry = XML::Atom::Entry->new('t/samples/entry-euc.xml');
is $entry->title, 'ゲストオーサー';
is $entry->content->body, '<p>日本語のフィード</p>';