[LON-CAPA-cvs] cvs: modules /jerf/tests lonhelpTest.pm

bowersj2 lon-capa-cvs@mail.lon-capa.org
Thu, 29 May 2003 20:23:55 -0000


bowersj2		Thu May 29 16:23:55 2003 EDT

  Modified files:              
    /modules/jerf/tests	lonhelpTest.pm 
  Log:
  Likely final lonhelp.pm test; capable of ensuring that links are valid,
  files exist, and renderer at least partially works.
  
  Unfortunately TTH frequently (though not reliably) blows up when
  trying to render this test, even though the exact same .tex works when
  rendered on the web. (I'm thinking mod_perl is even kludgier then
  you'd natually expect on the inside.)
  
  
Index: modules/jerf/tests/lonhelpTest.pm
diff -u modules/jerf/tests/lonhelpTest.pm:1.1 modules/jerf/tests/lonhelpTest.pm:1.2
--- modules/jerf/tests/lonhelpTest.pm:1.1	Fri May 23 16:31:13 2003
+++ modules/jerf/tests/lonhelpTest.pm	Thu May 29 16:23:54 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # lonhelp Handler Tester
 #
-# $Id: lonhelpTest.pm,v 1.1 2003/05/23 20:31:13 bowersj2 Exp $
+# $Id: lonhelpTest.pm,v 1.2 2003/05/29 20:23:54 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -40,8 +40,9 @@
 
 use base qw(Test::Unit::TestCase);
 use strict;
-use Apache::Constants qw(:common);
+use Apache::Constants qw(:common :http);
 use Apache::lonhelp;
+use Data::Dumper;
 
 sub new {
     my $self = shift()->SUPER::new(@_);
@@ -62,7 +63,7 @@
     my $self = shift;
     my $r = ApacheRequest->new();
 
-    $r->doHandler("Apache::lonhelper");
+    $r->doHandler("Apache::lonhelp");
 }
 
 # This tests the label converter; I use this paradigm a lot for string
@@ -95,6 +96,7 @@
 
 # We can't test directly for whether or not a given HTML result from
 # TTH is correct. But there *are* some things we can ensure are true...
+# Would be nice to run it through a REAL validator here...
 sub valid_html_code {
     my $code = shift;
 
@@ -107,6 +109,8 @@
 }
 
 # Test all of the .tex files for various truths
+# This also tests the texxml files in passing, because if they reference
+# non-existant files, those references show up in the *access.tex files.
 sub test_help_files_all_valid {
     my $self = shift;
     
@@ -124,6 +128,7 @@
         my $humanFileName = substr $file, rindex($file, '/') + 1;
         if ($openresult) {
             my $tex = join('', <TEX>);
+	    $self->assert($tex);
             
             # Now validate the tex
             
@@ -152,7 +157,6 @@
                         "\\label{$fileStem} in it.";
                 }
             }
-
         } else {
             push @$errors, "Couldn't open $humanFileName";
         }
@@ -163,4 +167,37 @@
     my $errorMessage = join("\n", @$errors);
     $self->assert($errorMessage eq '', $errorMessage);
 }
+
+# For unknown reasons, this test frequently blows up tth, but works on the web.
+# It's not worth tracking down, IMHO.
+
+#sub test_handler_renders_help_files {
+#    my $self = shift;
+#
+#    # Run the handler on each file and validate that the handler renders it
+#    # without errors
+#    my $docRoot = $Apache::lonnet::perlvar{'lonDocRoot'};
+#    my $helpRoot = $docRoot . '/adm/help/tex/';
+#    for my $file (glob($helpRoot . "*.tex")) {
+#        # Swap out the .tex for a .hlp extension
+#        $file =~ s/tex$/hlp/;
+#	# Grab just the filename
+#	$file = substr($file, rindex($file, '/') + 1);
+#        my $r = ApacheRequest->new({'uri' => "/adm/help/$file"});
+#        $r->doHandler('Apache::lonhelp');
+#        $self->assert($r->getReturnValue() == OK);
+#        my $html = $r->getOutputString();
+#        $self->assert(valid_html_code($html));
+#        $self->assert(!$r->childTerminated(), "lontexconvert.pm died on $file");
+#    }
+#}
+
+sub test_handler_correct_returns_not_found {
+    my $self = shift;
+
+    my $r = ApacheRequest->new({'uri' => '/adm/help/non-existant.hlp'});
+    $r->doHandler('Apache::lonhelp');
+    $self->assert($r->getReturnValue() == HTTP_NOT_FOUND);
+}
+
 1;