Bug 20123: Make the timezone entry empty and uncommented by default
[koha.git] / t / Context.t
blobe2c1825270e54219f7e804c2d1329258ee66cdf4
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use DBI;
5 use Test::More tests => 26;
6 use Test::MockModule;
8 BEGIN {
9 use_ok('C4::Context');
12 my $context = new Test::MockModule('C4::Context');
13 my $userenv = {};
15 $context->mock('userenv', sub {
16 return $userenv;
17 });
19 local $SIG{__WARN__} = sub { die $_[0] };
21 eval { C4::Context::IsSuperLibrarian(); };
22 like ( $@, qr/not defined/, "IsSuperLibrarian logs an error if no userenv is defined" );
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" );
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" );
34 $userenv->{flags} = undef;
35 $is_super_librarian = eval{ C4::Context::IsSuperLibrarian() };
36 is ( $@, q||, "IsSuperLibrarian does not log an error if \$userenv->{flags} is undefined" );
37 is ( $is_super_librarian, 0, "With flag=undef, it is not a super librarian" );
39 $userenv->{flags} = 0;
40 $is_super_librarian = eval{ C4::Context::IsSuperLibrarian() };
41 is ( $@, q||, "IsSuperLibrarian does not log an error if \$userenv->{flags} is equal to 0" );
42 is ( $is_super_librarian, 0, "With flag=0, it is not a super librarian" );
44 is(C4::Context::db_scheme2dbi('mysql'), 'mysql', 'ask for mysql, get mysql');
45 is(C4::Context::db_scheme2dbi('Pg'), 'Pg', 'ask for Pg, get Pg');
46 is(C4::Context::db_scheme2dbi('xxx'), 'mysql', 'ask for unsupported DBMS, get mysql');
47 is(C4::Context::db_scheme2dbi(), 'mysql', 'ask for nothing, get mysql');
49 # C4::Context::interface
50 my $lastwarn;
51 local $SIG{__WARN__} = sub { $lastwarn = $_[0] };
52 is(C4::Context->interface, 'opac','interface defaults to opac');
53 is(C4::Context->interface('foobar'), 'opac', 'interface foobar');
54 like($lastwarn, qr/invalid interface : 'foobar'/, 'interface warn on foobar');
55 is(C4::Context->interface, 'opac', 'interface still opac');
56 is(C4::Context->interface('intranet'), 'intranet', 'interface intranet');
57 is(C4::Context->interface, 'intranet', 'interface still intranet');
58 is(C4::Context->interface('foobar'), 'intranet', 'interface foobar again');
59 is(C4::Context->interface, 'intranet', 'interface still intranet');
60 is(C4::Context->interface('OPAC'), 'opac', 'interface OPAC uc');
61 is(C4::Context->interface, 'opac', 'interface still opac');
62 #Bug 14751
63 is( C4::Context->interface( 'SiP' ), 'sip', 'interface SiP' );
64 is( C4::Context->interface( 'COMMANDLINE' ), 'commandline', 'interface commandline uc' );