stas        2003/11/07 00:52:44

  Added:       t/modules cgi2.t cgipost2.t cgiupload2.t
               t/response/TestModules cgi2.pm cgipost2.pm cgiupload2.pm
  Log:
  replicate all cgi tests to run as well under 'SetHandler modperl'
  (requires CGI.pm 3.01, not released at the moment ;)
  
  Revision  Changes    Path
  1.1                  modperl-2.0/t/modules/cgi2.t
  
  Index: cgi2.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestRequest;
  use Apache::TestUtil;
  use Apache::Build ();
  
  my $build = Apache::Build->build_config;
  
  use constant HAVE_LWP => have_lwp();
  
  my $tests = 4;
  $tests += 1 if HAVE_LWP;
  
  plan tests => $tests, have
      have_min_module_version(CGI => 3.01);
  
  my $module = 'TestModules::cgi2';
  my $location = '/' . Apache::TestRequest::module2path($module);
  
  my($res, $str);
  
  sok {
      my $url = "$location?PARAM=2";
      $res = GET $url;
      $str = $res->content;
      t_cmp("ok 2", $str, "GET $url");
  };
  
  sok {
      my $content = 'PARAM=%33';
      $str = POST_BODY $location, content => $content;
      t_cmp("ok 3", $str, "POST $location\n$content");
  };
  
  if (HAVE_LWP) {
      sok {
          $str = UPLOAD_BODY $location, content => 4;
          t_cmp("ok 4", $str, 'file upload');
      };
  }
  
  sok {
      my $header = 'Content-type';
      $res = GET $location;
      t_cmp(qr{^text/test-output},
            $res->header($header),
            "$header header");
  };
  
  sok {
      my $header = 'X-Perl-Module';
      $res = GET $location;
      t_cmp($module,
            $res->header($header),
            "$header header");
  };
  
  
  
  1.1                  modperl-2.0/t/modules/cgipost2.t
  
  Index: cgipost2.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  use Apache::TestRequest qw(POST_BODY_ASSERT);
  
  my $module = 'TestModules::cgipost2';
  my $url = '/' . Apache::TestRequest::module2path($module);
  
  my @data = (25, 50, 75, 100, 125, 150);
  
  plan tests => scalar(@data), have_min_module_version(CGI => 3.01);
  
  foreach my $post (@data) {
      my %param = ();
  
      foreach my $key (1 .. $post) {
        $param{$key} = 'data' x $key;
      }
  
      my $post_data = join '&', map { "$_=$param{$_}" }
                                sort { $a <=> $b } keys %param;
      my $expected  = join ':', map { $param{$_}      }
                                sort { $a <=> $b } keys %param;
  
      my $e_length = length $expected;
  
      my $received = POST_BODY_ASSERT $url, content => $post_data;
  
      my $r_length = length $received;
  
      t_debug "expected $e_length bytes, received $r_length bytes\n";
      ok ($expected eq $received);
  }
  
  
  
  
  1.1                  modperl-2.0/t/modules/cgiupload2.t
  
  Index: cgiupload2.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  use Apache::TestRequest;
  use Apache::Build ();
  
  my $build = Apache::Build->build_config;
  plan tests => 2, have have_lwp(),
      have_min_module_version(CGI => 3.01);
  
  my $location = "/TestModules__cgiupload2";
  
  my $filename;
  my $pod = 'pod/perlfunc.pod';
  
  for (@INC) {
      if (-e "$_/$pod") {
          $filename = "$_/$pod";
          last;
      }
  }
  
  $filename ||= '../Makefile';
  
  for (1,2) {
      my $str = UPLOAD_BODY $location, filename => $filename;
      my $body_len = length $str;
      my $file_len = -s $filename;
      t_debug "body_len=$body_len, file_len=$file_len";
      ok $body_len == $file_len;
  }
  
  
  
  1.1                  modperl-2.0/t/response/TestModules/cgi2.pm
  
  Index: cgi2.pm
  ===================================================================
  package TestModules::cgi2;
  
  # this handler doesn't use the :Apache layer, so CGI.pm needs to do
  # $r->read(...)  instead of read(STDIN,...)
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::compat ();
  use CGI ();
  
  use Apache::Const -compile => 'OK';
  
  sub handler {
      my $r = shift;
  
      unless ($ENV{MOD_PERL}) {
          die "\$ENV{MOD_PERL} is not set";
      }
  
      if ($CGI::Q) {
          die "CGI.pm globals were not reset";
      }
  
      unless ($CGI::MOD_PERL) {
          die "CGI.pm does not think this is mod_perl";
      }
  
      my $cgi = CGI->new($r);
  
      my $param = $cgi->param('PARAM');
      my $httpupload = $cgi->param('HTTPUPLOAD');
  
      $r->print($cgi->header('-type' => 'text/test-output',
                             '-X-Perl-Module' => __PACKAGE__));
  
      if ($httpupload) {
          no strict;
          local $/;
          my $content = <$httpupload>;
          $r->print("ok $content");
      }
      elsif ($param) {
          $r->print("ok $param");
      }
      else {
          $r->print("no param or upload data\n");
      }
  
      Apache::OK;
  }
  
  1;
  
  
  
  
  1.1                  modperl-2.0/t/response/TestModules/cgipost2.pm
  
  Index: cgipost2.pm
  ===================================================================
  package TestModules::cgipost2;
  
  # this handler doesn't use the :Apache layer, so CGI.pm needs to do
  # $r->read(...)  instead of read(STDIN,...)
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::compat ();
  use CGI ();
  
  use Apache::Const -compile => 'OK';
  
  sub handler {
      my $r = shift;
  
      $r->content_type('text/plain');
      my $cgi = CGI->new($r);
  
      $r->print(join ":", map { $cgi->param($_) } $cgi->param);
  
      Apache::OK;
  }
  
  1;
  __END__
  
  
  
  
  1.1                  modperl-2.0/t/response/TestModules/cgiupload2.pm
  
  Index: cgiupload2.pm
  ===================================================================
  package TestModules::cgiupload2;
  
  # this handler doesn't use the :Apache layer, so CGI.pm needs to do
  # $r->read(...)  instead of read(STDIN,...)
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::compat ();
  use CGI ();
  
  use Apache::Const -compile => 'OK';
  
  sub handler {
      my $r = shift;
  
      my $cgi = CGI->new($r);
  
      local $\;
      local $/;
      my $file = $cgi->param('filename');
      $r->print(<$file>);
  
      Apache::OK;
  }
  
  1;
  
  
  

Reply via email to