Apache2-API
view release on metacpan or search on metacpan
t/lib/Test/Apache2/API/Request.pm view on Meta::CPAN
{
my $bitmask = shift( @_ );
my $opts = shift( @_ );
my $self = $opts->{object};
my $req = $self->api->request;
my $r = $self->_request;
my $cnt = 0;
$opts->{log}->( "\$bitmask is '$bitmask'" );
$opts->{log}->( "\$req->method_number = '" . $req->method_number . "'" );
$cnt++ if( !$bitmask || ( $bitmask & Apache2::Const::M_POST ) );
$cnt++ if( !$bitmask || ( $bitmask & $req->method_number ) );
return( $cnt == 2 );
} }) ); }
# NOTE: special processing
sub args { return( shift->_test({ method => 'args', expect => sub
{
my $ref = shift( @_ );
my $opts = shift( @_ );
my @vals = Scalar::Util::blessed( $ref ) ? $ref->get( 'foo' ) : ();
$opts->{log}->( "\@vals is '@vals', and foo = '$ref->{foo}', bar = '$ref->{bar}' and lang is '$ref->{lang}'" );
return( $ref->{foo} == 1 && $ref->{bar} == 3 && $ref->{lang} eq 'ja_JP' && "@vals" eq '1 2' );
} }) ); }
# my $as_string_request = <<EOT;
# GET /tests/request/as_string HTTP/1.1
# TE: deflate,gzip;q=0.3
# Connection: TE
# Accept: application/json; version=1.0; charset=utf-8, text/javascript, */*
# Accept-Encoding: gzip, deflate, br
# Accept-Language: en-GB,fr-FR;q=0.8,fr;q=0.6,ja;q=0.4,en;q=0.2
# Host: www.example.org:${port}
# User-Agent: Test-Apache2-API/v0.1.0
#
# HTTP/1.1 (null)
# Test-No: as_string
# EOT
sub as_string { return( shift->_test({ method => 'as_string', expect => sub
{
my $str = shift( @_ );
my $opts = shift( @_ );
my $self = $opts->{object};
my $r = $self->request;
$opts->{log}->( "request as a string is: $str" );
# return( $str eq $as_string_request );
return( $str =~ m,^GET[[:blank:]]+/tests/request/as_string[[:blank:]]+HTTP/\d.\d, );
} }) ); }
sub auth { return( shift->_test({ method => 'auth', expect => q{Bearer: eyJleHAiOjE2MzYwNzEwMzksImFsZyI6IkhTMjU2In0.eyJqdGkiOiJkMDg2Zjk0OS1mYWJmLTRiMzgtOTE1ZC1hMDJkNzM0Y2ZmNzAiLCJmaXJzdF9uYW1lIjoiSm9obiIsImlhdCI6MTYzNTk4NDYzOSwiYXpwIjoiNGQ0YWFiYWQtYm...
sub auto_header { return( shift->_test({ method => 'auto_header', expect => 0, type => 'boolean' }) ); }
sub body { return( shift->_test({ method => 'body', expect => 'APR::Request::Param::Table', type => 'isa' }) ); }
sub charset { return( shift->_test({ method => 'charset', expect => 'utf-8' }) ); }
sub client_api_version { return( shift->_test({ method => 'client_api_version', expect => '1.0' }) ); }
sub connection { return( shift->_test({ method => 'connection', expect => 'Apache2::Connection', type => 'isa' }) ); }
# sub cookie { return( shift->_test({ method => 'cookie', expect => 'Cookie', type => 'isa', args => ['my_session'] }) ); }
sub cookie { return( shift->_test({ method => 'cookie', expect => 'foo', args => ['my_session'] }) ); }
my $sample_data = <<EOT;
{
"id": 123,
"client_id": "37c58138-e259-44aa-9eee-baf3cbecca75"
}
EOT
sub data { return( shift->_test({ method => 'data', expect => $sample_data }) ); }
sub decode { return( shift->_test({ method => 'decode', expect => q{var=$ & < > ? ; # : = , " ' ~ + %}, args => ['var%3D%24+%26+%3C+%3E+%3F+%3B+%23+%3A+%3D+%2C+%22+%27+~+%2B+%25'] }) ); }
sub encode { return( shift->_test({ method => 'encode', expect => q{var%3D%24+%26+%3C+%3E+%3F+%3B+%23+%3A+%3D+%2C+%22+%27+~+%2B+%25}, args => [q{var=$ & < > ? ; # : = , " ' ~ + %}] }) ); }
sub document_root { return( shift->_test({ method => 'document_root', expect => $config->{vars}->{documentroot} }) ); }
sub document_uri { return( shift->_test({ method => 'document_uri', expect => undef }) ); }
sub env { return( shift->_test({ method => 'env', expect => 'APR::Table', type => 'isa' }) ); }
sub finfo { return( shift->_test({ method => 'finfo', expect => 'APR::Finfo', type => 'isa' }) ); }
sub gateway_interface { return( shift->_test({ method => 'gateway_interface', expect => 'CGI/1.1' }) ); }
sub global_request { return( shift->_test({ method => 'global_request', expect => 'Apache2::RequestRec', type => 'isa' }) ); }
sub has_auth { return( shift->_test({ method => 'has_auth', expect => 0, type => 'boolean' }) ); }
sub header_only { return( shift->_test({ method => 'header_only', expect => 0, type => 'boolean' }) ); }
sub headers { return( shift->_test({ method => 'headers', expect => 'APR::Table', type => 'isa' }) ); }
sub headers_as_hashref { return( shift->_test({ method => 'headers_as_hashref', expect => sub
{
my $ref = shift( @_ );
return( ref( $ref // '' ) eq 'HASH' );
} }) ); }
sub headers_as_json { return( shift->_test({ method => 'headers_as_json', expect => sub
{
my $json = shift( @_ );
return( substr( $json, 0, 1 ) eq '{' );
} }) ); }
sub headers_in { return( shift->_test({ method => 'headers_in', expect => 'APR::Table', type => 'isa' }) ); }
# if_modified_since
# if_none_match
sub is_secure { return( shift->_test({ method => 'is_secure', expect => HAS_SSL, type => 'boolean' }) ); }
sub json { return( shift->_test({ method => 'json', expect => 'JSON', type => 'isa' }) ); }
sub local_addr { return( shift->_test({ method => 'local_addr', expect => 'APR::SockAddr', type => 'isa' }) ); }
sub method { return( shift->_test({ method => 'method', expect => 'GET' }) ); }
sub mod_perl_version { return( shift->_test({ method => 'mod_perl_version', expect => sub
{
my $vers = shift( @_ );
( run in 0.672 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )