1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#/usr/bin/perl -w
use strict;
use File::Spec;
use Test::More tests => 14;
use CGI;
use CGI::Session;
my $dir_name = File::Spec->tmpdir();
my $session = CGI::Session->new('id:static','testname',{Directory=>$dir_name});
ok($session);
# as class method
ok(CGI::Session->name,'name used as class method');
ok(CGI::Session->name('fluffy'),'name as class method w/ param');
ok(CGI::Session->name eq 'fluffy','name as class method w/ param effective?');
# as instance method
ok($session->name,'name as instance method');
ok($session->name eq CGI::Session->name,'instance method falls through to class');
ok($session->name('spot'),'instance method w/ param');
ok($session->name eq 'spot','instance method w/ param effective?');
ok(CGI::Session->name eq 'fluffy','instance method did not affect class method');
## test interface for setting session/cookie key name CGISESSID.
my $s2 = CGI::Session->new(
'id:static',
'testname',
{ Directory => $dir_name },
{ name => 'itchy' }
);
is $s2->name, 'itchy', 'constructor new with name for session/cookie key';
is( CGI::Session->name, 'fluffy', 'constructor name not affecting class');
is $session->name, 'spot', 'constructor on new session not affecting old';
## test from query
$s2 = CGI::Session->new(
'id:static',
CGI->new( 'itchy=2001' ),
{ Directory => $dir_name },
{ name => 'itchy' }
);
is $s2->id, 2001, 'session from query with new name';
## should die since it won't find value from query
eval {
$s2 = CGI::Session->new(
'id:static',
CGI->new( 'CGISESSID=2001' ),
{ Directory => $dir_name },
{ name => 'itchy' }
);
};
ok $@, "session in query with default name";
|