support get_dbh callback
[catagits/Web-Session.git] / t / 006_basic_w_dbi_store.t
CommitLineData
6f28db48 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use File::Spec;
6use File::Temp qw(tempdir);
7
db4670eb 8use Test::Requires qw(DBI DBD::SQLite MIME::Base64 Storable);
6f28db48 9use Test::More;
10
11use Plack::Request;
12use Plack::Session;
13use Plack::Session::State::Cookie;
14use Plack::Session::Store::DBI;
15
16use t::lib::TestSession;
17
18my $tmp = tempdir(CLEANUP => 1);
19my $file = File::Spec->catfile($tmp, "006_basic_w_dbi_store.db");
20my $dbh = DBI->connect( "dbi:SQLite:$file", undef, undef, {RaiseError => 1, AutoCommit => 1} );
21$dbh->do(<<EOSQL);
22CREATE TABLE sessions (
23 id CHAR(72) PRIMARY KEY,
24 session_data TEXT
25);
26EOSQL
6f28db48 27
28t::lib::TestSession::run_all_tests(
db4670eb 29 store => Plack::Session::Store::DBI->new( dbh => $dbh ),
6f28db48 30 state => Plack::Session::State->new,
31 env_cb => sub {
32 open my $in, '<', \do { my $d };
33 my $env = {
34 'psgi.version' => [ 1, 0 ],
35 'psgi.input' => $in,
36 'psgi.errors' => *STDERR,
37 'psgi.url_scheme' => 'http',
38 SERVER_PORT => 80,
39 REQUEST_METHOD => 'GET',
40 QUERY_STRING => join "&" => map { $_ . "=" . $_[0]->{ $_ } } keys %{$_[0] || +{}},
41 };
42 },
43);
44
4804dac3 45t::lib::TestSession::run_all_tests(
46 store => Plack::Session::Store::DBI->new( get_dbh => sub { $dbh } ),
47 state => Plack::Session::State->new,
48 env_cb => sub {
49 open my $in, '<', \do { my $d };
50 my $env = {
51 'psgi.version' => [ 1, 0 ],
52 'psgi.input' => $in,
53 'psgi.errors' => *STDERR,
54 'psgi.url_scheme' => 'http',
55 SERVER_PORT => 80,
56 REQUEST_METHOD => 'GET',
57 QUERY_STRING => join "&" => map { $_ . "=" . $_[0]->{ $_ } } keys %{$_[0] || +{}},
58 };
59 },
60);
61
62
db4670eb 63$dbh->disconnect;
6f28db48 64
4804dac3 65done_testing;