Bug 14168 - enhance streaming cataloging to include youtube
[koha.git] / t / Context.t
blob8febdb466c99eaefd06ee653168d2c699fd1d5dc
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use DBI;
5 use Test::More tests => 24;
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');
53 is(C4::Context->interface('foobar'), 'opac');
54 like($lastwarn, qr/invalid interface : 'foobar'/);
55 is(C4::Context->interface, 'opac');
56 is(C4::Context->interface('intranet'), 'intranet');
57 is(C4::Context->interface, 'intranet');
58 is(C4::Context->interface('foobar'), 'intranet');
59 is(C4::Context->interface, 'intranet');
60 is(C4::Context->interface('OPAC'), 'opac');
61 is(C4::Context->interface, 'opac');