File: 02site-map.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 (270 lines) | stat: -rw-r--r-- 6,254 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/usr/bin/perl -w

use strict;

use lib './t/lib';

use Test::More tests => 6;

use HTML::Widgets::NavMenu ();

use HTML::Widgets::NavMenu::Test::Data;

my $test_data = get_test_data();

sub validate_site_map
{
    my $results         = shift;
    my $expected_string = shift;
    my $test_blurb      = shift;

    my @result = @$results;

    my @expected = ( split( /\n/, $expected_string ) );

    is_deeply( \@expected, \@result, $test_blurb );
}

{
    my $nav_menu = HTML::Widgets::NavMenu->new(
        'path_info' => "hello/",
        @{ $test_data->{'minimal'} },
    );

    my $results       = $nav_menu->gen_site_map();
    my $expected_text = <<"EOF";
<ul>
<li>
<a href="../">Home</a>
</li>
<li>
<a href="../me/" title="About Myself">About Me</a> - About Myself
</li>
</ul>
EOF

    # TEST
    validate_site_map( $results, $expected_text, "site_map #1" );
}

{
    my $nav_menu = HTML::Widgets::NavMenu->new(
        'path_info'    => "hello/",
        'current_host' => "default",
        'hosts' => { 'default' => { 'base_url' => "http://www.hello.com/" }, },
        'tree_contents' => {
            'host'      => "default",
            'text'      => "Top 1",
            'title'     => "T1 Title",
            'expand_re' => "",
            'subs'      => [
                {
                    'text' => "Home",
                    'url'  => "",
                },
                {
                    'text'  => "About Me",
                    'title' => "About Myself",
                    'url'   => "me/",
                    'subs'  => [
                        {
                            'url'   => "round/hello/personal.html",
                            'text'  => "Bio",
                            'title' => "Biography of Myself",
                        },
                    ],
                },
            ],
        },
    );

    my $results       = $nav_menu->gen_site_map();
    my $expected_text = <<"EOF";
<ul>
<li>
<a href="../">Home</a>
</li>
<li>
<a href="../me/" title="About Myself">About Me</a> - About Myself
<br />
<ul>
<li>
<a href="../round/hello/personal.html" title="Biography of Myself">Bio</a> - Biography of Myself
</li>
</ul>
</li>
</ul>
EOF

    # TEST
    validate_site_map( $results, $expected_text, "site_map #2" );
}

{
    my $nav_menu = HTML::Widgets::NavMenu->new(
        'path_info' => "hello/world/",
        @{ $test_data->{'two_sites'} },
    );

    my $results       = $nav_menu->gen_site_map();
    my $expected_text = <<"EOF";
<ul>
<li>
<a href="../../">Home</a>
</li>
<li>
<a href="../../me/" title="About Myself">About Me</a> - About Myself
<br />
<ul>
<li>
<a href="../../round/hello/personal.html" title="Biography of Myself">Bio</a> - Biography of Myself
</li>
<li>
<a href="../../round/toto/" title="A Useful Conspiracy">Gloria</a> - A Useful Conspiracy
</li>
</ul>
</li>
<li>
<a href="http://www.other-url.co.il/~shlomif/hoola/" title="Drumming is good for your health">Tam Tam Drums</a> - Drumming is good for your health
<br />
<ul>
<li>
<a href="../hoop.html" title="Hoola Hoops Rulez and Ownz!">Hoola Hoops</a> - Hoola Hoops Rulez and Ownz!
</li>
<li>
<a href="http://www.other-url.co.il/~shlomif/tetra/">Tetrahedron</a>
<br />
<ul>
<li>
<a href="http://www.other-url.co.il/~shlomif/tetra/one/" title="Tetra One Title">Tetra One</a> - Tetra One Title
</li>
</ul>
</li>
</ul>
</li>
</ul>
EOF

    # TEST
    validate_site_map( $results, $expected_text, "site_map - complex" );
}

# Now testing that the separator is safely skipped and does not generate
# a double </li>
{
    my $nav_menu = HTML::Widgets::NavMenu->new(
        'path_info'    => "hello/",
        'current_host' => "default",
        'hosts' => { 'default' => { 'base_url' => "http://www.hello.com/" }, },
        'tree_contents' => {
            'host'      => "default",
            'text'      => "Top 1",
            'title'     => "T1 Title",
            'expand_re' => "",
            'subs'      => [
                {
                    'text' => "Home",
                    'url'  => "",
                },
                {
                    'text'  => "About Me",
                    'title' => "About Myself",
                    'url'   => "me/",
                },
                {
                    'separator' => 1,
                    'skip'      => 1,
                },
                {
                    'text'  => "Hoola",
                    'title' => "Hoola Hoop",
                    'url'   => "me-too/",
                },
            ],
        },
    );

    my $results       = $nav_menu->gen_site_map();
    my $expected_text = <<"EOF";
<ul>
<li>
<a href="../">Home</a>
</li>
<li>
<a href="../me/" title="About Myself">About Me</a> - About Myself
</li>
<li>
<a href="../me-too/" title="Hoola Hoop">Hoola</a> - Hoola Hoop
</li>
</ul>
EOF

    # TEST
    validate_site_map( $results, $expected_text, "site_map - separator" );
}

# This is a test for the rec_url_type directive.
{
    my $nav_menu = HTML::Widgets::NavMenu->new(
        'path_info' => "/darling/",
        @{ $test_data->{'rec_url_type_menu'} },
    );

    my $results = $nav_menu->gen_site_map();

    my $expected_text = <<"EOF";
<ul>
<li>
<a href="http://www.hello.com/~shlomif/">Home</a>
</li>
<li>
<a href="/~shlomif/me/" title="About Myself">About Me</a> - About Myself
</li>
<li>
<a href="http://www.hello.com/~shlomif/tedious/to/write/">Hoola</a>
</li>
<li>
<a href="../yowza/">Yowza</a>
<br />
<ul>
<li>
<a href="http://www.hello.com/~shlomif/yowza/howza/">This should be full_abs again</a>
</li>
</ul>
</li>
</ul>
EOF

    # TEST
    validate_site_map( $results, $expected_text, "site_map - rec_url_type" );
}

# This is a test for the url_is_abs directive.
{
    my $nav_menu = HTML::Widgets::NavMenu->new(
        'path_info' => "/darling/",
        @{ $test_data->{'url_is_abs_menu'} },
    );

    my $results = $nav_menu->gen_site_map();

    my $expected_text = <<"EOF";
<ul>
<li>
<a href="../">Home</a>
</li>
<li>
<a href="http://www.google.com/" title="Google it!">Link to Google</a> - Google it!
<br />
<ul>
<li>
<a href="../sub-dir/">Sub Directory</a>
</li>
</ul>
</li>
</ul>
EOF

    # TEST
    validate_site_map( $results, $expected_text, "site_map - url_is_abs" );
}