5 use Test
::More tests
=> 24;
12 my $context = new Test
::MockModule
('C4::Context');
15 $context->mock('userenv', sub {
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
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');