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
|
#!/usr/bin/perl -w
use strict;
use Test::More tests => 13;
use HTML::Widgets::NavMenu ();
{
my $nav_menu = HTML::Widgets::NavMenu->new(
'path_info' => "/path1/path2/",
'current_host' => "shlomif",
'hosts' => {
'shlomif' => {
'base_url' => "http://www.shlomifish.org/",
'trailing_url_base' => "/",
},
'vipe' => {
'base_url' => "http://vipe.technion.ac.il/~shlomif/",
'trailing_url_base' => "/~shlomif/",
},
},
# This is just to settle the constructor
'tree_contents' => {
'host' => "shlomif",
'text' => "Top 1",
'title' => "T1 Title",
},
);
# TEST*3
foreach my $url_type (qw(rel site_abs full_abs))
{
is(
$nav_menu->get_cross_host_rel_url(
'host' => "vipe",
'host_url' => "hello/",
'url_type' => $url_type,
),
"http://vipe.technion.ac.il/~shlomif/hello/",
"Testing for cross-host URL of $url_type."
);
}
# TEST
is(
$nav_menu->get_cross_host_rel_url(
'host' => "shlomif",
'host_url' => "hello/",
'url_type' => "rel",
),
"../../hello/",
"Checking for intra-host link of 'rel'"
);
# TEST
is(
$nav_menu->get_cross_host_rel_url(
'host' => "shlomif",
'host_url' => "hello/",
'url_type' => "site_abs",
),
"/hello/",
"Checking for intra-host link of 'site_abs'"
);
# TEST
is(
$nav_menu->get_cross_host_rel_url(
'host' => "shlomif",
'host_url' => "hello/",
'url_type' => "full_abs",
),
"http://www.shlomifish.org/hello/",
"Checking for intra-host link of 'full_abs'"
);
# TEST
eval {
my $string = $nav_menu->get_cross_host_rel_url(
'host' => "shlomif",
'host_url' => "hello/",
'url_type' => "unknown",
);
};
ok( $@,
"Checking for exception thrown on intra-host URL with an unknown url_type"
);
# Now we check for a URL that shares a component with this one.
# TEST
is(
$nav_menu->get_cross_host_rel_url(
'host' => "shlomif",
'host_url' => "path1/other-path/",
'url_type' => "rel",
),
"../other-path/",
"Checking for intra-host (shared component) link of 'rel'"
);
# TEST
is(
$nav_menu->get_cross_host_rel_url(
'host' => "shlomif",
'host_url' => "path1/other-path/",
'url_type' => "site_abs",
),
"/path1/other-path/",
"Checking for intra-host (shared component) link of 'site_abs'"
);
# TEST
is(
$nav_menu->get_cross_host_rel_url(
'host' => "shlomif",
'host_url' => "path1/other-path/",
'url_type' => "full_abs",
),
"http://www.shlomifish.org/path1/other-path/",
"Checking for intra-host (shared component) link of 'full_abs'"
);
# Now we check for 'url_is_abs'
# TEST
is(
$nav_menu->get_cross_host_rel_url(
'host' => "shlomif",
'host_url' => "http://www.myhost.com/",
'url_type' => "rel",
'url_is_abs' => 1,
),
"http://www.myhost.com/",
"Checking for url_is_abs."
);
# TEST
is(
$nav_menu->get_cross_host_rel_url(
'host' => "shlomif",
'host_url' => "http://www.myhost.com/",
'url_type' => "site_abs",
'url_is_abs' => 1,
),
"http://www.myhost.com/",
"Checking for url_is_abs"
);
# TEST
is(
$nav_menu->get_cross_host_rel_url(
'host' => "shlomif",
'host_url' => "http://www.myhost.com/",
'url_type' => "full_abs",
'url_is_abs' => 1,
),
"http://www.myhost.com/",
"Checking for url_is_abs"
);
}
|