2013-02-17 08:46:31 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
BEGIN {
|
2014-01-25 22:08:22 +01:00
|
|
|
eval q{use XML::Feed; use HTML::Parser; use HTML::LinkExtor; use File::MimeInfo};
|
2013-02-17 08:46:31 +01:00
|
|
|
if ($@) {
|
2013-02-18 22:24:22 +01:00
|
|
|
eval q{use Test::More skip_all =>
|
2014-01-25 22:08:22 +01:00
|
|
|
"XML::Feed and/or HTML::Parser or File::MimeInfo not available"};
|
2013-02-17 08:46:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2015-11-30 18:33:00 +01:00
|
|
|
eval q{use Test::More tests => 137};
|
2013-02-17 08:46:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-19 00:01:13 +01:00
|
|
|
use Cwd;
|
2013-02-22 05:12:15 +01:00
|
|
|
use File::Basename;
|
2013-02-19 00:01:13 +01:00
|
|
|
|
2015-11-30 18:33:00 +01:00
|
|
|
my $installed = $ENV{INSTALLED_TESTS};
|
|
|
|
|
|
|
|
my @base_command;
|
|
|
|
if ($installed) {
|
|
|
|
ok(1, "running installed");
|
|
|
|
@base_command = qw(ikiwiki);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ok(! system("make -s ikiwiki.out"));
|
2016-07-28 10:50:09 +02:00
|
|
|
@base_command = ("perl", "-I".getcwd, qw(./ikiwiki.out
|
2015-11-30 18:33:00 +01:00
|
|
|
--underlaydir=underlays/basewiki
|
|
|
|
--set underlaydirbase=underlays
|
2016-07-28 10:50:09 +02:00
|
|
|
--templatedir=templates));
|
2015-11-30 18:33:00 +01:00
|
|
|
}
|
|
|
|
|
2013-02-18 22:24:22 +01:00
|
|
|
my $tmp = 't/tmp';
|
|
|
|
my $statedir = 't/tinypodcast/.ikiwiki';
|
|
|
|
|
2013-02-22 05:12:15 +01:00
|
|
|
sub podcast {
|
|
|
|
my $podcast_style = shift;
|
|
|
|
|
2013-02-17 08:46:31 +01:00
|
|
|
my $baseurl = 'http://example.com';
|
2015-11-30 18:33:00 +01:00
|
|
|
my @command = (@base_command, qw(--plugin inline --rss --atom));
|
2015-03-01 17:14:32 +01:00
|
|
|
push @command, "--url=$baseurl", qw(t/tinypodcast), "$tmp/out";
|
2013-02-17 16:09:05 +01:00
|
|
|
|
2013-02-19 00:19:45 +01:00
|
|
|
ok(! system("mkdir $tmp"),
|
|
|
|
q{setup});
|
|
|
|
ok(! system(@command),
|
|
|
|
q{build});
|
2013-02-17 08:46:31 +01:00
|
|
|
|
|
|
|
my %media_types = (
|
2013-02-18 22:48:44 +01:00
|
|
|
'simplepost' => undef,
|
2013-02-17 08:46:31 +01:00
|
|
|
'piano.mp3' => 'audio/mpeg',
|
|
|
|
'scroll.3gp' => 'video/3gpp',
|
2014-06-13 16:25:27 +02:00
|
|
|
'walter.ogg' => 'audio/ogg',
|
2013-02-17 08:46:31 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
for my $format (qw(atom rss)) {
|
2013-02-22 05:12:15 +01:00
|
|
|
my $feed = XML::Feed->parse("$tmp/out/$podcast_style/index.$format");
|
2013-02-17 08:46:31 +01:00
|
|
|
|
2013-02-22 05:12:15 +01:00
|
|
|
is($feed->title, $podcast_style,
|
2013-02-17 16:52:23 +01:00
|
|
|
qq{$format feed title});
|
2013-02-22 05:12:15 +01:00
|
|
|
is($feed->link, "$baseurl/$podcast_style/",
|
2013-02-17 16:52:23 +01:00
|
|
|
qq{$format feed link});
|
2013-02-18 22:48:44 +01:00
|
|
|
is($feed->description, 'wiki',
|
2013-02-17 16:52:23 +01:00
|
|
|
qq{$format feed description});
|
2013-02-17 08:46:31 +01:00
|
|
|
if ('atom' eq $format) {
|
2013-02-18 22:48:44 +01:00
|
|
|
is($feed->author, $feed->description,
|
2013-02-17 16:52:23 +01:00
|
|
|
qq{$format feed author});
|
2013-02-18 22:48:44 +01:00
|
|
|
is($feed->id, $feed->link,
|
2013-02-17 16:52:23 +01:00
|
|
|
qq{$format feed id});
|
|
|
|
is($feed->generator, "ikiwiki",
|
|
|
|
qq{$format feed generator});
|
2013-02-17 08:46:31 +01:00
|
|
|
}
|
|
|
|
|
2013-02-21 03:16:19 +01:00
|
|
|
for my $entry ($feed->entries) {
|
|
|
|
my $title = $entry->title;
|
|
|
|
my $url = $entry->id;
|
|
|
|
my $body = $entry->content->body;
|
|
|
|
my $enclosure = $entry->enclosure;
|
|
|
|
|
|
|
|
is($entry->link, $url, qq{$format $title link});
|
|
|
|
isnt($entry->issued, undef,
|
|
|
|
qq{$format $title issued date});
|
|
|
|
isnt($entry->modified, undef,
|
|
|
|
qq{$format $title modified date});
|
|
|
|
|
|
|
|
if (defined $media_types{$title}) {
|
|
|
|
is($url, "$baseurl/$title",
|
|
|
|
qq{$format $title id});
|
|
|
|
is($body, undef,
|
|
|
|
qq{$format $title no body text});
|
|
|
|
is($enclosure->url, $url,
|
|
|
|
qq{$format $title enclosure url});
|
|
|
|
is($enclosure->type, $media_types{$title},
|
|
|
|
qq{$format $title enclosure type});
|
|
|
|
cmp_ok($enclosure->length, '>', 0,
|
|
|
|
qq{$format $title enclosure length});
|
|
|
|
}
|
|
|
|
else {
|
2013-02-22 05:12:15 +01:00
|
|
|
# XXX hack hack hack
|
2013-02-21 03:16:19 +01:00
|
|
|
my $expected_id = "$baseurl/$title/";
|
|
|
|
$expected_id =~ s/\ /_/g;
|
|
|
|
|
|
|
|
is($url, $expected_id,
|
|
|
|
qq{$format $title id});
|
|
|
|
isnt($body, undef,
|
|
|
|
qq{$format $title body text});
|
2013-02-22 05:12:15 +01:00
|
|
|
|
|
|
|
if ('fancy' eq $podcast_style) {
|
|
|
|
isnt($enclosure, undef,
|
|
|
|
qq{$format $title enclosure});
|
|
|
|
my $filename = basename($enclosure->url);
|
|
|
|
is($enclosure->type, $media_types{$filename},
|
|
|
|
qq{$format $title enclosure type});
|
|
|
|
cmp_ok($enclosure->length, '>', 0,
|
|
|
|
qq{$format $title enclosure length});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
is($enclosure, undef,
|
|
|
|
qq{$format $title no enclosure});
|
|
|
|
}
|
2013-02-21 03:16:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ok(! system("rm -rf $tmp $statedir"), q{teardown});
|
|
|
|
}
|
|
|
|
|
2013-02-18 22:24:22 +01:00
|
|
|
sub single_page_html {
|
2015-11-30 18:33:00 +01:00
|
|
|
my @command = @base_command;
|
2013-02-18 22:24:22 +01:00
|
|
|
push @command, qw(t/tinypodcast), "$tmp/out";
|
|
|
|
|
2013-02-19 00:19:45 +01:00
|
|
|
ok(! system("mkdir $tmp"),
|
|
|
|
q{setup});
|
|
|
|
ok(! system(@command),
|
|
|
|
q{build});
|
2013-02-19 00:01:13 +01:00
|
|
|
|
2013-02-18 22:48:44 +01:00
|
|
|
my $html = "$tmp/out/pianopost/index.html";
|
2013-02-19 00:19:45 +01:00
|
|
|
like(_extract_html_content($html, 'content'), qr/has content and/m,
|
|
|
|
q{html body text});
|
2013-06-27 02:21:33 +02:00
|
|
|
like(_extract_html_content($html, 'enclosure'), qr/Download/m,
|
2013-02-19 00:19:45 +01:00
|
|
|
q{html enclosure});
|
2013-02-19 00:01:13 +01:00
|
|
|
my ($href) = _extract_html_links($html, 'piano');
|
2013-02-21 01:14:20 +01:00
|
|
|
is($href, '/piano.mp3',
|
2015-03-01 17:14:32 +01:00
|
|
|
q{html enclosure sans --url is site-absolute});
|
2013-02-19 00:19:45 +01:00
|
|
|
|
|
|
|
$html = "$tmp/out/attempted_multiple_enclosures/index.html";
|
|
|
|
like(_extract_html_content($html, 'content'), qr/has content and/m,
|
|
|
|
q{html body text});
|
2013-06-27 02:21:33 +02:00
|
|
|
like(_extract_html_content($html, 'enclosure'), qr/Download/m,
|
2013-02-19 00:19:45 +01:00
|
|
|
q{html enclosure});
|
|
|
|
($href) = _extract_html_links($html, 'walter');
|
2013-02-21 01:14:20 +01:00
|
|
|
is($href, '/walter.ogg',
|
2015-03-01 17:14:32 +01:00
|
|
|
q{html enclosure sans --url is site-absolute});
|
2013-02-21 01:14:20 +01:00
|
|
|
|
|
|
|
my $baseurl = 'http://example.com';
|
2015-03-01 17:14:32 +01:00
|
|
|
ok(! system(@command, "--url=$baseurl", q{--rebuild}));
|
2013-02-21 01:14:20 +01:00
|
|
|
|
|
|
|
$html = "$tmp/out/pianopost/index.html";
|
|
|
|
($href) = _extract_html_links($html, 'piano');
|
|
|
|
is($href, "$baseurl/piano.mp3",
|
2015-03-01 17:14:32 +01:00
|
|
|
q{html enclosure with --url is fully absolute});
|
2013-02-21 01:14:20 +01:00
|
|
|
|
|
|
|
$html = "$tmp/out/attempted_multiple_enclosures/index.html";
|
|
|
|
($href) = _extract_html_links($html, 'walter');
|
|
|
|
is($href, "$baseurl/walter.ogg",
|
2015-03-01 17:14:32 +01:00
|
|
|
q{html enclosure with --url is fully absolute});
|
2013-02-18 22:24:22 +01:00
|
|
|
|
2013-02-19 00:01:13 +01:00
|
|
|
ok(! system("rm -rf $tmp $statedir"), q{teardown});
|
2013-02-18 22:24:22 +01:00
|
|
|
}
|
|
|
|
|
2013-02-19 01:34:20 +01:00
|
|
|
sub inlined_pages_html {
|
2015-11-30 18:33:00 +01:00
|
|
|
my @command = (@base_command, qw(--plugin inline));
|
2013-02-19 01:34:20 +01:00
|
|
|
push @command, qw(t/tinypodcast), "$tmp/out";
|
|
|
|
|
|
|
|
ok(! system("mkdir $tmp"),
|
|
|
|
q{setup});
|
|
|
|
ok(! system(@command),
|
|
|
|
q{build});
|
|
|
|
|
|
|
|
my $html = "$tmp/out/fancy/index.html";
|
|
|
|
my $contents = _extract_html_content($html, 'content');
|
|
|
|
like($contents, qr/has content and an/m,
|
|
|
|
q{html body text from pianopost});
|
|
|
|
like($contents, qr/has content and only one/m,
|
|
|
|
q{html body text from attempted_multiple_enclosures});
|
|
|
|
my $enclosures = _extract_html_content($html, 'inlineenclosure');
|
2013-06-27 02:21:33 +02:00
|
|
|
like($enclosures, qr/Download/m,
|
2013-02-19 01:34:20 +01:00
|
|
|
q{html enclosure});
|
|
|
|
my ($href) = _extract_html_links($html, 'piano.mp3');
|
2013-02-21 01:14:20 +01:00
|
|
|
is($href, '/piano.mp3',
|
2015-03-01 17:14:32 +01:00
|
|
|
q{html enclosure from pianopost sans --url});
|
2013-02-19 01:34:20 +01:00
|
|
|
($href) = _extract_html_links($html, 'walter.ogg');
|
2013-02-21 01:14:20 +01:00
|
|
|
is($href, '/walter.ogg',
|
2015-03-01 17:14:32 +01:00
|
|
|
q{html enclosure from attempted_multiple_enclosures sans --url});
|
2013-02-19 01:34:20 +01:00
|
|
|
|
|
|
|
ok(! system("rm -rf $tmp $statedir"), q{teardown});
|
|
|
|
}
|
|
|
|
|
2013-02-18 22:24:22 +01:00
|
|
|
sub _extract_html_content {
|
|
|
|
my ($file, $desired_id, $desired_tag) = @_;
|
|
|
|
$desired_tag = 'div' unless defined $desired_tag;
|
|
|
|
|
|
|
|
my $p = HTML::Parser->new(api_version => 3);
|
|
|
|
my $content = '';
|
|
|
|
|
|
|
|
$p->handler(start => sub {
|
|
|
|
my ($tag, $self, $attr) = @_;
|
|
|
|
return if $tag ne $desired_tag;
|
|
|
|
return unless exists $attr->{id} && $attr->{id} eq $desired_id;
|
|
|
|
|
|
|
|
$self->handler(text => sub {
|
|
|
|
my ($dtext) = @_;
|
|
|
|
$content .= $dtext;
|
|
|
|
}, "dtext");
|
|
|
|
}, "tagname,self,attr");
|
|
|
|
|
|
|
|
$p->parse_file($file) || die $!;
|
|
|
|
|
|
|
|
return $content;
|
2013-02-17 08:46:31 +01:00
|
|
|
}
|
|
|
|
|
2013-02-19 00:01:13 +01:00
|
|
|
sub _extract_html_links {
|
|
|
|
my ($file, $desired_value) = @_;
|
|
|
|
|
|
|
|
my @hrefs = ();
|
|
|
|
|
|
|
|
my $p = HTML::LinkExtor->new(sub {
|
|
|
|
my ($tag, %attr) = @_;
|
|
|
|
return if $tag ne 'a';
|
|
|
|
return unless $attr{href} =~ qr/$desired_value/;
|
|
|
|
push(@hrefs, values %attr);
|
|
|
|
}, getcwd() . '/' . $file);
|
|
|
|
|
|
|
|
$p->parse_file($file);
|
|
|
|
|
|
|
|
return @hrefs;
|
|
|
|
}
|
|
|
|
|
2013-02-22 05:12:15 +01:00
|
|
|
podcast('simple');
|
2013-02-18 22:24:22 +01:00
|
|
|
single_page_html();
|
2013-02-19 01:34:20 +01:00
|
|
|
inlined_pages_html();
|
2013-02-22 05:12:15 +01:00
|
|
|
podcast('fancy');
|