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

(-)a/C4/Koha.pm (-1 / +1 lines)
Lines 1237-1243 sub IsAuthorisedValueCategory { Link Here
1237
    my $query = '
1237
    my $query = '
1238
        SELECT category
1238
        SELECT category
1239
        FROM authorised_values
1239
        FROM authorised_values
1240
        WHERE BINARY category=?
1240
        WHERE category=?
1241
        LIMIT 1
1241
        LIMIT 1
1242
    ';
1242
    ';
1243
    my $sth = C4::Context->dbh->prepare($query);
1243
    my $sth = C4::Context->dbh->prepare($query);
(-)a/t/Koha.t (-32 / +30 lines)
Lines 18-58 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use C4::Context;
20
use C4::Context;
21
use Test::More tests => 29;
21
use Test::More tests => 30;
22
use Test::MockModule;
22
use Test::MockModule;
23
use DBD::Mock;
24
23
25
use_ok('C4::Koha');
24
use_ok('C4::Koha');
26
25
27
my $module_context = new Test::MockModule('C4::Context');
26
use Test::DBIx::Class {
28
$module_context->mock(
27
    schema_class => 'Koha::Schema',
29
    '_new_dbh',
28
    connect_info => ['dbi:SQLite:dbname=:memory:','',''],
30
    sub {
29
    connect_opts => { name_sep => '.', quote_char => '`', },
31
        my $dbh = DBI->connect( 'DBI:Mock:', '', '' )
30
    fixture_class => '::Populate',
32
          || die "Cannot create handle: $DBI::errstr\n";
31
}, 'AuthorisedValue' ;
33
        return $dbh;
32
34
    }
33
sub fixtures {
35
);
34
    my ( $data ) = @_;
36
35
    fixtures_ok [
37
SKIP: {
36
        AuthorisedValue => [
38
37
            [ 'category', 'authorised_value' ],
39
    skip "DBD::Mock is too old", 3
38
            @$data,
40
        unless $DBD::Mock::VERSION >= 1.45;
39
        ],
41
40
    ], 'add fixtures';
42
    my @loc_results = (['category'],['LOC']);
41
}
43
    my @empty_results = ([]);
42
44
    my @relterms_results = (['category'],['RELTERMS']);
43
my $db = Test::MockModule->new('Koha::Database');
45
44
$db->mock( _new_schema => sub { return Schema(); } );
46
    my $dbh = C4::Context->dbh();
45
47
46
my $authorised_values = [
48
    $dbh->{mock_add_resultset} = \@loc_results;
47
    ['LOC', 'LOC'],
49
    is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category');
48
    ['RELTERMS', 'RELTERMS'],
50
    $dbh->{mock_add_resultset} = \@empty_results;
49
];
51
    is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category');
50
fixtures($authorised_values);
52
    $dbh->{mock_add_resultset} = \@relterms_results;
51
53
    is ( IsAuthorisedValueCategory('RELTERMS'), 1, 'RELTERMS is a valid authorized value category');
52
is ( IsAuthorisedValueCategory('LOC'), 1, 'LOC is a valid authorized value category');
54
53
is ( IsAuthorisedValueCategory('something'), 0, 'something is not a valid authorized value category');
55
} # End SKIP block
54
is ( IsAuthorisedValueCategory('RELTERMS'), 1, 'RELTERMS is a valid authorized value category');
56
55
57
#
56
#
58
# test that &slashifyDate returns correct (non-US) date
57
# test that &slashifyDate returns correct (non-US) date
59
- 

Return to bug 14778