File: links.t

package info (click to toggle)
libwiki-toolkit-formatter-usemod-perl 0.25-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 176 kB
  • sloc: perl: 258; makefile: 2
file content (76 lines) | stat: -rw-r--r-- 1,916 bytes parent folder | download | duplicates (5)
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use strict;
use Test::More;

eval { require Test::MockObject; };
if ( $@ ) {
    plan skip_all => "Can't find Test::MockObject";
}

plan tests => 4;

my $wikitext = <<WIKITEXT;

ExistingNode

NonExistentNode

http://external.example.com/

[http://external2.example.com/ foo]

WIKITEXT

my $wiki = Test::MockObject->new;
$wiki->mock( "node_exists",
             sub {
                 my ($self, $node) = @_;
                 return $node eq "ExistingNode" ? 1 : 0;
             } );

my $formatter = Wiki::Toolkit::Formatter::Kake->new(
    node_prefix => "/wiki/",
    node_suffix => ".html",
    edit_prefix => "/wiki/edit/",
    edit_suffix => ".html",
);

my $html = $formatter->format( $wikitext, $wiki );

like( $html, qr|\[NonExistentNode\]<a href="/wiki/edit/NonExistentNode.html" title="create">\?</a>|,
      "can override ->make_edit_link" );

like( $html,
      qr|<a href="/wiki/ExistingNode.html" class="internal">ExistingNode</a>|,
      "can override ->make_internal_link" );

like( $html,
      qr'<a href="http://external.example.com/">http://external.example.com/</a> <img src="external.gif">',
      "can override ->make_external_link" );

like( $html,
      qr'<a href="http://external2.example.com/">foo</a> <img src="external.gif">',
      "...works for external links with titles too" );

package Wiki::Toolkit::Formatter::Kake;
use base "Wiki::Toolkit::Formatter::UseMod";

sub make_edit_link {
    my ($self, %args) = @_;
    my $title = $args{title};
    my $url = $args{url};
    return qq|[$title]<a href="$url" title="create">?</a>|;
}

sub make_internal_link {
    my ($self, %args) = @_;
    my $title = $args{title};
    my $url = $args{url};
    return qq|<a href="$url" class="internal">$title</a>|;
}

sub make_external_link {
    my ($self, %args) = @_;
    my $title = $args{title};
    my $url = $args{url};
    return qq|<a href="$url">$title</a> <img src="external.gif">|;
}