Commits

Anonymous committed 3119da3

Nav-Menu: in the old-fangled release, made a bug-fix for the leading path
generation so there'll be at least one component.

Comments (0)

Files changed (2)

lib/Shlomif/NavMenu.pm

 
     my $coords = $self->get_current_coords();
 
+    my $node_ret = $self->find_node_by_coords($coords, $args{'callback'});
+
     # This is so we won't mark the root as CurrentlyActive.
     # Otherwise, the tree is attempted to be captioned and stuff.
     # TODO: add a suitable test.
     if (@$coords)
-    {    
-        my $node_ret = $self->find_node_by_coords($coords, $args{'callback'});
+    {
         my $ptr = $node_ret->{ptr};
         $ptr->{perl_ref}->setActive(1);
         $ptr->{perl_ref}->setCurrentlyActive(1);

t/09leading-path.t

+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More tests => 3;
+
+use Shlomif::NavMenu;
+
+use HTML::Widgets::NavMenu::Test::Data;
+
+my $test_data = get_test_data();
+
+# This check tests that a leading path with a URL that is not registered
+# in the nav menu still has one component of the root.
+{
+    my $nav_menu = Shlomif::NavMenu->new(
+        'path_info' => "/non-existent-path/",
+        @{$test_data->{'minimal'}},
+    );
+
+    my $rendered = 
+        $nav_menu->render(
+            'no_ie' => "true",
+            'styles' =>
+            {
+                'bar' => 'nav',
+                'level0' => 'navbarmain',
+                'level1' => 'navbarnested',
+                'level2' => "navbarnested",
+                'level3' => "navbarnested",
+                'level4' => "navbarnested",
+                'list' => "navbarmain",
+            },
+        );
+
+    my @leading_path = @{$rendered->{'leading_path'}};
+
+    # TEST
+    ok ((scalar(@leading_path) == 1), "Checking for a leading path of len 1");
+
+    my $component = $leading_path[0];
+
+    # TEST
+    is ($component->title(), "T1 Title", "Testing for title of leading_path"); 
+    
+    # TEST
+    is ($component->direct_url(), "../", "Testing for direct_url");
+}
+
+    
+