]> sipb.mit.edu Git - ikiwiki.git/blob - t/podcast.t
Document that podcasts are text XOR enclosure.
[ikiwiki.git] / t / podcast.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 BEGIN {
6         eval q{use XML::Feed};
7         if ($@) {
8                 eval q{use Test::More skip_all => "XML::Feed not available"};
9         }
10         else {
11                 eval q{use Test::More tests => 72};
12         }
13 }
14
15 sub simple_podcast {
16         my $baseurl = 'http://example.com';
17         my @command = (qw(./ikiwiki.out -plugin inline -rss -atom));
18         push @command, qw(-underlaydir=underlays/basewiki);
19         push @command, qw(-set underlaydirbase=underlays -templatedir=templates);
20         push @command, "-url=$baseurl", qw(t/tinypodcast t/tmp/out);
21
22         ok(! system("mkdir t/tmp"));
23         ok(! system(@command));
24
25         my %media_types = (
26                 'post'          => undef,
27                 'piano.mp3'     => 'audio/mpeg',
28                 'scroll.3gp'    => 'video/3gpp',
29                 'walter.ogg'    => 'video/x-theora+ogg',
30         );
31
32         for my $format (qw(atom rss)) {
33                 my $feed = XML::Feed->parse("t/tmp/out/index.$format");
34
35                 is($feed->title, 'wiki',
36                         qq{$format feed title});
37                 is($feed->link, "$baseurl/",
38                         qq{$format feed link});
39                 is($feed->description, $feed->title,
40                         qq{$format feed description});
41                 if ('atom' eq $format) {
42                         is($feed->author, $feed->title,
43                                 qq{$format feed author});
44                         is($feed->id, "$baseurl/",
45                                 qq{$format feed id});
46                         is($feed->generator, "ikiwiki",
47                                 qq{$format feed generator});
48                 }
49
50                 for my $entry ($feed->entries) {
51                         my $title = $entry->title;
52                         my $url = $entry->id;
53                         my $body = $entry->content->body;
54                         my $enclosure = $entry->enclosure;
55
56                         is($entry->link, $url, qq{$format $title link});
57                         isnt($entry->issued, undef,
58                                 qq{$format $title issued date});
59                         isnt($entry->modified, undef,
60                                 qq{$format $title modified date});
61
62                         if (defined $media_types{$title}) {
63                                 is($url, "$baseurl/$title",
64                                         qq{$format $title id});
65                                 is($body, undef,
66                                         qq{$format $title no body text});
67                                 is($enclosure->url, $url,
68                                         qq{$format $title enclosure url});
69                                 is($enclosure->type, $media_types{$title},
70                                         qq{$format $title enclosure type});
71                                 cmp_ok($enclosure->length, '>', 0,
72                                         qq{$format $title enclosure length});
73                         }
74                         else {
75                                 is($url, "$baseurl/$title/",
76                                         qq{$format $title id});
77                                 isnt($body, undef,
78                                         qq{$format $title body text});
79                                 is($enclosure, undef,
80                                         qq{$format $title no enclosure});
81                         }
82                 }
83         }
84
85         ok(! system("rm -rf t/tmp t/tinypodcast/.ikiwiki"));
86 }
87
88 simple_podcast();