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

(-)a/C4/Context.pm (-3 / +17 lines)
Lines 1261-1275 sub IsSuperLibrarian { Link Here
1261
    return ($userenv->{flags}//0) % 2;
1261
    return ($userenv->{flags}//0) % 2;
1262
}
1262
}
1263
1263
1264
=head2 interface
1265
1266
Sets the current interface for later retrieval in any Perl module
1267
1268
    C4::Context->interface('opac');
1269
    C4::Context->interface('intranet');
1270
    my $interface = C4::Context->interface;
1271
1272
=cut
1273
1264
sub interface {
1274
sub interface {
1265
    my ($class, $interface) = @_;
1275
    my ($class, $interface) = @_;
1266
1276
1267
    if (defined $interface) {
1277
    if (defined $interface) {
1268
        $interface ||= 'opac';
1278
        $interface = lc $interface;
1269
        $context->{interface} = $interface;
1279
        if ($interface eq 'opac' || $interface eq 'intranet') {
1280
            $context->{interface} = $interface;
1281
        } else {
1282
            warn "invalid interface : '$interface'";
1283
        }
1270
    }
1284
    }
1271
1285
1272
    return $context->{interface};
1286
    return $context->{interface} // 'opac';
1273
}
1287
}
1274
1288
1275
1;
1289
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