Cookie

 view release on metacpan or  search on metacpan

t/006_cookies_sqlite.t  view on Meta::CPAN

#!perl
BEGIN
{
    use strict;
    use warnings;
    use lib './lib';
    use Test::More;
    use vars qw( $DEBUG $HAS_DBI $HAS_SQLITE_BIN $SQLITE_BIN );
    # 2021-11-01T08:12:10
    use Test::Time time => 1635754330;
    use File::Which ();
    use HTTP::Request ();
    use HTTP::Response ();
    use Module::Generic::File qw( file );
    our $CRYPTX_REQUIRED_VERSION = '0.074';
    our $DEBUG = exists( $ENV{AUTHOR_TESTING} ) ? $ENV{AUTHOR_TESTING} : 0;
    $DEBUG ||= 4 if( exists( $ENV{AUTOMATED_TESTING} ) );
};

BEGIN
{
    require( "./t/env.pl" ) if( -e( "t/env.pl" ) );
    eval
    {
        require DBI;
        require DBD::SQLite;
    };
    $HAS_DBI = !$@;
    $SQLITE_BIN = File::Which::which( 'sqlite3' );
    $HAS_SQLITE_BIN = ( defined( $SQLITE_BIN ) && length( $SQLITE_BIN ) ) ? 1 : 0;
    plan skip_all => "DBI and DBD::SQLite not installed and sqlite3 binary not found" if( !$HAS_DBI && !$HAS_SQLITE_BIN );
};

BEGIN
{
    use_ok( 'Cookie' );
    use_ok( 'Cookie::Jar' );
};

use strict;
use warnings;
my $rv;

my $jar = Cookie::Jar->new( debug => $DEBUG );
$jar->add({
    name => 'cookie1',
    value => 'value1',
    domain => 'example.com',
    path => '/',
    expires => '+100D',
    secure => 1,
    http_only => 0,
    strict => 0,
    created_on => '-2D',
});

$jar->add({
    name => 'cookie2',
    value => 'value2',
    domain => 'example.org',
    path => '/session',
    expires => 0,
    secure => 1,
    http_only => 1,
    strict => 1,
    created_on => 'now',
});

is( $jar->length, 2, 'total cookies in jar' );
diag( "SQLite binary is '$SQLITE_BIN' and do we have DBI? ", ( $HAS_DBI ? 'yes' : 'no' ) ) if( $DEBUG );
my $db = file( __FILE__ )->parent->child( 'cookies.sqlite' );
$rv = $jar->save_as_mozilla( $db );



( run in 0.878 second using v1.01-cache-2.11-cpan-98e64b0badf )