Commits

Anonymous committed e85d816

Implemented the links to the control panel and the help screen (so far
non functioning). Added unit tests.

Comments (0)

Files changed (4)

 t/SVN-RaWeb-Light.t
 t/01output.t
 t/02unit.t
+t/03trans_unit.t
+t/04exceptions.t
 lib/SVN/RaWeb/Light.pm
 examples/berlios.pl
 META.yml                                 Module meta-data (added by MakeMaker)
 SVN/RaWeb/Light/Mock/CGI.pm
 SVN/RaWeb/Light/Mock/Stdout.pm
 SVN/RaWeb/Light/Mock/Svn.pm
+SVN/RaWeb/Light/Test/LimitOutput.pm
 TODO

lib/SVN/RaWeb/Light.pm

     {
         $rev_num = $self->svn_ra()->get_latest_revnum();
     }
+    
+    $self->rev_num($rev_num);
+    $self->url_suffix($self->get_url_suffix_with_extras());
+    $self->esc_url_suffix(escape($self->url_suffix()));
+}
+
+# Gets the URL suffix calculated with optional extra components.
+sub get_url_suffix_with_extras
+{
+    my $self = shift;
+    my $components = shift;
+
+    my $query_string = $self->cgi->query_string();
+    if ($query_string eq "")
     {
-        my $query_string = $self->cgi->query_string();
-        if ($query_string eq "")
+        if (defined($components))
         {
-            $url_suffix = "";
+            return "?" . $components;
         }
         else
         {
-            $url_suffix = "?" . $query_string;
+            return "";
+        }        
+    }
+    else
+    {
+        if (defined($components))
+        {
+            return "?" . $query_string . ";" . $components;
+        }
+        else
+        {
+            return "?" . $query_string;
         }
     }
-    
-    $self->rev_num($rev_num);
-    $self->url_suffix($url_suffix);
-    $self->esc_url_suffix(escape($self->url_suffix()));
 }
 
 sub calc_path
     print "</ul>\n";
 }
 
+sub print_control_section
+{
+    my $self = shift;
+    print "<ul>\n" .
+        "<li><a href=\"./?mode=help\">Show Help Screen</a></li>\n" .
+        "<li><a href=\"./" . escape($self->get_url_suffix_with_extras("panel=1")) . "\">Show Control Panel</a></li>\n" .
+        "</ul>\n";
+}
+
 sub get_dir
 {
     my $self = shift;
     print $self->render_dir_header();
     print $self->render_top_url_translations_text();
     $self->print_items_list();
+    $self->print_control_section();
     print "</body></html>\n";
 }
 
         "<li><a href=\"hello.pm\">hello.pm</a></li>\n" .
         "<li><a href=\"mydir/\">mydir/</a></li>\n" .
         "</ul>\n".
+        "<ul>\n" .
+        "<li><a href=\"./?mode=help\">Show Help Screen</a></li>\n" .
+        "<li><a href=\"./?panel=1\">Show Control Panel</a></li>\n" .
+        "</ul>\n" .
         "</body></html>\n"),
         "Checking for valid output of a dir listing");
-        
 }
 
 # Test the directory output for the root directory
         "<li><a href=\"the-directory/\">the-directory/</a></li>\n" .
         "<li><a href=\"yowza.txt\">yowza.txt</a></li>\n" .
         "</ul>\n".
+        "<ul>\n" .
+        "<li><a href=\"./?mode=help\">Show Help Screen</a></li>\n" .
+        "<li><a href=\"./?panel=1\">Show Control Panel</a></li>\n" .
+        "</ul>\n" .        
         "</body></html>\n"),
         "Checking for valid output of a dir listing in root");
 }
 use warnings;
 use strict;
 
-use Test::More tests => 14;
+use Test::More tests => 18;
 
 # We need to load the mocking modules first because they fill the 
 # namespaces and %INC. Otherwise, "use CGI" and "use SVN::*" will cause
     );
 }
 
+
+# Unit tests for get_url_suffix_with_extras
+
+sub my_url_suffix_test
+{
+    my %args = (@_);
+
+    @CGI::new_params =
+    (
+        'path_info' => "/trunk/hello/",
+        'params' =>
+        {
+        },
+        'query_string' => $args{'query_string'},
+    );
+
+    reset_out_buffer();
+
+    my $svn_ra_web =
+        SVN::RaWeb::Light->new(
+            'url' => "http://svn-i.shlomifish.org/svn/myrepos/",
+        );
+
+    is(
+        $svn_ra_web->get_url_suffix_with_extras(@{$args{'func_params'}}), 
+        $args{'result'},
+        $args{'msg'}
+    );
+}
+{
+    # TEST
+    my_url_suffix_test(
+        'query_string' => "",
+        'func_params' => [],
+        'result' => "",
+        'msg' => "Testing empty for both query string and additional",
+    );
+
+    # TEST
+    my_url_suffix_test(
+        'query_string' => "h=j&k=l",
+        'func_params' => [],
+        'result' => "?h=j&k=l",
+        'msg' => "Testing filled in query string and no additonal",
+    );
+
+    # TEST
+    my_url_suffix_test(
+        'query_string' => "",
+        'func_params' => ["panel=1"],
+        'result' => "?panel=1",
+        'msg' => "Testing empty query string and additional params",
+    );
+
+    # TEST
+    my_url_suffix_test(
+        'query_string' => "h=j&k=l",
+        'func_params' => ["panel=1"],
+        'result' => "?h=j&k=l;panel=1",
+        'msg' => "Testing empty query string and additional params",
+    );
+}
+