View | Details | Raw Unified | Return to bug 11848
Collapse All | Expand All

(-)a/C4/Context.pm (-3 / +17 lines)
Lines 1250-1264 sub IsSuperLibrarian { Link Here
1250
    return $userenv->{flags} % 2;
1250
    return $userenv->{flags} % 2;
1251
}
1251
}
1252
1252
1253
=head2 interface
1254
1255
Sets the current interface for later retrieval in any Perl module
1256
1257
    C4::Context->interface('opac');
1258
    C4::Context->interface('intranet');
1259
    my $interface = C4::Context->interface;
1260
1261
=cut
1262
1253
sub interface {
1263
sub interface {
1254
    my ($class, $interface) = @_;
1264
    my ($class, $interface) = @_;
1255
1265
1256
    if (defined $interface) {
1266
    if (defined $interface) {
1257
        $interface ||= 'opac';
1267
        $interface = lc $interface;
1258
        $context->{interface} = $interface;
1268
        if ($interface eq 'opac' || $interface eq 'intranet') {
1269
            $context->{interface} = $interface;
1270
        } else {
1271
            warn "invalid interface : '$interface'";
1272
        }
1259
    }
1273
    }
1260
1274
1261
    return $context->{interface};
1275
    return $context->{interface} // 'opac';
1262
}
1276
}
1263
1277
1264
1;
1278
1;
(-)a/t/Context.t (-2 / +15 lines)
Lines 2-8 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use DBI;
4
use DBI;
5
use Test::More tests => 10;
5
use Test::More tests => 20;
6
use Test::MockModule;
6
use Test::MockModule;
7
7
8
BEGIN {
8
BEGIN {
Lines 35-37 is(C4::Context::db_scheme2dbi('mysql'), 'mysql', 'ask for mysql, get mysql'); Link Here
35
is(C4::Context::db_scheme2dbi('Pg'),    'Pg',    'ask for Pg, get Pg');
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');
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');
37
is(C4::Context::db_scheme2dbi(),        'mysql', 'ask for nothing, get mysql');
38
- 
38
39
# C4::Context::interface
40
my $lastwarn;
41
local $SIG{__WARN__} = sub { $lastwarn = $_[0] };
42
is(C4::Context->interface, 'opac');
43
is(C4::Context->interface('foobar'), 'opac');
44
like($lastwarn, qr/invalid interface : 'foobar'/);
45
is(C4::Context->interface, 'opac');
46
is(C4::Context->interface('intranet'), 'intranet');
47
is(C4::Context->interface, 'intranet');
48
is(C4::Context->interface('foobar'), 'intranet');
49
is(C4::Context->interface, 'intranet');
50
is(C4::Context->interface('OPAC'), 'opac');
51
is(C4::Context->interface, 'opac');

Return to bug 11848