"Fossies" - the Fresh Open Source Software Archive

Member "Apache-Session-1.93/t/99dbfilestore.t" (15 Sep 2009, 1771 Bytes) of package /linux/www/Apache-Session-1.93.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 use Test::More;
    2 use Test::Exception;
    3 use File::Temp qw[tempdir];
    4 use Cwd qw[getcwd];
    5 
    6 plan skip_all => "Optional module (DB_File) not installed"
    7   unless eval {
    8                require DB_File;
    9               };
   10 
   11 my $package = 'Apache::Session::Store::DB_File';
   12 
   13 plan tests => 13;
   14 
   15 use_ok $package;
   16 use_ok 'DB_File';
   17 can_ok $package, qw[new insert materialize remove];
   18 
   19 my $origdir = getcwd;
   20 my $tempdir = tempdir( DIR => '.', CLEANUP => 1 );
   21 chdir( $tempdir );
   22 
   23 my $serial  = '12345';
   24 my $id      = 'test1';
   25 my $dbfile  = 'foo.dbm';
   26 my $session = {
   27     serialized => $serial,
   28     data       => {
   29                    _session_id => $id,
   30                   },
   31     args       => {
   32                    FileName => $dbfile,
   33                   },
   34 };
   35 
   36 my $store = $package->new;
   37 isa_ok $store, $package;
   38 
   39 my $i_ret = $store->insert($session);
   40 is( $i_ret, $serial, "insert() returned value of serialized" );
   41 
   42 ok( -e $dbfile, 'dbm file exists' );
   43 
   44 undef $store;
   45 
   46 $store = $package->new;
   47 isa_ok $store, $package;
   48 
   49 $session->{serialized} = undef;
   50 lives_ok {
   51     $store->materialize($session)
   52 } 'materialize did not die';
   53 is( $session->{serialized}, $serial, "materialized session is correct" );
   54 
   55 my $new_serial = 'hi';
   56 $session->{serialized} = $new_serial;
   57 my $u_ret = $store->update($session);
   58 is( $u_ret, $new_serial, "update() returned value of new serialized" );
   59 
   60 undef $store;
   61 
   62 my %hash;
   63 tie %hash, 'DB_File', $dbfile;
   64 
   65 is( $hash{$id}, $new_serial, "dbm file updated correctly" );
   66 
   67 $store = $package->new;
   68 isa_ok $store, $package;
   69 $store->remove($session);
   70 
   71 dies_ok {
   72     $store->materialize($session);
   73 } "Can't materialize removed session";
   74 
   75 undef $store;
   76 untie %hash;
   77 undef %hash;
   78 
   79 chdir( $origdir );