Add a comment to WebGUI::Session::Var::start that if no userSessionId is passed

that a new userSessionId will be created and that the current sessionId (the actual
session object's id) will be set to this new id.
Add several new tests to Session/Var.t  Tried hard to exploit the change in 
sessionId and haven't found a way, yet.
This commit is contained in:
Colin Kuskie 2006-09-22 03:44:34 +00:00
parent 44884ef7c8
commit 56e78708a4
2 changed files with 59 additions and 9 deletions

View file

@ -211,7 +211,8 @@ sub session {
=head2 start ( [ userId, sessionId ] )
Start a new user session. Returns the session id.
Start a new user session. Returns the user session id. The session variable's sessionId
is set to the var object's session id.
=head3 userId

View file

@ -16,7 +16,8 @@ use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Session::Var;
use Test::More tests => 19; # increment this value for each test you create
use Test::More tests => 25; # increment this value for each test you create
use Test::Deep;
my $session = WebGUI::Test->session;
@ -27,28 +28,76 @@ $session->var->switchAdminOn;
is($session->var->isAdminOn, 1, "switchAdminOn()");
$session->var->switchAdminOff;
is($session->var->isAdminOn, 0, "switchAdminOff()");
my $id = $session->var->getId;
$session->var->end;
my ($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$id]);
ok($count == 0,"end()");
is($count, 1,"created an user session entry in the database");
my %newEnvHash = ( REMOTE_ADDR => '192.168.0.34');
my $origEnv = $session->env->{_env};
$session->env->{_env} = \%newEnvHash;
my $varTime = time();
my $varExpires = $varTime + $session->setting->get('sessionTimeout');
my $var = WebGUI::Session::Var->new($session);
isa_ok($var, 'WebGUI::Session::Var', 'new returns Var object');
is($var->get('userId'), 1, 'default userId is 1');
is($var->get('sessionId'), $var->getId, "get('sessionId') and getId return the same thing");
isnt($var->getId, $session->var->getId, 'a new, unique sessionId was created');
isnt($var->getId, $session->var->getId, "a sessionId different from our Session's var sessionId was created");
is($var->getId, $session->getId, 'SessionId set to userSessionId from var');
is($var->get('adminOn'), $var->isAdminOn, "get('adminOn') and isAdminOn return the same thing");
is($var->get('adminOn'), 0, "adminOn is off by default"); ##retest
cmp_ok(abs($var->get('lastPageView') - $varTime), '<=', 1, 'lastPageView set correctly');
cmp_ok(abs($var->get('expires') - $varExpires), '<=', 1, 'expires set correctly');
is($var->get('lastIP'), '192.168.0.34', "lastIP fetched");
isa_ok($var->session, 'WebGUI::Session', 'session method returns a Session object');
is($var->session->getId, $session->getId, 'session method returns our Session object');
sleep(2);
$newEnvHash{REMOTE_ADDR} = '10.0.5.5';
#Grab a more recent version of our user session object
$varTime = time();
$varExpires = $varTime + $session->setting->get('sessionTimeout');
my $var2 = WebGUI::Session::Var->new($session, $session->getId);
cmp_deeply(
$var2,
methods(
['get', 'sessionId'] => $var->get('sessionId'),
['get', 'userId'] => $var->get('userId'),
['get', 'adminOn'] => $var->get('adminOn'),
),
'similar methods in copy of original var object'
);
cmp_ok(abs($var2->get('lastPageView') - $varTime), '<=', 1, 'lastPageView set correctly on copy');
cmp_ok(abs($var2->get('expires') - $varExpires), '<=', 1, 'expires set correctly on copy');
is($var2->get('lastIP'), '10.0.5.5', "lastIP set on copy");
my $var2Id = $var2->getId;
$var2->end;
($count) = $session->db->quickArray("select count(*) from userSession where sessionId=?",[$var2->getId]);
ok($count == 0,"end() removes current entry from database");
$var->end;
$session->env->{_env} = $origEnv;
TODO: {
local $TODO = "Stuff to write later";
ok(0, 'check fetching a particular sessionId');
ok(0, 'check fetching a non-existant sessionId');
ok(0, 'check setting a particular userId');
ok(0, 'check setting a non-existant userId');
ok(0, 'check that lastIp was set correctly');
ok(0, 'check fetching a non-existant sessionId with noFuss');
}
END: {
foreach my $varObj ($var, $var2) {
if (defined $varObj and ref $varObj eq 'WebGUI::Session::Var') {
$varObj->end();
}
}
}