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

(-)a/C4/Context.pm (-3 / +17 lines)
Lines 1264-1278 sub IsSuperLibrarian { Link Here
1264
    return ($userenv->{flags}//0) % 2;
1264
    return ($userenv->{flags}//0) % 2;
1265
}
1265
}
1266
1266
1267
=head2 interface
1268
1269
Sets the current interface for later retrieval in any Perl module
1270
1271
    C4::Context->interface('opac');
1272
    C4::Context->interface('intranet');
1273
    my $interface = C4::Context->interface;
1274
1275
=cut
1276
1267
sub interface {
1277
sub interface {
1268
    my ($class, $interface) = @_;
1278
    my ($class, $interface) = @_;
1269
1279
1270
    if (defined $interface) {
1280
    if (defined $interface) {
1271
        $interface ||= 'opac';
1281
        $interface = lc $interface;
1272
        $context->{interface} = $interface;
1282
        if ($interface eq 'opac' || $interface eq 'intranet') {
1283
            $context->{interface} = $interface;
1284
        } else {
1285
            warn "invalid interface : '$interface'";
1286
        }
1273
    }
1287
    }
1274
1288
1275
    return $context->{interface};
1289
    return $context->{interface} // 'opac';
1276
}
1290
}
1277
1291
1278
1;
1292
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 => 14;
5
use Test::More tests => 24;
6
use Test::MockModule;
6
use Test::MockModule;
7
7
8
BEGIN {
8
BEGIN {
Lines 45-47 is(C4::Context::db_scheme2dbi('mysql'), 'mysql', 'ask for mysql, get mysql'); Link Here
45
is(C4::Context::db_scheme2dbi('Pg'),    'Pg',    'ask for Pg, get Pg');
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');
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');
47
is(C4::Context::db_scheme2dbi(),        'mysql', 'ask for nothing, get mysql');
48
- 
48
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');

Return to bug 11848