Bug 11389: reenable Pg as a DB scheme that Koha can connect to
[koha.git] / t / Context.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4 use DBI;
5 use Test::More tests => 10;
6 use Test::MockModule;
7
8 BEGIN {
9     use_ok('C4::Context');
10 }
11
12 my $context = new Test::MockModule('C4::Context');
13 my $userenv = {};
14
15 $context->mock('userenv', sub {
16     return $userenv;
17 });
18
19 local $SIG{__WARN__} = sub { die $_[0] };
20
21 eval { C4::Context::IsSuperLibrarian(); };
22 like ( $@, qr/not defined/, "IsSuperLibrarian logs an error if no userenv is defined" );
23
24 $userenv->{flags} = 42;
25 my $is_super_librarian = eval{ C4::Context::IsSuperLibrarian() };
26 is ( $@, q||, "IsSuperLibrarian does not log an error if userenv is defined" );
27 is ( $is_super_librarian, 0, "With flag=42, it is not a super librarian" );
28
29 $userenv->{flags} = 421;
30 $is_super_librarian = eval{ C4::Context::IsSuperLibrarian() };
31 is ( $@, q||, "IsSuperLibrarian does not log an error if userenv is defined" );
32 is ( $is_super_librarian, 1, "With flag=1, it is a super librarian" );
33
34 is(C4::Context::db_scheme2dbi('mysql'), 'mysql', 'ask for mysql, get mysql');
35 is(C4::Context::db_scheme2dbi('Pg'),    'Pg',    'ask for Pg, get Pg');
36 is(C4::Context::db_scheme2dbi('xxx'),   'mysql', 'ask for unsupported DBMS, get mysql');
37 is(C4::Context::db_scheme2dbi(),        'mysql', 'ask for nothing, get mysql');