4 use RT::Test tests => undef;
5 use RT::Interface::Web::Menu;
7 sub child_path_is($$$) {
8 my ($menu, $child, $expected) = @_;
9 my $c = $menu->child($child->[0], path => $child->[1]);
10 is $c->path, $expected, "'$child->[1]' normalizes to '$expected'";
16 sub new { bless {}, shift }
21 sub new { bless {}, shift }
22 sub cgi_object { CGI->new }
25 local $HTML::Mason::Commands::r = FakeRequest->new;
26 local $HTML::Mason::Commands::m = FakeInterp->new;
28 my $menu = RT::Interface::Web::Menu->new;
29 ok $menu, "Created top level menu";
31 child_path_is $menu, [search => "Search/Simple.html"], "/Search/Simple.html";
32 child_path_is $menu, [absolute => "/Prefs/Other.html"], "/Prefs/Other.html";
33 child_path_is $menu, [scheme => "http://example.com"], "http://example.com";
36 child_path_is $menu, [tools => "/Tools/"], "/Tools/";
37 child_path_is $tools, [myday => "MyDay.html"], "/Tools/MyDay.html";
38 child_path_is $tools, [activity => "/Activity.html"], "/Activity.html";
40 child_path_is $tools, [external => "http://example.com"], "http://example.com";
41 child_path_is $ext, [wiki => "wiki/"], "http://example.com/wiki/";
43 # Pathological case of multiplying slashes
45 child_path_is $menu, [home => "/"], "/";
46 child_path_is $home, [slash => "/"], "/";
47 child_path_is $home, [empty => ""], "/";
52 my ($menu, $expected, $name) = @_;
53 my @children = $menu->children;
55 is scalar @children, scalar @$expected, "correct number of children";
56 is_deeply [map { $_->key } @children], $expected, $name;
58 my $last_child = shift @children; # first child's sort doesn't matter
60 ok $_->sort_order > $last_child->sort_order, sprintf "%s order higher than %s's", $_->key, $last_child->key;
65 $menu = RT::Interface::Web::Menu->new;
67 ok $menu->child("foo", title => "foo"), "added child foo";
68 order_ok $menu, [qw(foo)], "sorted";
70 ok $menu->child("foo")->add_after("bar", title => "bar"), "added child bar after foo";
71 order_ok $menu, [qw(foo bar)], "sorted after";
73 ok $menu->child("bar")->add_before("baz", title => "baz"), "added child baz before bar";
74 order_ok $menu, [qw(foo baz bar)], "sorted before (in between)";
76 ok $menu->child("bat", title => "bat", sort_order => 2.2), "added child bat between baz and bar";
77 order_ok $menu, [qw(foo baz bat bar)], "sorted between manually";
79 ok $menu->child("bat")->add_before("pre", title => "pre"), "added child pre before bat";
80 order_ok $menu, [qw(foo baz pre bat bar)], "sorted between (before)";
82 ok $menu->child("bat")->add_after("post", title => "post"), "added child post after bat";
83 order_ok $menu, [qw(foo baz pre bat post bar)], "sorted between (after)";