| 1 |
# $Id$ |
|---|
| 2 |
|
|---|
| 3 |
use strict; |
|---|
| 4 |
|
|---|
| 5 |
use Test::More tests => 71; |
|---|
| 6 |
use XML::Atom; |
|---|
| 7 |
use XML::Atom::Entry; |
|---|
| 8 |
use XML::Atom::Person; |
|---|
| 9 |
|
|---|
| 10 |
my $entry; |
|---|
| 11 |
|
|---|
| 12 |
$entry = XML::Atom::Entry->new; |
|---|
| 13 |
$entry->title('Foo Bar'); |
|---|
| 14 |
is $entry->title, 'Foo Bar'; |
|---|
| 15 |
|
|---|
| 16 |
$entry = XML::Atom::Entry->new('t/samples/entry-ns.xml'); |
|---|
| 17 |
isa_ok $entry, 'XML::Atom::Entry'; |
|---|
| 18 |
is $entry->title, 'Unit Test 1'; |
|---|
| 19 |
|
|---|
| 20 |
$entry = XML::Atom::Entry->new(Stream => 't/samples/entry-ns.xml'); |
|---|
| 21 |
is $entry->title, 'Unit Test 1'; |
|---|
| 22 |
my $body = $entry->content->body; |
|---|
| 23 |
ok $body; |
|---|
| 24 |
like $body, qr/^<img src="foo.gif" align="left"/; |
|---|
| 25 |
like $body, qr/This is what you get when you do unit testing\./; |
|---|
| 26 |
|
|---|
| 27 |
$entry = XML::Atom::Entry->new(Stream => 't/samples/entry-full.xml'); |
|---|
| 28 |
is $entry->title, 'Guest Author'; |
|---|
| 29 |
is $entry->id, 'tag:typepad.com:post:75207'; |
|---|
| 30 |
is $entry->issued, '2003-07-21T02:47:34-07:00'; |
|---|
| 31 |
is $entry->modified, '2003-08-22T18:36:57-07:00'; |
|---|
| 32 |
is $entry->created, '2003-07-21T02:47:34-07:00'; |
|---|
| 33 |
is $entry->summary, 'No, Ben isn\'t updating. It\'s me testing out guest author functionality....'; |
|---|
| 34 |
isa_ok $entry->author, 'XML::Atom::Person'; |
|---|
| 35 |
is $entry->author->name, 'Mena'; |
|---|
| 36 |
$entry->author->name('Ben'); |
|---|
| 37 |
is $entry->author->url, 'http://mena.typepad.com/'; |
|---|
| 38 |
my $dc = XML::Atom::Namespace->new(dc => 'http://purl.org/dc/elements/1.1/'); |
|---|
| 39 |
is $entry->get($dc->subject), 'Food'; |
|---|
| 40 |
my @subj = $entry->getlist($dc->subject); |
|---|
| 41 |
is scalar(@subj), 2; |
|---|
| 42 |
is $subj[0], 'Food'; |
|---|
| 43 |
is $subj[1], 'Cats'; |
|---|
| 44 |
isa_ok $entry->content, 'XML::Atom::Content'; |
|---|
| 45 |
is $entry->content->body, '<p>No, Ben isn\'t updating. It\'s me testing out guest author functionality.</p>'; |
|---|
| 46 |
|
|---|
| 47 |
my @link = $entry->link; |
|---|
| 48 |
is scalar(@link), 2; |
|---|
| 49 |
is $link[0]->rel, 'alternate'; |
|---|
| 50 |
is $link[0]->type, 'text/html'; |
|---|
| 51 |
is $link[0]->href, 'http://ben.stupidfool.org/typepad/2003/07/guest_author.html'; |
|---|
| 52 |
is $link[1]->rel, 'service.edit'; |
|---|
| 53 |
is $link[1]->type, 'application/x.atom+xml'; |
|---|
| 54 |
is $link[1]->href, 'http://www.example.com/atom/entry_id=75207'; |
|---|
| 55 |
is $link[1]->title, 'Edit'; |
|---|
| 56 |
|
|---|
| 57 |
my @links = $entry->links; |
|---|
| 58 |
is scalar(@links), 2; |
|---|
| 59 |
is $links[0]->rel, 'alternate'; |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
my $link = $entry->link; |
|---|
| 63 |
isa_ok $link, 'XML::Atom::Link'; |
|---|
| 64 |
is $link->rel, 'alternate'; |
|---|
| 65 |
is $link->type, 'text/html'; |
|---|
| 66 |
is $link->href, 'http://ben.stupidfool.org/typepad/2003/07/guest_author.html'; |
|---|
| 67 |
|
|---|
| 68 |
$link = XML::Atom::Link->new; |
|---|
| 69 |
$link->title('Number Three'); |
|---|
| 70 |
$link->rel('service.post'); |
|---|
| 71 |
$link->href('http://www.example.com/atom'); |
|---|
| 72 |
$link->type('application/x.atom+xml'); |
|---|
| 73 |
|
|---|
| 74 |
$entry->add_link($link); |
|---|
| 75 |
@link = $entry->link; |
|---|
| 76 |
is scalar(@link), 3; |
|---|
| 77 |
is $link[2]->rel, 'service.post'; |
|---|
| 78 |
is $link[2]->type, 'application/x.atom+xml'; |
|---|
| 79 |
is $link[2]->href, 'http://www.example.com/atom'; |
|---|
| 80 |
is $link[2]->title, 'Number Three'; |
|---|
| 81 |
|
|---|
| 82 |
## xxx test setting/getting different content encodings |
|---|
| 83 |
## xxx encodings |
|---|
| 84 |
## xxx Doc param |
|---|
| 85 |
|
|---|
| 86 |
$entry->title('Foo Bar'); |
|---|
| 87 |
is $entry->title, 'Foo Bar'; |
|---|
| 88 |
$entry->set($dc->subject, 'Food & Drink'); |
|---|
| 89 |
is $entry->get($dc->subject), 'Food & Drink'; |
|---|
| 90 |
|
|---|
| 91 |
ok(my $xml = $entry->as_xml); |
|---|
| 92 |
|
|---|
| 93 |
my $entry2 = XML::Atom::Entry->new(Stream => \$xml); |
|---|
| 94 |
isa_ok $entry2, 'XML::Atom::Entry'; |
|---|
| 95 |
is $entry2->title, 'Foo Bar'; |
|---|
| 96 |
is $entry2->author->name, 'Ben'; |
|---|
| 97 |
is $entry2->get($dc->subject), 'Food & Drink'; |
|---|
| 98 |
isa_ok $entry2->content, 'XML::Atom::Content'; |
|---|
| 99 |
is $entry2->content->body, '<p>No, Ben isn\'t updating. It\'s me testing out guest author functionality.</p>'; |
|---|
| 100 |
|
|---|
| 101 |
my $entry3 = XML::Atom::Entry->new; |
|---|
| 102 |
my $author = XML::Atom::Person->new; |
|---|
| 103 |
$author->name('Melody'); |
|---|
| 104 |
is $author->name, 'Melody'; |
|---|
| 105 |
$author->email('melody@nelson.com'); |
|---|
| 106 |
$author->url('http://www.melodynelson.com/'); |
|---|
| 107 |
$entry3->title('Histoire'); |
|---|
| 108 |
ok !$entry3->author; |
|---|
| 109 |
$entry3->author($author); |
|---|
| 110 |
isa_ok $entry3->author, 'XML::Atom::Person'; |
|---|
| 111 |
is $entry3->author->name, 'Melody'; |
|---|
| 112 |
|
|---|
| 113 |
$entry = XML::Atom::Entry->new; |
|---|
| 114 |
$entry->content('<p>Not well-formed.'); |
|---|
| 115 |
is $entry->content->mode, 'escaped'; |
|---|
| 116 |
is $entry->content->body, '<p>Not well-formed.'; |
|---|
| 117 |
|
|---|
| 118 |
$entry = XML::Atom::Entry->new( Stream => \$entry->as_xml ); |
|---|
| 119 |
is $entry->content->mode, 'escaped'; |
|---|
| 120 |
is $entry->content->body, '<p>Not well-formed.'; |
|---|
| 121 |
|
|---|
| 122 |
$entry = XML::Atom::Entry->new; |
|---|
| 123 |
$entry->content("This is a test that should use base64\0."); |
|---|
| 124 |
$entry->content->type('image/gif'); |
|---|
| 125 |
is $entry->content->mode, 'base64'; |
|---|
| 126 |
is $entry->content->body, "This is a test that should use base64\0."; |
|---|
| 127 |
is $entry->content->type, 'image/gif'; |
|---|
| 128 |
|
|---|
| 129 |
$entry = XML::Atom::Entry->new( Stream => \$entry->as_xml ); |
|---|
| 130 |
is $entry->content->mode, 'base64'; |
|---|
| 131 |
is $entry->content->body, "This is a test that should use base64\0."; |
|---|
| 132 |
is $entry->content->type, 'image/gif'; |
|---|
| 133 |
|
|---|
| 134 |
my $ns = XML::Atom::Namespace->new(list => "http://www.sixapart.com/atom/list#"); |
|---|
| 135 |
$link->set($ns, type => "Books"); |
|---|
| 136 |
$entry->add_link($link); |
|---|
| 137 |
$xml = $entry->as_xml; |
|---|
| 138 |
like $xml, qr/list:type="Books"/; |
|---|
| 139 |
|
|---|
| 140 |
$entry->set($dc, "subject" => "Weblog"); |
|---|
| 141 |
|
|---|
| 142 |
like $entry->as_xml, qr/<dc:subject .*>Weblog<\/dc:subject>/; |
|---|
| 143 |
|
|---|
| 144 |
$entry->add($dc, "subject" => "Tech"); |
|---|
| 145 |
like $entry->as_xml, qr/<dc:subject .*>Weblog<\/dc:subject>/; |
|---|
| 146 |
like $entry->as_xml, qr/<dc:subject .*>Tech<\/dc:subject>/; |
|---|
| 147 |
|
|---|
| 148 |
# re-set |
|---|
| 149 |
$entry->set($dc, "subject" => "Weblog"); |
|---|
| 150 |
like $entry->as_xml, qr/<dc:subject .*>Weblog<\/dc:subject>/; |
|---|
| 151 |
|
|---|
| 152 |
# euc-jp feed |
|---|
| 153 |
$entry = XML::Atom::Entry->new('t/samples/entry-euc.xml'); |
|---|
| 154 |
is $entry->title, 'ã²ã¹ããªãŒãµãŒ'; |
|---|
| 155 |
is $entry->content->body, '<p>æ¥æ¬èªã®ãã£ãŒã</p>'; |
|---|