1N/A# to have a consistent baseline, we nail the current time 1N/A# to 100 seconds after the epoch 1N/A#----------------------------------------------------------------------------- 1N/A# make sure module loaded 1N/A#----------------------------------------------------------------------------- 1N/A # including leading and trailing whitespace in first cookie 1N/A ' foo=123 ; bar=qwerty; baz=wibble; qux=a1', 1N/A 'foo=123; bar=qwerty; baz=wibble;', 1N/A 'foo=vixen; bar=cow; baz=bitch; qux=politician', 1N/A 'foo=a%20phrase; bar=yes%2C%20a%20phrase; baz=%5Ewibble; qux=%27', 1N/A#----------------------------------------------------------------------------- 1N/A#----------------------------------------------------------------------------- 1N/A is_deeply(\@array, [], " parse('') returns an empty array in list context (undocumented)"); 1N/A is_deeply($scalar, {}, " parse('') returns an empty hashref in scalar context (undocumented)"); 1N/A is_deeply(\@array, [], " parse(undef) returns an empty array in list context (undocumented)"); 1N/A is_deeply($scalar, {}, " parse(undef) returns an empty hashref in scalar context (undocumented)"); 1N/A#----------------------------------------------------------------------------- 1N/A#----------------------------------------------------------------------------- 1N/A # make sure there are no cookies in the environment 1N/A # now set a cookie in the environment and try again 1N/A "expected cookies extracted"); 1N/A # Delete that and make sure it goes away 1N/A # try another cookie in the other environment variable thats supposed to work 1N/A "expected cookies extracted"); 1N/A#----------------------------------------------------------------------------- 1N/A#----------------------------------------------------------------------------- 1N/A # make sure there are no cookies in the environment 1N/A # now set a cookie in the environment and try again 1N/A "expected cookies extracted"); 1N/A # Delete that and make sure it goes away 1N/A # try another cookie in the other environment variable thats supposed to work 1N/A "expected cookies extracted"); 1N/A#----------------------------------------------------------------------------- 1N/A#----------------------------------------------------------------------------- 1N/A # Try new with full information provided 1N/A is(ref($c), 'CGI::Cookie', 'new returns objects of correct type'); 1N/A like($c->expires, '/^[a-z]{3},\s*\d{2}-[a-z]{3}-\d{4}/i', 'expires in correct format'); 1N/A # now try it with the only two manditory values (should also set the default path) 1N/A is(ref($c), 'CGI::Cookie', 'new returns objects of correct type'); 1N/A is($c->path, '/', 'path atribute is set to default'); 1N/A# I'm really not happy about the restults of this section. You pass 1N/A# the new method invalid arguments and it just merilly creates a 1N/A# I've commented them out because they currently pass but I don't 1N/A# think they should. I think this is testing broken behaviour :-( 1N/A# # This shouldn't work 1N/A# $c = CGI::Cookie->new(-name => 'baz' ); 1N/A# is(ref($c), 'CGI::Cookie', 'new returns objects of correct type'); 1N/A# is($c->name , 'baz', 'name is correct'); 1N/A# ok(!defined $c->value, "Value is undefined "); 1N/A# ok(!defined $c->expires, 'expires is not set'); 1N/A# ok(!defined $c->domain , 'domain attributeis not set'); 1N/A# is($c->path , '/', 'path atribute is set to default'); 1N/A# ok(!defined $c->secure , 'secure attribute is set'); 1N/A#----------------------------------------------------------------------------- 1N/A#----------------------------------------------------------------------------- 1N/A "Stringified cookie contains HttpOnly" ); 1N/A "Stringified cookie does not contain HttpOnly" ); 1N/A#----------------------------------------------------------------------------- 1N/A#----------------------------------------------------------------------------- 1N/A # have to use $c1->expires because the time will occasionally be 1N/A # different between the two creates causing spurious failures. 1N/A # This looks titally whacked, but it does the -1, 0, 1 comparison 1N/A # thing so 0 means they match 1N/A # have to use $c1->expires because the time will occasionally be 1N/A # different between the two creates causing spurious failures. 1N/A # This looks titally whacked, but it does the -1, 0, 1 comparison 1N/A # thing so 0 (i.e. false) means they match 1N/A#----------------------------------------------------------------------------- 1N/A# Test name, value, domain, secure, expires and path 1N/A#----------------------------------------------------------------------------- 1N/A is($c->name('Clash'), 'Clash', 'name is set correctly'); 1N/A is($c->name, 'Clash', 'name now returns updated value'); 1N/A # this is insane! it returns a simple scalar but can't accept one as 1N/A # an argument, you have to give it an arrary ref. It's totally 1N/A # inconsitent with these other methods :-( 1N/A is($c->value(['Gerbil']), 'Gerbil', 'value is set correctly'); 1N/A is($c->value, 'Gerbil', 'value now returns updated value'); 1N/A like($c->expires, '/^[a-z]{3},\s*\d{2}-[a-z]{3}-\d{4}/i', 'expires is correct'); 1N/A like($c->expires('+12h'), '/^[a-z]{3},\s*\d{2}-[a-z]{3}-\d{4}/i', 'expires is set correctly'); 1N/A like($c->expires, '/^[a-z]{3},\s*\d{2}-[a-z]{3}-\d{4}/i', 'expires now returns updated value'); 1N/A is($c->path('/basket/'), '/basket/', 'path is set correctly'); 1N/A is($c->path, '/basket/', 'path now returns updated value'); 1N/A#---------------------------------------------------------------------------- 1N/A#---------------------------------------------------------------------------- 1N/A#---------------------------------------------------------------------------- 1N/A#---------------------------------------------------------------------------- 1N/A # Older Perl may be confused while evaluating test results with cookie 1N/A # dump. To avoid this we will make sure that cookie is print on STDERR 1N/A is($@,'', "calling bake() without mod_perl should survive"); 1N/A#----------------------------------------------------------------------------- 1N/A# Apache2?::Cookie compatibility. 1N/A#----------------------------------------------------------------------------- 1N/A ), 'Pass an Apache object to the CGI::Cookie constructor'; 1N/A 'bake() should call headers_out->set()'; 1N/A ), 'Pass an Apache::RequestReq object to the CGI::Cookie constructor'; 1N/A 'bake() should call headers_out->set()';