diff options
author | Joey Hess <joey@kitenet.net> | 2010-12-26 13:53:31 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2010-12-26 13:53:31 -0400 |
commit | 9982862925627d4714ed8b61d8b591950ed5aaa5 (patch) | |
tree | 195e8b18aee65aa2317e1287ea88393be286c1de | |
parent | 5df0718abf13e01515ddb13659949908dba92cf8 (diff) | |
parent | be6ca4c4e99c40f4c4763147c798a6f144dadc0c (diff) | |
download | ikiwiki-9982862925627d4714ed8b61d8b591950ed5aaa5.tar ikiwiki-9982862925627d4714ed8b61d8b591950ed5aaa5.tar.gz |
Merge remote branch 'smcv/ready/urlto'
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | IkiWiki.pm | 4 | ||||
-rwxr-xr-x | t/autoindex.t | 74 | ||||
-rwxr-xr-x | t/po.t | 29 | ||||
-rwxr-xr-x | t/tag.t | 45 | ||||
-rwxr-xr-x | t/urlto.t | 7 |
6 files changed, 155 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore index e9ab152b6..6b7efe5c1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ po/underlays/basewiki/*/*/*.mdwn po/underlays/directives/ikiwiki/directive/*.mdwn po/underlays_copy_stamp underlays/locale +/t/tmp/ diff --git a/IkiWiki.pm b/IkiWiki.pm index 926d42a49..bbe1ad055 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -544,7 +544,7 @@ sub checkconfig () { error(gettext("Must specify url to wiki with --url when using --cgi")); } - if (length $config{url}) { + if (defined $config{url} && length $config{url}) { eval q{use URI}; my $baseurl = URI->new($config{url}); @@ -1140,7 +1140,7 @@ sub urlto ($;$$) { my $absolute=shift; if (! length $to) { - return beautify_urlpath(baseurl($from)."index.$config{htmlext}"); + $to = 'index'; } if (! $destsources{$to}) { diff --git a/t/autoindex.t b/t/autoindex.t new file mode 100755 index 000000000..b47f2e0eb --- /dev/null +++ b/t/autoindex.t @@ -0,0 +1,74 @@ +#!/usr/bin/perl +package IkiWiki; + +use warnings; +use strict; +use Test::More; + +BEGIN { use_ok("IkiWiki"); } +BEGIN { use_ok("IkiWiki::Render"); } +BEGIN { use_ok("IkiWiki::Plugin::autoindex"); } +BEGIN { use_ok("IkiWiki::Plugin::html"); } +BEGIN { use_ok("IkiWiki::Plugin::mdwn"); } + +ok(! system("rm -rf t/tmp; mkdir t/tmp")); + +$config{verbose} = 1; +$config{srcdir} = 't/tmp'; +$config{underlaydir} = 't/tmp'; +$config{underlaydirbase} = '.'; +$config{templatedir} = 'templates'; +$config{usedirs} = 1; +$config{htmlext} = 'html'; +$config{wiki_file_chars} = "-[:alnum:]+/.:_"; +$config{userdir} = "users"; +$config{tagbase} = "tags"; +$config{default_pageext} = "mdwn"; +$config{wiki_file_prune_regexps} = [qr/^\./]; + +is(checkconfig(), 1); + +%oldrenderedfiles=%pagectime=(); +%pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks= +%destsources=%renderedfiles=%pagecase=%pagestate=(); + +# pages that (we claim) were deleted in an earlier pass +$wikistate{autoindex}{deleted}{deleted} = 1; +$wikistate{autoindex}{deleted}{expunged} = 1; +$wikistate{autoindex}{deleted}{reinstated} = 1; + +foreach my $page (qw(tags/numbers deleted/bar reinstated reinstated/foo gone/bar)) { + # we use a non-default extension for these, so they're distinguishable + # from programmatically-created pages + $pagesources{$page} = "$page.html"; + $pagemtime{$page} = $pagectime{$page} = 1000000; + writefile("$page.html", "t/tmp", "your ad here"); +} + +# "gone" disappeared just before this refresh pass so it still has a mtime +$pagemtime{gone} = $pagectime{gone} = 1000000; + +IkiWiki::Plugin::autoindex::refresh(); + +# these pages are still on record as having been deleted, because they have +# a reason to be re-created +is($wikistate{autoindex}{deleted}{deleted}, 1); +is($wikistate{autoindex}{deleted}{gone}, 1); +ok(! -f "t/tmp/deleted.mdwn"); +ok(! -f "t/tmp/gone.mdwn"); + +# this page does not exist and has no reason to be re-created, so we forget +# about it - it will be re-created if it gains sub-pages +ok(! exists $wikistate{autoindex}{deleted}{expunged}); +ok(! -f "t/tmp/expunged.mdwn"); + +# this page was re-created, so it drops off the radar +ok(! exists $wikistate{autoindex}{deleted}{reinstated}); +ok(! -f "t/tmp/reinstated.mdwn"); + +# needs creating +ok(! exists $wikistate{autoindex}{deleted}{tags}); +ok(-s "t/tmp/tags.mdwn"); + +done_testing(); +1; @@ -17,7 +17,7 @@ BEGIN { } } -use Test::More tests => 91; +use Test::More tests => 109; BEGIN { use_ok("IkiWiki"); } @@ -34,6 +34,8 @@ $config{destdir} = "$dir/dst"; $config{destdir} = "$dir/dst"; $config{underlaydirbase} = "/dev/null"; $config{underlaydir} = "/dev/null"; +$config{url} = "http://example.com"; +$config{cgiurl} = "http://example.com/ikiwiki.cgi"; $config{discussion} = 0; $config{po_master_language} = { code => 'en', name => 'English' @@ -166,11 +168,32 @@ $msgprefix="urlto (po_link_to=current)"; is(urlto('', 'index'), './index.en.html', "$msgprefix index -> ''"); is(urlto('', 'nontranslatable'), '../index.en.html', "$msgprefix nontranslatable -> ''"); is(urlto('', 'translatable.fr'), '../index.fr.html', "$msgprefix translatable.fr -> ''"); +# when asking for a semi-absolute or absolute URL, we can't know what the +# current language is, so for translatable pages we use the master language +is(urlto('nontranslatable'), '/nontranslatable/', "$msgprefix 1-arg -> nontranslatable"); +is(urlto('translatable'), '/translatable/index.en.html', "$msgprefix 1-arg -> translatable"); +is(urlto('nontranslatable', undef, 1), 'http://example.com/nontranslatable/', "$msgprefix 1-arg -> nontranslatable"); +is(urlto('index', undef, 1), 'http://example.com/index.en.html', "$msgprefix 1-arg -> index"); +is(urlto('', undef, 1), 'http://example.com/index.en.html', "$msgprefix 1-arg -> ''"); +# FIXME: should these three produce the negotiatable URL instead of the master +# language? +is(urlto(''), '/index.en.html', "$msgprefix 1-arg -> ''"); +is(urlto('index'), '/index.en.html', "$msgprefix 1-arg -> index"); +is(urlto('translatable', undef, 1), 'http://example.com/translatable/index.en.html', "$msgprefix 1-arg -> translatable"); + $config{po_link_to}='negotiated'; $msgprefix="urlto (po_link_to=negotiated)"; is(urlto('', 'index'), './', "$msgprefix index -> ''"); is(urlto('', 'nontranslatable'), '../', "$msgprefix nontranslatable -> ''"); is(urlto('', 'translatable.fr'), '../', "$msgprefix translatable.fr -> ''"); +is(urlto('nontranslatable'), '/nontranslatable/', "$msgprefix 1-arg -> nontranslatable"); +is(urlto('translatable'), '/translatable/', "$msgprefix 1-arg -> translatable"); +is(urlto(''), '/', "$msgprefix 1-arg -> ''"); +is(urlto('index'), '/', "$msgprefix 1-arg -> index"); +is(urlto('nontranslatable', undef, 1), 'http://example.com/nontranslatable/', "$msgprefix 1-arg -> nontranslatable"); +is(urlto('translatable', undef, 1), 'http://example.com/translatable/', "$msgprefix 1-arg -> translatable"); +is(urlto('index', undef, 1), 'http://example.com/', "$msgprefix 1-arg -> index"); +is(urlto('', undef, 1), 'http://example.com/', "$msgprefix 1-arg -> ''"); ### bestlink $config{po_link_to}='current'; @@ -192,6 +215,10 @@ $msgprefix="beautify_urlpath (po_link_to=negotiated)"; is(IkiWiki::beautify_urlpath('test1/index.html'), './test1/', "$msgprefix test1/index.html"); is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/', "$msgprefix test1/index.en.html"); is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/', "$msgprefix test1/index.fr.html"); +$config{po_link_to}='current'; +$msgprefix="beautify_urlpath (po_link_to=current)"; +is(IkiWiki::beautify_urlpath('test1/index.en.html'), './test1/index.en.html', "$msgprefix test1/index.en.html"); +is(IkiWiki::beautify_urlpath('test1/index.fr.html'), './test1/index.fr.html', "$msgprefix test1/index.fr.html"); ### re-scan refresh_n_scan('index.mdwn'); @@ -3,15 +3,30 @@ package IkiWiki; use warnings; use strict; -use Test::More tests => 7; +use Test::More tests => 21; BEGIN { use_ok("IkiWiki"); } +BEGIN { use_ok("IkiWiki::Render"); } +BEGIN { use_ok("IkiWiki::Plugin::mdwn"); } BEGIN { use_ok("IkiWiki::Plugin::tag"); } ok(! system("rm -rf t/tmp; mkdir t/tmp")); +$config{verbose} = 1; +$config{srcdir} = 't/tmp'; +$config{underlaydir} = 't/tmp'; +$config{templatedir} = 'templates'; +$config{usedirs} = 1; +$config{htmlext} = 'html'; +$config{wiki_file_chars} = "-[:alnum:]+/.:_"; $config{userdir} = "users"; $config{tagbase} = "tags"; +$config{tag_autocreate} = 1; +$config{default_pageext} = "mdwn"; +$config{wiki_file_prune_regexps} = [qr/^\./]; +$config{underlaydirbase} = '.'; + +is(checkconfig(), 1); %oldrenderedfiles=%pagectime=(); %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks= @@ -20,6 +35,7 @@ $config{tagbase} = "tags"; foreach my $page (qw(tags/numbers tags/letters one two alpha beta)) { $pagesources{$page} = "$page.mdwn"; $pagemtime{$page} = $pagectime{$page} = 1000000; + writefile("$page.mdwn", "t/tmp", "your ad here"); } $links{one}=[qw(tags/numbers alpha tags/letters)]; @@ -36,4 +52,31 @@ ok(!pagespec_match("two", "tagged(alpha)")); ok(pagespec_match("one", "link(tags/numbers)")); ok(pagespec_match("one", "link(alpha)")); +# emulate preprocessing [[!tag numbers primes lucky]] on page "seven", causing +# the "numbers" and "primes" tag pages to be auto-created +IkiWiki::Plugin::tag::preprocess_tag(page => "seven", numbers => undef, primes => undef, lucky => undef); +is($autofiles{"tags/lucky.mdwn"}{plugin}, "tag"); +is($autofiles{"tags/numbers.mdwn"}{plugin}, "tag"); +is($autofiles{"tags/primes.mdwn"}{plugin}, "tag"); + +ok(!-e "t/tmp/tags/lucky.mdwn"); +my (%pages, @del); +IkiWiki::gen_autofile("tags/lucky.mdwn", \%pages, \@del); +is_deeply(\%pages, {"t/tmp/tags/lucky" => 1}) || diag explain \%pages; +is_deeply(\@del, []) || diag explain \@del; +ok(-s "t/tmp/tags/lucky.mdwn"); + +# generating an autofile that already exists does nothing +%pages = @del = (); +IkiWiki::gen_autofile("tags/numbers.mdwn", \%pages, \@del); +is_deeply(\%pages, {}) || diag explain \%pages; +is_deeply(\@del, []) || diag explain \@del; + +# generating an autofile that we just deleted does nothing +%pages = (); +@del = ('tags/primes.mdwn'); +IkiWiki::gen_autofile("tags/primes.mdwn", \%pages, \@del); +is_deeply(\%pages, {}) || diag explain \%pages; +is_deeply(\@del, ['tags/primes.mdwn']) || diag explain \@del; + 1; @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 21; +use Test::More tests => 26; BEGIN { use_ok("IkiWiki"); } @@ -19,6 +19,7 @@ is(IkiWiki::cgiurl(cgiurl => $config{cgiurl}), "http://smcv.example.co.uk/cgi-bi is(IkiWiki::cgiurl(cgiurl => $config{cgiurl}, do => 'badger'), "http://smcv.example.co.uk/cgi-bin/ikiwiki.cgi?do=badger"); is(IkiWiki::urlto('index', undef, 1), "http://smcv.example.co.uk/"); is(IkiWiki::urlto('stoats', undef, 1), "http://smcv.example.co.uk/stoats/"); +is(IkiWiki::urlto('', undef, 1), "http://smcv.example.co.uk/"); # "local" (absolute path within site) version (default for cgiurl) is(IkiWiki::cgiurl(), "/cgi-bin/ikiwiki.cgi"); @@ -28,10 +29,13 @@ is(IkiWiki::urlto('index', undef), "/"); is(IkiWiki::urlto('index'), "/"); is(IkiWiki::urlto('stoats', undef), "/stoats/"); is(IkiWiki::urlto('stoats'), "/stoats/"); +is(IkiWiki::urlto(''), "/"); # fully-relative version (default for urlto and baseurl) is(IkiWiki::baseurl('badger/mushroom'), "../../"); is(IkiWiki::urlto('badger/mushroom', 'snake'), "../badger/mushroom/"); +is(IkiWiki::urlto('', 'snake'), "../"); +is(IkiWiki::urlto('', 'penguin/herring'), "../../"); # explicit cgiurl override is(IkiWiki::cgiurl(cgiurl => 'https://foo/ikiwiki'), "https://foo/ikiwiki"); @@ -44,3 +48,4 @@ is(IkiWiki::checkconfig(), 1); is(IkiWiki::cgiurl(), "http://dynamic.example.co.uk/~smcv/ikiwiki.cgi"); is(IkiWiki::baseurl(undef), "http://example.co.uk/~smcv/"); is(IkiWiki::urlto('stoats', undef), "http://example.co.uk/~smcv/stoats/"); +is(IkiWiki::urlto('', undef), "http://example.co.uk/~smcv/"); |