File: 03nav-links.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 (149 lines) | stat: -rw-r--r-- 3,546 bytes parent folder | download
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
#!/usr/bin/perl -w

use strict;

use lib './t/lib';

use Test::More tests => 14;

use HTML::Widgets::NavMenu ();

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

my $test_data = get_test_data();

my @site_args = (
    '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/",
            },
            {
                'text'  => "Last Page",
                'title' => "Last Page",
                'url'   => "last-page.html",
            }
        ],
    },
);

# The purpose of this test is to check for the in-existence of navigation
# links from the first page. Generally, there shouldn't be "top", "up" and
# "prev" nav-links and only "next".
{
    my $nav_menu = HTML::Widgets::NavMenu->new(
        'path_info' => "/",
        @site_args
    );

    my $rendered = $nav_menu->render();

    my $nav_links = $rendered->{'nav_links'};

    # TEST
    ok(
        ( 1 ? ( scalar( keys(%$nav_links) ) == 1 ) : 1 )
            && ( exists( $nav_links->{'next'} ) ),
        "Lack of Nav-Links in the First Page"
    );

    my $obj_nav_links = $rendered->{'nav_links_obj'};

    my $next = $obj_nav_links->{'next'};

    # TEST
    is( $next->host(), "default", "Checking for \$next->host()." );

    # TEST
    is( $next->label(), "About Me", "Checking for label()" );

    # TEST
    is( $next->title(), "About Myself", "Checking for title()" );

    # TEST
    is( $next->direct_url(), "./me/", "Checking for direct_url()" );

    # TEST
    is( $next->host_url(), "me/", "Checking for host_url()" );
}

# The purpose of this test is to check for up arrow leading from the middle
# page to the "Home" page
{
    my $nav_menu = HTML::Widgets::NavMenu->new(
        'path_info' => "/me/",
        @site_args
    );

    my $rendered = $nav_menu->render();

    my $nav_links = $rendered->{'nav_links'};

    # TEST
    is( $nav_links->{'up'}, "../",
        "Up page leading upwards to the first page." );

    # TEST
    is( $nav_links->{'top'}, "../",
        "Top nav-link leading topwards to the first page." );

    my $nav_links_obj = $rendered->{'nav_links_obj'};

    my $up = $nav_links_obj->{'up'};

    # TEST
    is( $up->direct_url(), "../", "direct_url()" );

    # TEST
    is( $up->host(), "default" );

    # TEST
    is( $up->label(), "Home" );
}

# This tests for behaviour with url_is_abs:
{
    my $nav_menu = HTML::Widgets::NavMenu->new(
        'path_info' => "/",
        @{ $test_data->{'url_is_abs_menu'} },
    );

    my $rendered = $nav_menu->render();

    my $nav_links = $rendered->{'nav_links'};

    # TEST
    is( $nav_links->{'next'}, "http://www.google.com/",
        "Next nav_link in url_is_abs site" );
}

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

    my $rendered = $nav_menu->render();

    my $nav_links = $rendered->{'nav_links'};

    # TEST
    is( $nav_links->{'up'}, "http://www.google.com/",
        "Up nav_link in url_is_abs site" );

    # TEST
    is( $nav_links->{'prev'}, "http://www.google.com/",
        "Prev nav_link in url_is_abs site" );
}