| 1 |
#!perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Test::More; |
| 6 |
use XML::Feed; |
| 7 |
use XML::Feed::Enclosure; |
| 8 |
|
| 9 |
$XML::Feed::MULTIPLE_ENCLOSURES=1; |
| 10 |
|
| 11 |
my @formats = qw(atom rss20); |
| 12 |
plan tests => scalar(@formats)*38; |
| 13 |
|
| 14 |
foreach my $format (@formats) { |
| 15 |
ok (my $feed = XML::Feed->parse("t/samples/$format-multi-enclosure.xml"), "Parsed $format"); |
| 16 |
my ($entry) = $feed->entries; |
| 17 |
ok (my @enclosures = $entry->enclosure, "Got enclosure"); |
| 18 |
ok ($enclosures[0]->isa("XML::Feed::Enclosure"), "Object isa XML::Feed::Enclosure"); |
| 19 |
is ($enclosures[0]->type, "audio/mpeg", "Got the enclosure mime type"); |
| 20 |
is ($enclosures[0]->length, "2478719", "Got enclosure length"); |
| 21 |
is ($enclosures[0]->url, "http://example.com/sample_podcast.mp3", "Got enclosure url"); |
| 22 |
ok ($enclosures[1]->isa("XML::Feed::Enclosure"), "Object isa XML::Feed::Enclosure"); |
| 23 |
is ($enclosures[1]->type, "video/mpeg", "Got the enclosure mime type"); |
| 24 |
is ($enclosures[1]->length, "8888", "Got enclosure length"); |
| 25 |
is ($enclosures[1]->url, "http://example.com/sample_movie.mpg", "Got enclosure url"); |
| 26 |
|
| 27 |
ok (my $tmp = XML::Feed::Enclosure->new({ type => "image/jpeg" }), "Created a new enclosure"); |
| 28 |
is ($tmp->type, "image/jpeg", "Got type back"); |
| 29 |
ok ($tmp->url("http://example.com/sample_image.jpg"), "Set url"); |
| 30 |
ok ($tmp->length("1337"), "Set length"); |
| 31 |
ok ($entry->enclosure($tmp), "Set the enclosure"); |
| 32 |
|
| 33 |
ok (@enclosures = $entry->enclosure, "Got enclosure again"); |
| 34 |
ok ($enclosures[-1]->isa("XML::Feed::Enclosure"), "Object still isa XML::Feed::Enclosure"); |
| 35 |
is ($enclosures[-1]->type, "image/jpeg", "Got the enclosure mime type"); |
| 36 |
is ($enclosures[-1]->length, "1337", "Got enclosure length again"); |
| 37 |
is ($enclosures[-1]->url, "http://example.com/sample_image.jpg", "Got enclosure url again"); |
| 38 |
|
| 39 |
my $xml = $feed->as_xml; |
| 40 |
ok ($feed = XML::Feed->parse(\$xml), "Parsed xml again"); |
| 41 |
ok (@enclosures = $entry->enclosure, "Got enclosure again"); |
| 42 |
ok ($enclosures[0]->isa("XML::Feed::Enclosure"), "Object isa XML::Feed::Enclosure"); |
| 43 |
is ($enclosures[0]->type, "audio/mpeg", "Got the enclosure mime type"); |
| 44 |
is ($enclosures[0]->length, "2478719", "Got enclosure length"); |
| 45 |
is ($enclosures[0]->url, "http://example.com/sample_podcast.mp3", "Got enclosure url"); |
| 46 |
ok ($enclosures[1]->isa("XML::Feed::Enclosure"), "Object isa XML::Feed::Enclosure"); |
| 47 |
is ($enclosures[1]->type, "video/mpeg", "Got the enclosure mime type"); |
| 48 |
is ($enclosures[1]->length, "8888", "Got enclosure length"); |
| 49 |
is ($enclosures[1]->url, "http://example.com/sample_movie.mpg", "Got enclosure url"); |
| 50 |
ok ($enclosures[2]->isa("XML::Feed::Enclosure"), "Object still isa XML::Feed::Enclosure"); |
| 51 |
is ($enclosures[2]->type, "image/jpeg", "Got the enclosure mime type"); |
| 52 |
is ($enclosures[2]->length, "1337", "Got enclosure length again"); |
| 53 |
is ($enclosures[2]->url, "http://example.com/sample_image.jpg", "Got enclosure url again"); |
| 54 |
ok ($enclosures[-1]->isa("XML::Feed::Enclosure"), "Object still isa XML::Feed::Enclosure"); |
| 55 |
is ($enclosures[-1]->type, "image/jpeg", "Got the enclosure mime type"); |
| 56 |
is ($enclosures[-1]->length, "1337", "Got enclosure length again"); |
| 57 |
is ($enclosures[-1]->url, "http://example.com/sample_image.jpg", "Got enclosure url again"); |
| 58 |
|
| 59 |
|
| 60 |
} |