File: 14-multi-enclosures.t

package info (click to toggle)
libxml-feed-perl 0.52%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 440 kB
  • ctags: 123
  • sloc: perl: 1,081; xml: 606; sh: 51; makefile: 2
file content (59 lines) | stat: -rw-r--r-- 4,397 bytes parent folder | download | duplicates (4)
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
#!perl -w

use strict;
use Test::More; 
use XML::Feed;
use XML::Feed::Enclosure;

$XML::Feed::MULTIPLE_ENCLOSURES=1;

my @formats = qw(atom rss20);
plan tests => scalar(@formats)*38;

foreach my $format (@formats) {
    ok (my $feed      = XML::Feed->parse("t/samples/$format-multi-enclosure.xml"), "Parsed $format");
    my ($entry)       = $feed->entries;
    ok (my @enclosures = $entry->enclosure,                                   "Got enclosure");
    ok ($enclosures[0]->isa("XML::Feed::Enclosure"),                             "Object isa XML::Feed::Enclosure");
    is ($enclosures[0]->type,   "audio/mpeg",                                    "Got the enclosure mime type");
    is ($enclosures[0]->length, "2478719",                                       "Got enclosure length");
    is ($enclosures[0]->url,    "http://example.com/sample_podcast.mp3",         "Got enclosure url");
    ok ($enclosures[1]->isa("XML::Feed::Enclosure"),                             "Object isa XML::Feed::Enclosure");
    is ($enclosures[1]->type,   "video/mpeg",                                    "Got the enclosure mime type");
    is ($enclosures[1]->length, "8888",                                       "Got enclosure length");
    is ($enclosures[1]->url,    "http://example.com/sample_movie.mpg",         "Got enclosure url");

    ok (my $tmp       = XML::Feed::Enclosure->new({ type => "image/jpeg" }), "Created a new enclosure");
    is ($tmp->type,         "image/jpeg",                                    "Got type back");
    ok ($tmp->url("http://example.com/sample_image.jpg"),                    "Set url");
    ok ($tmp->length("1337"),                                                "Set length");
    ok ($entry->enclosure($tmp),                                             "Set the enclosure");

    ok (@enclosures    = $entry->enclosure,                                   "Got enclosure again");
    ok ($enclosures[-1]->isa("XML::Feed::Enclosure"),                             "Object still isa XML::Feed::Enclosure");
    is ($enclosures[-1]->type,   "image/jpeg",                                    "Got the enclosure mime type");
    is ($enclosures[-1]->length, "1337",                                          "Got enclosure length again");
    is ($enclosures[-1]->url,    "http://example.com/sample_image.jpg",           "Got enclosure url again");

    my $xml = $feed->as_xml;
    ok ($feed         = XML::Feed->parse(\$xml),                             "Parsed xml again");
    ok (@enclosures    = $entry->enclosure,                                   "Got enclosure again");
    ok ($enclosures[0]->isa("XML::Feed::Enclosure"),                             "Object isa XML::Feed::Enclosure");
    is ($enclosures[0]->type,   "audio/mpeg",                                    "Got the enclosure mime type");
    is ($enclosures[0]->length, "2478719",                                       "Got enclosure length");
    is ($enclosures[0]->url,    "http://example.com/sample_podcast.mp3",         "Got enclosure url");
    ok ($enclosures[1]->isa("XML::Feed::Enclosure"),                             "Object isa XML::Feed::Enclosure");
    is ($enclosures[1]->type,   "video/mpeg",                                    "Got the enclosure mime type");
    is ($enclosures[1]->length, "8888",                                       "Got enclosure length");
    is ($enclosures[1]->url,    "http://example.com/sample_movie.mpg",         "Got enclosure url");
    ok ($enclosures[2]->isa("XML::Feed::Enclosure"),                             "Object still isa XML::Feed::Enclosure");
    is ($enclosures[2]->type,   "image/jpeg",                                    "Got the enclosure mime type");
    is ($enclosures[2]->length, "1337",                                          "Got enclosure length again");
    is ($enclosures[2]->url,    "http://example.com/sample_image.jpg",           "Got enclosure url again");
    ok ($enclosures[-1]->isa("XML::Feed::Enclosure"),                             "Object still isa XML::Feed::Enclosure");
    is ($enclosures[-1]->type,   "image/jpeg",                                    "Got the enclosure mime type");
    is ($enclosures[-1]->length, "1337",                                          "Got enclosure length again");
    is ($enclosures[-1]->url,    "http://example.com/sample_image.jpg",           "Got enclosure url again");


}