Apache2-API
view release on metacpan or search on metacpan
t/03.query.t view on Meta::CPAN
#!/usr/local/bin/perl
BEGIN
{
use strict;
use warnings;
use lib './lib';
use open ':std' => ':utf8';
# use Test2::V0;
use Test::More;
use vars qw( $DEBUG );
use ok( 'Apache2::API::Query' ) || bail_out( "Cannot load Apache2::API::Query" );
our $DEBUG = exists( $ENV{AUTHOR_TESTING} ) ? $ENV{AUTHOR_TESTING} : 0;
require( "./t/env.pl" ) if( -e( "t/env.pl" ) );
};
use strict;
use warnings;
my $qq = Apache2::API::Query->new( 'foo=1&foo=2&bar=3;bog=abc;bar=7;fluffy=3' );
isa_ok( $qq, 'Apache2::API::Query' );
# To generate this list:
# perl -lnE '/^sub (?!init|[A-Z]|_)/ and say "can_ok( \$qq, \''", [split(/\s+/, $_)]->[1], "\'' );"' ./lib/Apache2/API/Query.pm
can_ok( $qq, 'strip' );
can_ok( $qq, 'strip_except' );
can_ok( $qq, 'strip_null' );
can_ok( $qq, 'strip_like' );
can_ok( $qq, 'replace' );
can_ok( $qq, 'stringify' );
can_ok( $qq, 'qstringify' );
can_ok( $qq, 'revert' );
can_ok( $qq, 'has_changed' );
can_ok( $qq, 'hash' );
can_ok( $qq, 'hash_arrayref' );
can_ok( $qq, 'hidden' );
can_ok( $qq, 'separator' );
can_ok( $qq, '_deepcopy' );
can_ok( $qq, '_parse_qs' );
can_ok( $qq, '_init_from_arrayref' );
# borrowed from Apache2::API::Query
is( $qq->stringify, 'bar=3&bar=7&bog=abc&fluffy=3&foo=1&foo=2', 'stringify' );
ok( $qq = Apache2::API::Query->new( foo => 1, foo => 2, bar => 3, bog => 'abc', bar => 7, fluffy => 3 ), 'object from hash' );
is( $qq->stringify, 'bar=3&bar=7&bog=abc&fluffy=3&foo=1&foo=2', 'stringify from hash' );
# Constructor - hashref version
ok( $qq = Apache2::API::Query->new({ foo => [ 1, 2 ], bar => [ 3, 7 ], bog => 'abc', fluffy => 3 }), 'object from hash reference' );
is( $qq->stringify, 'bar=3&bar=7&bog=abc&fluffy=3&foo=1&foo=2', 'stringify from hash reference' );
# Constructor - CGI.pm-style hashref version, packed values
ok( $qq = Apache2::API::Query->new({ foo => "1\0002", bar => "3\0007", bog => 'abc', fluffy => 3 }), 'object from cgi-style hash reference' );
is( $qq->stringify, 'bar=3&bar=7&bog=abc&fluffy=3&foo=1&foo=2', 'stringify from hash reference' );
# NOTE: methods check
# strip
ok( $qq->strip( qw(foo bog) ), 'strip' );
is( $qq->stringify, 'bar=3&bar=7&fluffy=3', 'strip -> stringify' );
# Simple replace
$qq = Apache2::API::Query->new( 'foo=1&foo=2&bar=3;bog=abc;bar=7;fluffy=3' );
ok( $qq->replace( foo => 'xyz', bog => 'magic', extra => 1 ), 'replace' );
is( $qq->stringify, 'bar=3&bar=7&bog=magic&extra=1&fluffy=3&foo=xyz', 'replace -> stringify' );
# Composite replace
ok( $qq->replace(foo => [ 123, 456, 789 ], extra => 2), 'replace' );
is( $qq->stringify, 'bar=3&bar=7&bog=magic&extra=2&fluffy=3&foo=123&foo=456&foo=789', 'replace -> stringify' );
( run in 0.763 second using v1.01-cache-2.11-cpan-39bf76dae61 )