File: 14tag-gen.t

package info (click to toggle)
libhtml-widgets-navmenu-perl 1.1000-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 636 kB
  • sloc: perl: 8,051; makefile: 9
file content (103 lines) | stat: -rw-r--r-- 2,559 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/perl -w

use Test::More tests => 12;

use strict;

BEGIN
{
    use_ok('HTML::Widgets::NavMenu::TagGen');    # TEST
}

{
    my $test_tag = HTML::Widgets::NavMenu::TagGen->new(
        {
            'name'       => "a",
            'attributes' => {
                'href'  => { 'escape' => 1, },
                'title' => { 'escape' => 0, },
                'id'    => { 'escape' => 1, },
                'iname' => { 'escape' => 0, },
            },
        }
    );

    # TEST
    is(
        $test_tag->gen( { 'href' => "http://www.mysite.com/", } ),
        q{<a href="http://www.mysite.com/">},
        "Simple Tag Test"
    );

    # TEST
    is( $test_tag->gen( { 'href' => "/hello&you<yes>", } ),
        q{<a href="/hello&amp;you&lt;yes&gt;">}, "Escaping" );

    # TEST
    is(
        $test_tag->gen( { 'href' => "http://www.mysite.com/", }, 1 ),
        q{<a href="http://www.mysite.com/" />},
        "Standalone Tag"
    );

    # TEST
    is(
        $test_tag->gen( { 'href' => "/hello&you<yes>", }, 1 ),
        q{<a href="/hello&amp;you&lt;yes&gt;" />},
        "Standalone Tag with Escaping"
    );

    # TEST
    is( $test_tag->gen( {} ), q{<a>}, "Empty Tag" );

    # TEST
    is( $test_tag->gen( {}, 1 ), q{<a />}, "Empty Standalone Tag" );

    # TEST
    is(
        $test_tag->gen( { 'title' => "This is me&amp;yours title" } ),
        q{<a title="This is me&amp;yours title">},
        "Non-escaping for unescaped attribute"
    );

    # TEST
    is(
        $test_tag->gen(
            { 'title' => "Hello", 'href' => "/hi/", 'id' => "myid" }
        ),
        q{<a href="/hi/" id="myid" title="Hello">},
        "Multiple Attributes"
    );

    # TEST
    is(
        $test_tag->gen(
            {
                'title' => "Hello",
                'href'  => "/hi/",
                'id'    => "myid"
            },
            1
        ),
        q{<a href="/hi/" id="myid" title="Hello" />},
        "Multiple Attributes Standalone"
    );
    my $string = "&lt;Hello&amp;";

    # TEST
    is(
        $test_tag->gen( { map { $_ => $string } (qw(href title id iname)) } ),
q{<a href="&amp;lt;Hello&amp;amp;" id="&amp;lt;Hello&amp;amp;" iname="&lt;Hello&amp;" title="&lt;Hello&amp;">},
        "Selective Escaping"
    );

    # TEST
    is(
        $test_tag->gen(
            { map { $_ => $string } (qw(href title id iname)) }, 1
        ),
q{<a href="&amp;lt;Hello&amp;amp;" id="&amp;lt;Hello&amp;amp;" iname="&lt;Hello&amp;" title="&lt;Hello&amp;" />},
        "Selective Escaping Standalone"
    );
}