You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by do...@apache.org on 2002/08/27 06:31:55 UTC

cvs commit: modperl-2.0/t/response/TestDirective loadmodule.pm

dougm       2002/08/26 21:31:55

  Modified:    lib/ModPerl TestRun.pm
  Added:       t/response/TestDirective loadmodule.pm
  Log:
  test for directive handlers
  
  Revision  Changes    Path
  1.3       +14 -0     modperl-2.0/lib/ModPerl/TestRun.pm
  
  Index: TestRun.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/lib/ModPerl/TestRun.pm,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestRun.pm	24 Aug 2002 16:12:57 -0000	1.2
  +++ TestRun.pm	27 Aug 2002 04:31:55 -0000	1.3
  @@ -27,11 +27,25 @@
   
       $self->SUPER::configure_startup_pl;
   
  +    #XXX: issue for these is they need to happen after PerlSwitches
  +
       #XXX: this should only be done for the modperl-2.0 tests
       $self->postamble(<<'EOF');
   <Perl handler=ModPerl::Test::perl_section>
       $Foo = 'bar';
   </Perl>
  +EOF
  +
  +    #XXX: this should only be done for the modperl-2.0 tests
  +    $self->postamble(<<'EOF');
  +LoadModule TestDirective::loadmodule
  +
  +MyTest one two
  +ServerTest per-server
  +
  +<Location /TestDirective::loadmodule>
  +    MyOtherTest value
  +</Location>
   EOF
   }
   
  
  
  
  1.1                  modperl-2.0/t/response/TestDirective/loadmodule.pm
  
  Index: loadmodule.pm
  ===================================================================
  package TestDirective::loadmodule;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  
  use Apache::Const -compile => qw(OK OR_ALL RSRC_CONF TAKE1 TAKE23);
  
  use Apache::CmdParms ();
  use Apache::Module ();
  
  our @APACHE_MODULE_COMMANDS = (
      {
       name => 'MyTest',
       func => __PACKAGE__ . '::MyTest',
       req_override => Apache::RSRC_CONF,
  #     req_override => 'RSRC_CONF', #test 1.x compat for strings
       args_how => Apache::TAKE23,
  #     args_how => 'TAKE23', #test 1.x compat for strings
       errmsg => 'A test',
      },
      {
       name => 'MyOtherTest',
      },
      {
       name => 'ServerTest',
       req_override => Apache::RSRC_CONF,
      }
  );
  
  sub DIR_CREATE {
      my($class, $parms) = @_;
  
      bless {
  	path => $parms->path || "/",
      }, $class;
  }
  
  sub merge {
      my($base, $add) = @_;
  
      my %new = ();
  
      @new{keys %$base, keys %$add} =
  	(values %$base, values %$add);
  
      return bless \%new, ref($base);
  }
  
  sub DIR_MERGE {
      my $class = ref $_[0];
  #    warn "$class->DIR_MERGE\n";
      merge(@_);
  }
  
  sub SERVER_MERGE {
      my $class = ref $_[0];
  #    warn "$class->SERVER_MERGE\n";
      merge(@_);
  }
  
  sub SERVER_CREATE {
      my($class, $parms) = @_;
  #    warn "$class->SERVER_CREATE\n";
      return bless {
  	name => __PACKAGE__,
      }, $class;
  }
  
  sub MyTest {
      my($self, $parms, @args) = @_;
      $self->{MyTest} = \@args;
  }
  
  sub MyOtherTest {
      my($self, $parms, $arg) = @_;
      $self->{MyOtherTest} = $arg;
  }
  
  sub ServerTest {
      my($self, $parms, $arg) = @_;
      my $srv_cfg = $self->get_config($parms->server);
      $srv_cfg->{ServerTest} = $arg;
  }
  
  sub get_config {
      my($self, $s) = (shift, shift);
      Apache::Module->get_config($self, $s, @_);
  }
  
  sub handler : method {
      my($self, $r) = @_;
  
      my $s = $r->server;
      my $dir_cfg = $self->get_config($s, $r->per_dir_config);
      my $srv_cfg = $self->get_config($s);
  
      plan $r, tests => 7;
  
      t_debug("per-dir config:", $dir_cfg);
      t_debug("per-srv config:", $srv_cfg);
  
      ok $dir_cfg->isa($self);
      ok $srv_cfg->isa($self);
  
      my $path = $dir_cfg->{path};
  
      ok t_cmp(qr{^$path}, $r->uri,
               'r->uri =~ parms->path');
  
      ok t_cmp($self, $srv_cfg->{name},
               '$self eq $srv_cfg->{name}');
  
      ok t_cmp('value', $dir_cfg->{MyOtherTest},
               'MyOtherTest value');
  
      ok t_cmp(['one', 'two'], $dir_cfg->{MyTest},
               'MyTest one two');
  
      ok t_cmp('per-server', $srv_cfg->{ServerTest});
  
      Apache::OK;
  }
  
  1;
  __END__